From 4e1d415867833447835ef41c19c2e4b93b53372b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 07:08:38 +0000 Subject: [PATCH 01/83] Auto-generated commit 175c9daae227d426f5e85ca96d5db6dbab38ca6c --- index.d.ts | 243 +++++ index.mjs | 4 + index.mjs.map | 1 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 2937 insertions(+) create mode 100644 index.d.ts create mode 100644 index.mjs create mode 100644 index.mjs.map create mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..478f7bf --- /dev/null +++ b/index.d.ts @@ -0,0 +1,243 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/// + +import * as random from '@stdlib/types/random'; + +/** +* Interface defining `factory` options. +*/ +interface Options { + /** + * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. + */ + prng?: random.PRNG; + + /** + * Pseudorandom number generator seed. + */ + seed?: random.PRNGSeedMT19937; + + /** + * Pseudorandom number generator state. + */ + state?: random.PRNGStateMT19937; + + /** + * Specifies whether to copy a provided pseudorandom number generator state. + */ + copy?: boolean; +} + +/** +* Interface for PRNG properties and methods. +*/ +interface PRNG { + /** + * Generator name. + */ + readonly NAME: string; + + /** + * Underlying pseudorandom number generator. + */ + readonly PRNG: random.PRNG; + + /** + * PRNG seed. + */ + readonly seed: random.PRNGSeedMT19937; + + /** + * PRNG seed length. + */ + readonly seedLength: number; + + /** + * PRNG state. + */ + state: random.PRNGStateMT19937; + + /** + * PRNG state length. + */ + readonly stateLength: number; + + /** + * PRNG state size (in bytes). + */ + readonly byteLength: number; + + /** + * Serializes the pseudorandom number generator as a JSON object. + * + * @returns JSON representation + */ + toJSON(): string; +} + +/** +* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. +*/ +interface NullaryFunction extends PRNG { + /** + * Returns a pseudorandom number drawn from a triangular distribution. + * + * @returns pseudorandom number + */ + (): number; +} + +/** +* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. +*/ +interface BinaryFunction extends PRNG { + /** + * Returns a pseudorandom number drawn from a triangular distribution. + * + * @param a - minimum support + * @param b - maximum support + * @param c - mode + * @returns pseudorandom number + */ + ( a: number, b: number, c: number ): number; +} + +/** +* Interface for generating pseudorandom numbers drawn from a triangular distribution. +*/ +interface Random extends PRNG { + /** + * Returns pseudorandom number drawn from a triangular distribution. + * + * ## Notes + * + * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. + * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. + * + * @param a - minimum support + * @param b - maximum support + * @param c - mode + * @returns pseudorandom number + * + * @example + * var v = triangular( 2.0, 5.0, 3.33 ); + * // returns + * + * @example + * var v = triangular( 1.0, 2.0, 1.8 ); + * // returns NaN + */ + ( a: number, b: number, c: number ): number; + + /** + * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. + * + * ## Notes + * + * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. + * + * @param a - minimum support + * @param b - maximum support + * @param c - mode + * @param options - function options + * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers + * @param options.seed - pseudorandom number generator seed + * @param options.state - pseudorandom number generator state + * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) + * @throws arguments must satisfy `a <= c <= b` + * @throws must provide a valid state + * @returns pseudorandom number generator + * + * @example + * var rand = triangular.factory( 1.0, 3.0, 1.5 ); + * var v = rand(); + * // returns + * + * @example + * var rand = triangular.factory( 1.0, 2.0, 1.5, { + * 'seed': 297 + * }); + * var v = rand(); + * // returns + */ + factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length + + /** + * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. + * + * ## Notes + * + * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. + * + * @param options - function options + * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers + * @param options.seed - pseudorandom number generator seed + * @param options.state - pseudorandom number generator state + * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) + * @throws must provide a valid state + * @returns pseudorandom number generator + * + * @example + * var rand = triangular.factory(); + * var v = rand( 1.0, 3.0, 1.5 ); + * // returns + * + * @example + * var rand = triangular.factory({ + * 'seed': 297 + * }); + * var v = rand( 1.0, 2.0, 1.5 ); + * // returns + */ + factory( options?: Options ): BinaryFunction; +} + +/** +* Returns pseudorandom number drawn from a triangular distribution. +* +* ## Notes +* +* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. +* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. +* +* @param a - minimum support +* @param b - maximum support +* @param c - mode +* @returns pseudorandom number +* +* @example +* var v = triangular( 2.0, 5.0, 3.33 ); +* // returns +* +* @example +* var rand = triangular.factory({ +* 'seed': 297 +* }); +* var v = rand( 1.0, 2.0, 1.5 ); +* // returns +*/ +declare var triangular: Random; + + +// EXPORTS // + +export = triangular; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..adb893e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";var h=p.isPrimitive,j=u,c=g;var b=function(e,t,n){return!h(e)||c(e)?new TypeError(j("invalid argument. First argument must be a number and not `NaN`. Value: `%s`.",e)):!h(t)||c(t)?new TypeError(j("invalid argument. Second argument must be a number and not `NaN`. Value: `%s`.",t)):!h(n)||c(n)?new TypeError(j("invalid argument. Third argument must be a number and not `NaN`. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(j("invalid arguments. The condition `a <= c <= b` must be satisfied. Value: `[%f,%f,%f]`.",e,t,n))},v=f;var y=function(e,t,n,r){var s,i;return s=(r-t)/(n-t),(i=e())3){if(!E(e=arguments[3]))throw new TypeError(S("invalid argument. Options argument must be an object. Value: `%s`.",e));if(T(e,"prng")){if(!L(e.prng))throw new TypeError(S("invalid option. `prng` option must be a pseudorandom number generator function. Option: `%s`.",e.prng));t=e.prng}else t=P(e)}else t=P()}return x(n=void 0===s?h:f,"NAME","triangular"),e&&e.prng?(x(n,"seed",null),x(n,"seedLength",null),N(n,"state",O(null),V),x(n,"stateLength",null),x(n,"byteLength",null),x(n,"toJSON",O(null)),x(n,"PRNG",t)):(w(n,"seed",a),w(n,"seedLength",m),N(n,"state",u,p),w(n,"stateLength",d),w(n,"byteLength",l),x(n,"toJSON",g),x(n,"PRNG",t),t=t.normalized),n;function a(){return t.seed}function m(){return t.seedLength}function d(){return t.stateLength}function l(){return t.byteLength}function u(){return t.state}function p(e){t.state=e}function g(){var e={type:"PRNG"};return e.name=n.NAME,e.state=G(t.state),e.params=void 0===s?[]:[s,i,o],e}function f(){return J(t,s,i,o)}function h(e,n,r){return R(e)||R(n)||R(r)||!(e<=r&&r<=n)?NaN:J(t,e,n,r)}},q=M(),z=M;e(q,"factory",z);var F=q;export{F as default,z as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9bf2fec --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/index.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not `NaN`. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not `NaN`. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not `NaN`. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. The condition `a <= c <= b` must be satisfied. Value: `[%f,%f,%f]`.', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `prng` option must be a pseudorandom number generator function. Option: `%s`.', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `prng` option must be a pseudorandom number generator function. Option: `%s`.', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar triangular = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n"],"names":["isNumber","require$$0","isPrimitive","format","require$$1","isnan","require$$2","validate_1","a","b","c","TypeError","RangeError","sqrt","triangular_1","rand","fc","u","setReadOnly","setReadOnlyAccessor","setReadWriteAccessor","isObject","require$$3","isFunction","require$$4","hasOwnProp","require$$5","constantFunction","require$$6","noop","require$$7","randu","require$$8","factory","require$$9","typedarray2json","require$$10","require$$11","validate","require$$12","triangular0","require$$13","factory_1","opts","prng","err","arguments","length","triangular2","triangular1","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","params","NaN","triangular","lib"],"mappings":";;21CAsBA,IAAIA,EAAWC,EAAsCC,YACjDC,EAASC,EACTC,EAAQC,EAuCZ,IAAAC,EAnBA,SAAmBC,EAAGC,EAAGC,GACxB,OAAMV,EAAUQ,IAAOH,EAAOG,GACtB,IAAIG,UAAWR,EAAQ,gFAAiFK,KAE1GR,EAAUS,IAAOJ,EAAOI,GACtB,IAAIE,UAAWR,EAAQ,iFAAkFM,KAE3GT,EAAUU,IAAOL,EAAOK,GACtB,IAAIC,UAAWR,EAAQ,gFAAiFO,IAEzGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIG,WAAYT,EAAQ,yFAA0FK,EAAGC,EAAGC,KCjC7HG,EAAOZ,EAgCX,IAAAa,EAjBA,SAAqBC,EAAMP,EAAGC,EAAGC,GAChC,IAAIM,EAEAC,EAGJ,OAFAD,GAAMN,EAAIF,IAAMC,EAAID,IACpBS,EAAIF,KACKC,EAEDR,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACES,GAGfR,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAMO,KC1BzBC,EAAcjB,EACdkB,EAAsBf,EACtBgB,EAAuBd,EACvBe,EAAWC,EACXC,EAAaC,EACbC,EAAaC,EACbC,EAAmBC,EACnBC,EAAOC,EACPC,EAAQC,EAAyCC,QACjD5B,EAAQ6B,EACRC,EAAkBC,EAClBjC,EAASkC,EACTC,EAAWC,EACXC,EAAcC,EA0PlB,IAAAC,EApNA,WACC,IAAIC,EACA5B,EACA6B,EACAC,EACArC,EACAC,EACAC,EAEJ,GAA0B,IAArBoC,UAAUC,OACdhC,EAAOgB,SACD,GAA0B,IAArBe,UAAUC,OAAe,CAEpC,IAAM1B,EADNsB,EAAOG,UAAW,IAEjB,MAAM,IAAInC,UAAWR,EAAQ,qEAAsEwC,IAEpG,GAAKlB,EAAYkB,EAAM,QAAW,CACjC,IAAMpB,EAAYoB,EAAKC,MACtB,MAAM,IAAIjC,UAAWR,EAAQ,gGAAiGwC,EAAKC,OAEpI7B,EAAO4B,EAAKC,UAEZ7B,EAAOgB,EAAOY,OAET,CAKN,GADAE,EAAMP,EAHN9B,EAAIsC,UAAW,GACfrC,EAAIqC,UAAW,GACfpC,EAAIoC,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAM1B,EADNsB,EAAOG,UAAW,IAEjB,MAAM,IAAInC,UAAWR,EAAQ,qEAAsEwC,IAEpG,GAAKlB,EAAYkB,EAAM,QAAW,CACjC,IAAMpB,EAAYoB,EAAKC,MACtB,MAAM,IAAIjC,UAAWR,EAAQ,gGAAiGwC,EAAKC,OAEpI7B,EAAO4B,EAAKC,UAEZ7B,EAAOgB,EAAOY,QAGf5B,EAAOgB,IA6BT,OArBAb,EAJC0B,OADU,IAANpC,EACGwC,EAEAC,EAEW,OAAQ,cAGtBN,GAAQA,EAAKC,MACjB1B,EAAa0B,EAAM,OAAQ,MAC3B1B,EAAa0B,EAAM,aAAc,MACjCxB,EAAsBwB,EAAM,QAASjB,EAAkB,MAAQE,GAC/DX,EAAa0B,EAAM,cAAe,MAClC1B,EAAa0B,EAAM,aAAc,MACjC1B,EAAa0B,EAAM,SAAUjB,EAAkB,OAC/CT,EAAa0B,EAAM,OAAQ7B,KAE3BI,EAAqByB,EAAM,OAAQM,GACnC/B,EAAqByB,EAAM,aAAcO,GACzC/B,EAAsBwB,EAAM,QAASQ,EAAUC,GAC/ClC,EAAqByB,EAAM,cAAeU,GAC1CnC,EAAqByB,EAAM,aAAcW,GACzCrC,EAAa0B,EAAM,SAAUY,GAC7BtC,EAAa0B,EAAM,OAAQ7B,GAC3BA,EAAOA,EAAK0C,YAENb,EAQP,SAASM,IACR,OAAOnC,EAAK2C,KASb,SAASP,IACR,OAAOpC,EAAK4C,WASb,SAASL,IACR,OAAOvC,EAAK6C,YASb,SAASL,IACR,OAAOxC,EAAK8C,WASb,SAAST,IACR,OAAOrC,EAAK+C,MAUb,SAAST,EAAUU,GAClBhD,EAAK+C,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAOrB,EAAKsB,KAChBF,EAAIF,MAAQ3B,EAAiBpB,EAAK+C,OAEjCE,EAAIG,YADM,IAAN3D,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEfsD,EAaR,SAASf,IACR,OAAOT,EAAazB,EAAMP,EAAGC,EAAGC,GAwBjC,SAASsC,EAAaxC,EAAGC,EAAGC,GAC3B,OACCL,EAAOG,IACPH,EAAOI,IACPJ,EAAOK,MACLF,GAAKE,GAAKA,GAAKD,GAEV2D,IAED5B,EAAazB,EAAMP,EAAGC,EAAGC,KCjOlC2D,EC/BcpE,IDgCdgC,EAAA3B,EAFAL,EAOAoE,EAAA,UAAApC,GAKA,IAAAqC,EAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e68c85e --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From b95ce8f56d6f86130cd21adc3f74e361de423f39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 25 May 2022 01:50:17 +0000 Subject: [PATCH 02/83] Auto-generated commit --- .editorconfig | 181 ---- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 -- .github/workflows/bundle.yml | 496 ----------- .github/workflows/cancel.yml | 56 -- .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 -- .github/workflows/npm_downloads.yml | 108 --- .github/workflows/productionize.yml | 160 ---- .github/workflows/publish.yml | 157 ---- .github/workflows/test.yml | 92 -- .github/workflows/test_bundles.yml | 158 ---- .github/workflows/test_coverage.yml | 123 --- .github/workflows/test_install.yml | 83 -- .gitignore | 178 ---- .npmignore | 227 ----- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ------------ README.md | 37 +- benchmark/benchmark.factory.js | 105 --- benchmark/benchmark.js | 111 --- benchmark/benchmark.to_json.js | 48 -- benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 --- branches.md | 53 -- docs/repl.txt | 190 ----- docs/types/index.d.ts | 243 ------ docs/types/test.ts | 249 ------ examples/index.js | 50 -- index.mjs | 2 +- index.mjs.map | 2 +- lib/factory.js | 286 ------- lib/index.js | 65 -- lib/main.js | 47 -- lib/triangular.js | 55 -- lib/validate.js | 64 -- package.json | 75 +- stats.html | 2 +- test/test.factory.js | 985 ---------------------- test/test.js | 124 --- 45 files changed, 20 insertions(+), 5700 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/bundle.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/bundle.yml b/.github/workflows/bundle.yml deleted file mode 100644 index a9b11b8..0000000 --- a/.github/workflows/bundle.yml +++ /dev/null @@ -1,496 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: bundle - -# Workflow triggers: -on: - # Allow workflow to be manually run: - workflow_dispatch: - - # Run workflow upon completion of `productionize` workflow: - workflow_run: - workflows: ["productionize"] - types: [completed] - -# Workflow jobs: -jobs: - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Checkout production branch: - - name: 'Checkout production branch' - run: | - git fetch --all - git checkout -b production origin/production - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, checkout branch and rebase on `main`: - - name: 'If `deno` exists, checkout branch and rebase on `main`' - if: steps.deno-branch-exists.outputs.remote-exists - continue-on-error: true - run: | - git checkout -b deno origin/deno - git rebase main -s recursive -X ours - while [ $? -ne 0 ]; do - git rebase --skip - done - - # If `deno` does not exist, checkout `main` and create `deno` branch: - - name: 'If `deno` does not exist, checkout `main` and create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout main - git checkout -b deno - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno --force - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Checkout production branch: - - name: 'Checkout production branch' - run: | - git fetch --all - git checkout -b production origin/production - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) bundle: - - name: 'Create Universal Module Definition (UMD) bundle' - id: umd-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'umd' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/bundle.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +434,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +496,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index 1cb73f2..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16 ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 5712d7d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/index.mjs b/index.mjs index adb893e..053d96e 100644 --- a/index.mjs +++ b/index.mjs @@ -1,4 +1,4 @@ // Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 /// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";var h=p.isPrimitive,j=u,c=g;var b=function(e,t,n){return!h(e)||c(e)?new TypeError(j("invalid argument. First argument must be a number and not `NaN`. Value: `%s`.",e)):!h(t)||c(t)?new TypeError(j("invalid argument. Second argument must be a number and not `NaN`. Value: `%s`.",t)):!h(n)||c(n)?new TypeError(j("invalid argument. Third argument must be a number and not `NaN`. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(j("invalid arguments. The condition `a <= c <= b` must be satisfied. Value: `[%f,%f,%f]`.",e,t,n))},v=f;var y=function(e,t,n,r){var s,i;return s=(r-t)/(n-t),(i=e())3){if(!E(e=arguments[3]))throw new TypeError(S("invalid argument. Options argument must be an object. Value: `%s`.",e));if(T(e,"prng")){if(!L(e.prng))throw new TypeError(S("invalid option. `prng` option must be a pseudorandom number generator function. Option: `%s`.",e.prng));t=e.prng}else t=P(e)}else t=P()}return x(n=void 0===s?h:f,"NAME","triangular"),e&&e.prng?(x(n,"seed",null),x(n,"seedLength",null),N(n,"state",O(null),V),x(n,"stateLength",null),x(n,"byteLength",null),x(n,"toJSON",O(null)),x(n,"PRNG",t)):(w(n,"seed",a),w(n,"seedLength",m),N(n,"state",u,p),w(n,"stateLength",d),w(n,"byteLength",l),x(n,"toJSON",g),x(n,"PRNG",t),t=t.normalized),n;function a(){return t.seed}function m(){return t.seedLength}function d(){return t.stateLength}function l(){return t.byteLength}function u(){return t.state}function p(e){t.state=e}function g(){var e={type:"PRNG"};return e.name=n.NAME,e.state=G(t.state),e.params=void 0===s?[]:[s,i,o],e}function f(){return J(t,s,i,o)}function h(e,n,r){return R(e)||R(n)||R(r)||!(e<=r&&r<=n)?NaN:J(t,e,n,r)}},q=M(),z=M;e(q,"factory",z);var F=q;export{F as default,z as factory}; +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";var g=p.isPrimitive,j=u,c=h;var b=function(e,t,n){return!g(e)||c(e)?new TypeError(j("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!g(t)||c(t)?new TypeError(j("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!g(n)||c(n)?new TypeError(j("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(j("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))},v=f;var y=function(e,t,n,r){var s,i;return s=(r-t)/(n-t),(i=e())3){if(!T(e=arguments[3]))throw new TypeError(V("0PT2h",e));if(L(e,"prng")){if(!E(e.prng))throw new TypeError(V("0PT7M","prng",e.prng));t=e.prng}else t=R(e)}else t=R()}return w(n=void 0===s?g:f,"NAME","triangular"),e&&e.prng?(w(n,"seed",null),w(n,"seedLength",null),N(n,"state",P(null),M),w(n,"stateLength",null),w(n,"byteLength",null),w(n,"toJSON",P(null)),w(n,"PRNG",t)):(x(n,"seed",m),x(n,"seedLength",d),N(n,"state",u,p),x(n,"stateLength",a),x(n,"byteLength",l),w(n,"toJSON",h),w(n,"PRNG",t),t=t.normalized),n;function m(){return t.seed}function d(){return t.seedLength}function a(){return t.stateLength}function l(){return t.byteLength}function u(){return t.state}function p(e){t.state=e}function h(){var e={type:"PRNG"};return e.name=n.NAME,e.state=S(t.state),e.params=void 0===s?[]:[s,i,o],e}function f(){return J(t,s,i,o)}function g(e,n,r){return G(e)||G(n)||G(r)||!(e<=r&&r<=n)?NaN:J(t,e,n,r)}},q=O(),z=O;e(q,"factory",z);var F=q;export{F as default,z as factory}; //# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map index 9bf2fec..6d985a7 100644 --- a/index.mjs.map +++ b/index.mjs.map @@ -1 +1 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/index.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not `NaN`. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not `NaN`. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not `NaN`. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. The condition `a <= c <= b` must be satisfied. Value: `[%f,%f,%f]`.', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `prng` option must be a pseudorandom number generator function. Option: `%s`.', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `prng` option must be a pseudorandom number generator function. Option: `%s`.', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar triangular = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n"],"names":["isNumber","require$$0","isPrimitive","format","require$$1","isnan","require$$2","validate_1","a","b","c","TypeError","RangeError","sqrt","triangular_1","rand","fc","u","setReadOnly","setReadOnlyAccessor","setReadWriteAccessor","isObject","require$$3","isFunction","require$$4","hasOwnProp","require$$5","constantFunction","require$$6","noop","require$$7","randu","require$$8","factory","require$$9","typedarray2json","require$$10","require$$11","validate","require$$12","triangular0","require$$13","factory_1","opts","prng","err","arguments","length","triangular2","triangular1","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","params","NaN","triangular","lib"],"mappings":";;21CAsBA,IAAIA,EAAWC,EAAsCC,YACjDC,EAASC,EACTC,EAAQC,EAuCZ,IAAAC,EAnBA,SAAmBC,EAAGC,EAAGC,GACxB,OAAMV,EAAUQ,IAAOH,EAAOG,GACtB,IAAIG,UAAWR,EAAQ,gFAAiFK,KAE1GR,EAAUS,IAAOJ,EAAOI,GACtB,IAAIE,UAAWR,EAAQ,iFAAkFM,KAE3GT,EAAUU,IAAOL,EAAOK,GACtB,IAAIC,UAAWR,EAAQ,gFAAiFO,IAEzGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIG,WAAYT,EAAQ,yFAA0FK,EAAGC,EAAGC,KCjC7HG,EAAOZ,EAgCX,IAAAa,EAjBA,SAAqBC,EAAMP,EAAGC,EAAGC,GAChC,IAAIM,EAEAC,EAGJ,OAFAD,GAAMN,EAAIF,IAAMC,EAAID,IACpBS,EAAIF,KACKC,EAEDR,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACES,GAGfR,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAMO,KC1BzBC,EAAcjB,EACdkB,EAAsBf,EACtBgB,EAAuBd,EACvBe,EAAWC,EACXC,EAAaC,EACbC,EAAaC,EACbC,EAAmBC,EACnBC,EAAOC,EACPC,EAAQC,EAAyCC,QACjD5B,EAAQ6B,EACRC,EAAkBC,EAClBjC,EAASkC,EACTC,EAAWC,EACXC,EAAcC,EA0PlB,IAAAC,EApNA,WACC,IAAIC,EACA5B,EACA6B,EACAC,EACArC,EACAC,EACAC,EAEJ,GAA0B,IAArBoC,UAAUC,OACdhC,EAAOgB,SACD,GAA0B,IAArBe,UAAUC,OAAe,CAEpC,IAAM1B,EADNsB,EAAOG,UAAW,IAEjB,MAAM,IAAInC,UAAWR,EAAQ,qEAAsEwC,IAEpG,GAAKlB,EAAYkB,EAAM,QAAW,CACjC,IAAMpB,EAAYoB,EAAKC,MACtB,MAAM,IAAIjC,UAAWR,EAAQ,gGAAiGwC,EAAKC,OAEpI7B,EAAO4B,EAAKC,UAEZ7B,EAAOgB,EAAOY,OAET,CAKN,GADAE,EAAMP,EAHN9B,EAAIsC,UAAW,GACfrC,EAAIqC,UAAW,GACfpC,EAAIoC,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAM1B,EADNsB,EAAOG,UAAW,IAEjB,MAAM,IAAInC,UAAWR,EAAQ,qEAAsEwC,IAEpG,GAAKlB,EAAYkB,EAAM,QAAW,CACjC,IAAMpB,EAAYoB,EAAKC,MACtB,MAAM,IAAIjC,UAAWR,EAAQ,gGAAiGwC,EAAKC,OAEpI7B,EAAO4B,EAAKC,UAEZ7B,EAAOgB,EAAOY,QAGf5B,EAAOgB,IA6BT,OArBAb,EAJC0B,OADU,IAANpC,EACGwC,EAEAC,EAEW,OAAQ,cAGtBN,GAAQA,EAAKC,MACjB1B,EAAa0B,EAAM,OAAQ,MAC3B1B,EAAa0B,EAAM,aAAc,MACjCxB,EAAsBwB,EAAM,QAASjB,EAAkB,MAAQE,GAC/DX,EAAa0B,EAAM,cAAe,MAClC1B,EAAa0B,EAAM,aAAc,MACjC1B,EAAa0B,EAAM,SAAUjB,EAAkB,OAC/CT,EAAa0B,EAAM,OAAQ7B,KAE3BI,EAAqByB,EAAM,OAAQM,GACnC/B,EAAqByB,EAAM,aAAcO,GACzC/B,EAAsBwB,EAAM,QAASQ,EAAUC,GAC/ClC,EAAqByB,EAAM,cAAeU,GAC1CnC,EAAqByB,EAAM,aAAcW,GACzCrC,EAAa0B,EAAM,SAAUY,GAC7BtC,EAAa0B,EAAM,OAAQ7B,GAC3BA,EAAOA,EAAK0C,YAENb,EAQP,SAASM,IACR,OAAOnC,EAAK2C,KASb,SAASP,IACR,OAAOpC,EAAK4C,WASb,SAASL,IACR,OAAOvC,EAAK6C,YASb,SAASL,IACR,OAAOxC,EAAK8C,WASb,SAAST,IACR,OAAOrC,EAAK+C,MAUb,SAAST,EAAUU,GAClBhD,EAAK+C,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAOrB,EAAKsB,KAChBF,EAAIF,MAAQ3B,EAAiBpB,EAAK+C,OAEjCE,EAAIG,YADM,IAAN3D,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEfsD,EAaR,SAASf,IACR,OAAOT,EAAazB,EAAMP,EAAGC,EAAGC,GAwBjC,SAASsC,EAAaxC,EAAGC,EAAGC,GAC3B,OACCL,EAAOG,IACPH,EAAOI,IACPJ,EAAOK,MACLF,GAAKE,GAAKA,GAAKD,GAEV2D,IAED5B,EAAazB,EAAMP,EAAGC,EAAGC,KCjOlC2D,EC/BcpE,IDgCdgC,EAAA3B,EAFAL,EAOAoE,EAAA,UAAApC,GAKA,IAAAqC,EAAAD"} \ No newline at end of file +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/index.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/error-tools-fmtprodmsg' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/error-tools-fmtprodmsg' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar triangular = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n"],"names":["isNumber","require$$0","isPrimitive","format","require$$1","isnan","require$$2","validate_1","a","b","c","TypeError","RangeError","sqrt","triangular_1","rand","fc","u","setReadOnly","setReadOnlyAccessor","setReadWriteAccessor","isObject","require$$3","isFunction","require$$4","hasOwnProp","require$$5","constantFunction","require$$6","noop","require$$7","randu","require$$8","factory","require$$9","typedarray2json","require$$10","require$$11","validate","require$$12","triangular0","require$$13","factory_1","opts","prng","err","arguments","length","triangular2","triangular1","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","params","NaN","triangular","lib"],"mappings":";;o2CAsBA,IAAIA,EAAWC,EAAsCC,YACjDC,EAASC,EACTC,EAAQC,EAuCZ,IAAAC,EAnBA,SAAmBC,EAAGC,EAAGC,GACxB,OAAMV,EAAUQ,IAAOH,EAAOG,GACtB,IAAIG,UAAWR,EAAQ,8EAA+EK,KAExGR,EAAUS,IAAOJ,EAAOI,GACtB,IAAIE,UAAWR,EAAQ,+EAAgFM,KAEzGT,EAAUU,IAAOL,EAAOK,GACtB,IAAIC,UAAWR,EAAQ,8EAA+EO,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIG,WAAYT,EAAQ,qGAAsG,cAAeK,EAAGC,EAAGC,KCjCxJG,EAAOZ,EAgCX,IAAAa,EAjBA,SAAqBC,EAAMP,EAAGC,EAAGC,GAChC,IAAIM,EAEAC,EAGJ,OAFAD,GAAMN,EAAIF,IAAMC,EAAID,IACpBS,EAAIF,KACKC,EAEDR,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACES,GAGfR,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAMO,KC1BzBC,EAAcjB,EACdkB,EAAsBf,EACtBgB,EAAuBd,EACvBe,EAAWC,EACXC,EAAaC,EACbC,EAAaC,EACbC,EAAmBC,EACnBC,EAAOC,EACPC,EAAQC,EAAyCC,QACjD5B,EAAQ6B,EACRC,EAAkBC,EAClBjC,EAASkC,EACTC,EAAWC,EACXC,EAAcC,EA0PlB,IAAAC,EApNA,WACC,IAAIC,EACA5B,EACA6B,EACAC,EACArC,EACAC,EACAC,EAEJ,GAA0B,IAArBoC,UAAUC,OACdhC,EAAOgB,SACD,GAA0B,IAArBe,UAAUC,OAAe,CAEpC,IAAM1B,EADNsB,EAAOG,UAAW,IAEjB,MAAM,IAAInC,UAAWR,EAAQ,QAASwC,IAEvC,GAAKlB,EAAYkB,EAAM,QAAW,CACjC,IAAMpB,EAAYoB,EAAKC,MACtB,MAAM,IAAIjC,UAAWR,EAAQ,QAAS,OAAQwC,EAAKC,OAEpD7B,EAAO4B,EAAKC,UAEZ7B,EAAOgB,EAAOY,OAET,CAKN,GADAE,EAAMP,EAHN9B,EAAIsC,UAAW,GACfrC,EAAIqC,UAAW,GACfpC,EAAIoC,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAM1B,EADNsB,EAAOG,UAAW,IAEjB,MAAM,IAAInC,UAAWR,EAAQ,QAASwC,IAEvC,GAAKlB,EAAYkB,EAAM,QAAW,CACjC,IAAMpB,EAAYoB,EAAKC,MACtB,MAAM,IAAIjC,UAAWR,EAAQ,QAAS,OAAQwC,EAAKC,OAEpD7B,EAAO4B,EAAKC,UAEZ7B,EAAOgB,EAAOY,QAGf5B,EAAOgB,IA6BT,OArBAb,EAJC0B,OADU,IAANpC,EACGwC,EAEAC,EAEW,OAAQ,cAGtBN,GAAQA,EAAKC,MACjB1B,EAAa0B,EAAM,OAAQ,MAC3B1B,EAAa0B,EAAM,aAAc,MACjCxB,EAAsBwB,EAAM,QAASjB,EAAkB,MAAQE,GAC/DX,EAAa0B,EAAM,cAAe,MAClC1B,EAAa0B,EAAM,aAAc,MACjC1B,EAAa0B,EAAM,SAAUjB,EAAkB,OAC/CT,EAAa0B,EAAM,OAAQ7B,KAE3BI,EAAqByB,EAAM,OAAQM,GACnC/B,EAAqByB,EAAM,aAAcO,GACzC/B,EAAsBwB,EAAM,QAASQ,EAAUC,GAC/ClC,EAAqByB,EAAM,cAAeU,GAC1CnC,EAAqByB,EAAM,aAAcW,GACzCrC,EAAa0B,EAAM,SAAUY,GAC7BtC,EAAa0B,EAAM,OAAQ7B,GAC3BA,EAAOA,EAAK0C,YAENb,EAQP,SAASM,IACR,OAAOnC,EAAK2C,KASb,SAASP,IACR,OAAOpC,EAAK4C,WASb,SAASL,IACR,OAAOvC,EAAK6C,YASb,SAASL,IACR,OAAOxC,EAAK8C,WASb,SAAST,IACR,OAAOrC,EAAK+C,MAUb,SAAST,EAAUU,GAClBhD,EAAK+C,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAOrB,EAAKsB,KAChBF,EAAIF,MAAQ3B,EAAiBpB,EAAK+C,OAEjCE,EAAIG,YADM,IAAN3D,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEfsD,EAaR,SAASf,IACR,OAAOT,EAAazB,EAAMP,EAAGC,EAAGC,GAwBjC,SAASsC,EAAaxC,EAAGC,EAAGC,GAC3B,OACCL,EAAOG,IACPH,EAAOI,IACPJ,EAAOK,MACLF,GAAKE,GAAKA,GAAKD,GAEV2D,IAED5B,EAAazB,EAAMP,EAAGC,EAAGC,KCjOlC2D,EC/BcpE,IDgCdgC,EAAA3B,EAFAL,EAOAoE,EAAA,UAAApC,GAKA,IAAAqC,EAAAD"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2346fdb..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e703573..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var triangular = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( triangular, 'factory', factory ); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 99526d7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7ad8f32..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html index e68c85e..519c024 100644 --- a/stats.html +++ b/stats.html @@ -2669,7 +2669,7 @@ - - - - From dc7fad107227a26fab483f1987586b1dbd4a88a0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:53:54 +0000 Subject: [PATCH 05/83] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 -- docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 --- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 985 -------- test/test.js | 124 - 45 files changed, 2718 insertions(+), 5503 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index df2ff07..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:44:17.386Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index 1cb73f2..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16 ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d2c11af --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2573d4c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport triangular from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default triangular;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN"],"mappings":";;83CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAAf,EAAA,UAAAK"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e703573..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var triangular = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( triangular, 'factory', factory ); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4516886..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0c678fa --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 6a5c4d78023ac68710dcda1475a058dbab7e7c4e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 13:40:03 +0000 Subject: [PATCH 06/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..8532c20 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..b2efdf0 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); diff --git a/package.json b/package.json index 7ad8f32..4516886 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.x", "@stdlib/math-base-special-sqrt": "^0.0.x", "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-constant-function": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 9b2c037194aad5c28e6a23b8952a377117a25d83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 14:27:51 +0000 Subject: [PATCH 07/83] Remove files --- index.d.ts | 243 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2937 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d2c11af..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2573d4c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport triangular from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default triangular;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN"],"mappings":";;83CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAAf,EAAA,UAAAK"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0c678fa..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 11140b2850c6411808622c92ada0a4960a98dd53 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 14:29:02 +0000 Subject: [PATCH 08/83] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 687 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 -- docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 --- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 985 -------- test/test.js | 124 - 44 files changed, 2718 insertions(+), 5468 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 6726965..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,687 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index 1cb73f2..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16 ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d2c11af --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2573d4c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport triangular from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default triangular;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN"],"mappings":";;83CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAAf,EAAA,UAAAK"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e703573..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var triangular = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( triangular, 'factory', factory ); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4516886..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e06f10e --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From fb75ac41e70d3c480f41dbe10b99b24e31c245f3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 04:02:54 +0000 Subject: [PATCH 09/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..8532c20 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..b2efdf0 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); diff --git a/package.json b/package.json index 7ad8f32..4516886 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.x", "@stdlib/math-base-special-sqrt": "^0.0.x", "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-constant-function": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 25368af29bfba3cc6db4589eca9ba6e03223e9f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:55:26 +0000 Subject: [PATCH 10/83] Remove files --- index.d.ts | 243 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2937 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d2c11af..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2573d4c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport triangular from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default triangular;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN"],"mappings":";;83CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAAf,EAAA,UAAAK"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e06f10e..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From acbb1c66d3f4110f9b3fced741ec692c64d448b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:56:16 +0000 Subject: [PATCH 11/83] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 -- docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 --- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 985 -------- test/test.js | 124 - 45 files changed, 2718 insertions(+), 5542 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2f9882d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:46:23.005Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index 1cb73f2..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16 ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79f19cc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..46eb1ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport triangular from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default triangular;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAAf,EAAA,UAAAK"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e703573..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var triangular = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( triangular, 'factory', factory ); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4516886..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..40aaf03 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From e0ea9d1603a5721d3a5ab70259f4788199916c33 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:54:14 +0000 Subject: [PATCH 12/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..8532c20 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..b2efdf0 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); diff --git a/package.json b/package.json index 7ad8f32..4516886 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.x", "@stdlib/math-base-special-sqrt": "^0.0.x", "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-constant-function": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From c8784513e0bba3551d104e2ebaaa1a0197a37b87 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 17:34:52 +0000 Subject: [PATCH 13/83] Remove files --- index.d.ts | 243 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2937 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f19cc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 46eb1ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport triangular from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default triangular;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAAf,EAAA,UAAAK"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 40aaf03..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From dd1c0e54d10e33c718c9d50c62f26edad100a690 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 17:35:49 +0000 Subject: [PATCH 14/83] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 -- docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 --- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 985 -------- test/test.js | 124 - 45 files changed, 2718 insertions(+), 5558 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5bcc07f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:46:45.160Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index 1cb73f2..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16 ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79f19cc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..46eb1ad --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport triangular from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default triangular;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAAf,EAAA,UAAAK"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e703573..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var triangular = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( triangular, 'factory', factory ); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4516886..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8290b71 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 9764866271de0f8fbb48fee8df7ee2458dd9be89 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:24:25 +0000 Subject: [PATCH 15/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..8532c20 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..b2efdf0 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); diff --git a/package.json b/package.json index 7ad8f32..4516886 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.x", "@stdlib/math-base-special-sqrt": "^0.0.x", "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-constant-function": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From f4749745df2be867e5cd3ef815d76a3de45a3859 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:24:41 +0000 Subject: [PATCH 16/83] Remove files --- index.d.ts | 243 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2937 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f19cc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 46eb1ad..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport triangular from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( triangular, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default triangular;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAAf,EAAA,UAAAK"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8290b71..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From db292e9efbf72fc52228ecab07be1dcec99f0e00 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:25:35 +0000 Subject: [PATCH 17/83] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 -- docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 --- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 985 -------- test/test.js | 124 - 45 files changed, 2718 insertions(+), 5558 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 9d68e46..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:14:52.781Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index 1cb73f2..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16 ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79f19cc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5543a59 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4516886..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..98a3a9e --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From b9899b709c9515b3e5aceff91268fc1c2c0c6545 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 04:06:49 +0000 Subject: [PATCH 18/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..8532c20 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..b2efdf0 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); diff --git a/package.json b/package.json index 7ad8f32..4516886 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.x", "@stdlib/math-base-special-sqrt": "^0.0.x", "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-constant-function": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From dcad2fcd784facc037a8cb7c4569ab58a4bf133e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 12:17:23 +0000 Subject: [PATCH 19/83] Remove files --- index.d.ts | 243 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2937 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f19cc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5543a59..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,IClB5J,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,ICyB7B,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,OAET,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,UAEZN,EAAOU,EAAOL,QAGfL,EAAOU,IA6BT,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,KASb,SAASP,IACR,OAAOtB,EAAK8B,WASb,SAASL,IACR,OAAOzB,EAAK+B,YASb,SAASL,IACR,OAAO1B,EAAKgC,WASb,SAAST,IACR,OAAOvB,EAAKiC,MAUb,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,EAad,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,EAaR,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,GAwBjC,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,IC7O/B,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 98a3a9e..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From e2b27e9ba1890a6ca07f3682ac4a27245f9c77f4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 12:18:15 +0000 Subject: [PATCH 20/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 - docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 -- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 985 ----- test/test.js | 124 - 45 files changed, 4073 insertions(+), 5558 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f53febe..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:59:45.192Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2906a3a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index 1cb73f2..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16 ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79f19cc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..43ea0a9 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4516886..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4a0e160 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 049d451621160e58ad6685cd318e580f30cb4e1b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:43:22 +0000 Subject: [PATCH 21/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..8532c20 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..b2efdf0 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); diff --git a/package.json b/package.json index 7ad8f32..4516886 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.x", "@stdlib/math-base-special-sqrt": "^0.0.x", "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-constant-function": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From b445d954c9859b5377e9929cf87bc4e7ba470a70 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 14:45:16 +0000 Subject: [PATCH 22/83] Remove files --- index.d.ts | 243 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4292 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f19cc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 43ea0a9..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4a0e160..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 3774070fbe4d15f8171e19372305ad60e0e3a96b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 14:46:28 +0000 Subject: [PATCH 23/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 - docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 -- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 985 ----- test/test.js | 124 - 45 files changed, 4073 insertions(+), 5579 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f4f1566..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T23:03:07.831Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2906a3a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index 1cb73f2..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16 ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79f19cc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..43ea0a9 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4516886..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ca4f47f --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 6e4c7e8e567d0c1283d3621793ceabf5a838a825 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 8 Nov 2022 22:00:05 +0000 Subject: [PATCH 24/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..8532c20 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..b2efdf0 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); diff --git a/package.json b/package.json index 7ad8f32..4516886 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.x", "@stdlib/math-base-special-sqrt": "^0.0.x", "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-constant-function": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 0ccb6a7a7564993c4ff884353b328f4e1ce5f17e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 8 Nov 2022 23:16:06 +0000 Subject: [PATCH 25/83] Remove files --- index.d.ts | 243 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4292 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f19cc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 43ea0a9..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ca4f47f..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 782bbc791db90f35b0123814452e6ab268b99d0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 8 Nov 2022 23:17:11 +0000 Subject: [PATCH 26/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 - docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 -- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 985 ----- test/test.js | 124 - 44 files changed, 4073 insertions(+), 5578 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2906a3a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79f19cc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..43ea0a9 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4516886..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2699694 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 2b0fa94b5d467f33d9b4aa6b02ce7d227e913908 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 02:52:05 +0000 Subject: [PATCH 27/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..8532c20 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..b2efdf0 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); diff --git a/package.json b/package.json index dab8388..4e7ab68 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.x", "@stdlib/math-base-special-sqrt": "^0.0.x", "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-constant-function": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 33982279ea9b6374d784648e69757145739d5752 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 15:48:42 +0000 Subject: [PATCH 28/83] Remove files --- index.d.ts | 243 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4292 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f19cc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 43ea0a9..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isnan from '@stdlib/assert-is-nan' ;\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor' ;\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport constantFunction from '@stdlib/utils-constant-function' ;\nimport noop from '@stdlib/utils-noop' ;\nimport { factory as randu } from '@stdlib/random-base-mt19937' ;\nimport isnan from '@stdlib/math-base-assert-is-nan' ;\nimport typedarray2json from '@stdlib/array-to-json' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport validate from './validate.js' ;\nimport triangular0 from './triangular.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular' ;\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular' ;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2699694..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2c677597685722032d6238d8387c7c46f2768e98 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 15:49:41 +0000 Subject: [PATCH 29/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 183 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 - docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 -- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 985 ----- test/test.js | 124 - 45 files changed, 4073 insertions(+), 5584 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 04f9a41..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:51:24.881Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2906a3a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79f19cc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2381331 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4e7ab68..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..041d3dd --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 995201400a85d96c0bae30f88b5bab3ddea97ca7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 04:22:42 +0000 Subject: [PATCH 30/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..8532c20 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0PT2h', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..b2efdf0 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); diff --git a/package.json b/package.json index 6f510b4..4a22aae 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.x", "@stdlib/math-base-special-sqrt": "^0.0.x", "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-constant-function": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From d5ad98969d88b86dfcca92ccc9e8dc9176649722 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 13:25:24 +0000 Subject: [PATCH 31/83] Remove files --- index.d.ts | 243 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4292 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f19cc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2381331..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 041d3dd..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1001baf121ef29f30216bcbecbde1a40d824ba56 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 13:26:40 +0000 Subject: [PATCH 32/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 --- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 985 ---- test/test.js | 124 - 45 files changed, 6206 insertions(+), 5595 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8a422bf..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T02:37:48.640Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2906a3a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cbcaf7f..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5712d7d..478f7bf 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2fbaf8e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2381331 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8532c20..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0PT2h', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0PT7M', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index b2efdf0..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4a22aae..4be848f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-nan": "^0.0.x", - "@stdlib/assert-is-number": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-sqrt": "^0.0.x", - "@stdlib/random-base-mt19937": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-constant-function": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/assert-is-uint32array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/process-env": "^0.0.x", - "@stdlib/random-base-minstd": "^0.0.x", - "@stdlib/random-base-minstd-shuffle": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/stats-kstest": "^0.0.x", - "@stdlib/time-now": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9da3a50 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index e7856d5..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fbcac0e..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 5300d7b06f02997d9884a94673b67d667c09ecc0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 20 Aug 2023 01:58:42 +0000 Subject: [PATCH 33/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..c49a816 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V,FD', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V,FD', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..2ddd109 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); @@ -44,16 +44,16 @@ var isnan = require( '@stdlib/assert-is-nan' ); */ function validate( a, b, c ) { if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); + return new TypeError( format( '0p96v,NI', a ) ); } if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); + return new TypeError( format( '0p96w,NJ', b ) ); } if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); + return new TypeError( format( '0p97C,NR', c ) ); } if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); + return new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) ); } return null; } diff --git a/package.json b/package.json index cfe5a22..12347da 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.0.8", "@stdlib/math-base-special-sqrt": "^0.0.8", "@stdlib/random-base-mt19937": "^0.0.6", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-constant-function": "^0.0.8", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.7", From a9a96288ddf82c8e1d56730785d8616fd4046cb0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 20 Aug 2023 02:31:47 +0000 Subject: [PATCH 34/83] Remove files --- index.d.ts | 243 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6425 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 478f7bf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2fbaf8e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function g(e,t,n){return!p(e)||h(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||h(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||h(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("0PT2h",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("0PT7M","prng",p.prng));h=p.prng}else h=m(p)}else h=m()}return e(f=void 0===b?R:M,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",h)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",E,L),t(f,"stateLength",N),t(f,"byteLength",T),e(f,"toJSON",P),e(f,"PRNG",h),h=h.normalized),f;function w(){return h.seed}function x(){return h.seedLength}function N(){return h.stateLength}function T(){return h.byteLength}function E(){return h.state}function L(e){h.state=e}function P(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(h.state),e.params=void 0===b?[]:[b,v,y],e}function M(){return j(h,b,v,y)}function R(e,t,n){return a(e)||a(t)||a(n)||!(e<=n&&n<=t)?NaN:j(h,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2381331..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0PT2h', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0PT7M', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,QAASQ,IAEvC,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,QAAS,OAAQQ,EAAKC,OAEpDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9da3a50..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a10d10fa5edd7cd805d27c06a96df42e4a00911b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 20 Aug 2023 02:33:06 +0000 Subject: [PATCH 35/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 985 ---- test/test.js | 124 - 47 files changed, 6206 insertions(+), 5741 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2906a3a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -441,7 +440,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -503,7 +502,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9bce72d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0bd3c83..29ef36b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0721c00 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function u(e,t,n){return!h(e)||j(e)?new TypeError(a("0p96v,NI",e)):!h(t)||j(t)?new TypeError(a("0p96w,NJ",t)):!h(n)||j(n)?new TypeError(a("0p97C,NR",n)):e<=n&&n<=t?null:new RangeError(a("0p99C,HP","a <= c <= b",e,t,n))}function g(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(h=arguments[3]))throw new TypeError(a("0p92V,FD",h));if(i(h,"prng")){if(!r(h.prng))throw new TypeError(a("0p96u,JI","prng",h.prng));j=h.prng}else j=m(h)}else j=m()}return e(f=void 0===b?P:R,"NAME","triangular"),h&&h.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",j)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",J),e(f,"PRNG",j),j=j.normalized),f;function w(){return j.seed}function x(){return j.seedLength}function N(){return j.stateLength}function E(){return j.byteLength}function L(){return j.state}function T(e){j.state=e}function J(){var e={type:"PRNG"};return e.name=f.NAME,e.state=p(j.state),e.params=void 0===b?[]:[b,v,y],e}function R(){return g(j,b,v,y)}function P(e,t,n){return l(e)||l(t)||l(n)||!(e<=n&&n<=t)?NaN:g(j,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..16d37d1 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v,NI', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w,NJ', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C,NR', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,WAAYN,KAErCG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,WAAYL,KAErCE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,WAAYJ,IAEpCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,WAAY,cAAeN,EAAGC,EAAGC,GAGlE,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index c49a816..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2ddd109..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v,NI', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w,NJ', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C,NR', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 12347da..1c99f6b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.0.7", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-nan": "^0.0.8", - "@stdlib/assert-is-number": "^0.0.7", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/math-base-assert-is-nan": "^0.0.8", - "@stdlib/math-base-special-sqrt": "^0.0.8", - "@stdlib/random-base-mt19937": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-constant-function": "^0.0.8", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.7", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.0.7", - "@stdlib/utils-noop": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/assert-is-uint32array": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-uint32-max": "^0.0.7", - "@stdlib/process-env": "^0.0.7", - "@stdlib/random-base-minstd": "^0.0.6", - "@stdlib/random-base-minstd-shuffle": "^0.0.6", - "@stdlib/random-base-randu": "^0.0.8", - "@stdlib/stats-kstest": "^0.0.7", - "@stdlib/time-now": "^0.0.9", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e15cc68 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 4775e56dbf2c8f2a456cf434509c44e602b81e07 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 18:25:49 +0000 Subject: [PATCH 36/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..c49a816 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V,FD', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V,FD', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..2ddd109 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); @@ -44,16 +44,16 @@ var isnan = require( '@stdlib/assert-is-nan' ); */ function validate( a, b, c ) { if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); + return new TypeError( format( '0p96v,NI', a ) ); } if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); + return new TypeError( format( '0p96w,NJ', b ) ); } if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); + return new TypeError( format( '0p97C,NR', c ) ); } if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); + return new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) ); } return null; } diff --git a/package.json b/package.json index 648716a..0cd9694 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.1.0", "@stdlib/math-base-special-sqrt": "^0.1.0", "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-constant-function": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.0", From 65dcd2d69248f32e56263c86e99d0b7983929144 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 19:26:18 +0000 Subject: [PATCH 37/83] Remove files --- index.d.ts | 243 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6425 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 29ef36b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0721c00..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@esm/index.mjs";function u(e,t,n){return!h(e)||j(e)?new TypeError(a("0p96v,NI",e)):!h(t)||j(t)?new TypeError(a("0p96w,NJ",t)):!h(n)||j(n)?new TypeError(a("0p97C,NR",n)):e<=n&&n<=t?null:new RangeError(a("0p99C,HP","a <= c <= b",e,t,n))}function g(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(h=arguments[3]))throw new TypeError(a("0p92V,FD",h));if(i(h,"prng")){if(!r(h.prng))throw new TypeError(a("0p96u,JI","prng",h.prng));j=h.prng}else j=m(h)}else j=m()}return e(f=void 0===b?P:R,"NAME","triangular"),h&&h.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",j)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",J),e(f,"PRNG",j),j=j.normalized),f;function w(){return j.seed}function x(){return j.seedLength}function N(){return j.stateLength}function E(){return j.byteLength}function L(){return j.state}function T(e){j.state=e}function J(){var e={type:"PRNG"};return e.name=f.NAME,e.state=p(j.state),e.params=void 0===b?[]:[b,v,y],e}function R(){return g(j,b,v,y)}function P(e,t,n){return l(e)||l(t)||l(n)||!(e<=n&&n<=t)?NaN:g(j,e,t,n)}}var b=c();e(b,"factory",c);export{b as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 16d37d1..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v,NI', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w,NJ', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C,NR', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;64CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,WAAYN,KAErCG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,WAAYL,KAErCE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,WAAYJ,IAEpCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,WAAY,cAAeN,EAAGC,EAAGC,GAGlE,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e15cc68..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4eab2b0df35277b783a6ba09d7360d8e1aca12a6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 19:30:12 +0000 Subject: [PATCH 38/83] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 985 ---- test/test.js | 124 - 48 files changed, 6206 insertions(+), 5776 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 76c8907..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2906a3a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -452,7 +451,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -514,7 +513,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9bce72d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0bd3c83..29ef36b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..93861ba --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.0-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.0-esm/index.mjs";function u(e,t,n){return!h(e)||j(e)?new TypeError(a("0p96v,NI",e)):!h(t)||j(t)?new TypeError(a("0p96w,NJ",t)):!h(n)||j(n)?new TypeError(a("0p97C,NR",n)):e<=n&&n<=t?null:new RangeError(a("0p99C,HP","a <= c <= b",e,t,n))}function g(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(h=arguments[3]))throw new TypeError(a("0p92V,FD",h));if(i(h,"prng")){if(!r(h.prng))throw new TypeError(a("0p96u,JI","prng",h.prng));j=h.prng}else j=m(h)}else j=m()}return e(f=void 0===v?P:R,"NAME","triangular"),h&&h.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",j)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",J),e(f,"PRNG",j),j=j.normalized),f;function w(){return j.seed}function x(){return j.seedLength}function N(){return j.stateLength}function E(){return j.byteLength}function L(){return j.state}function T(e){j.state=e}function J(){var e={type:"PRNG"};return e.name=f.NAME,e.state=p(j.state),e.params=void 0===v?[]:[v,b,y],e}function R(){return g(j,v,b,y)}function P(e,t,n){return l(e)||l(t)||l(n)||!(e<=n&&n<=t)?NaN:g(j,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c86fa04 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v,NI', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w,NJ', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C,NR', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;y9CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,WAAYN,KAErCG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,WAAYL,KAErCE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,WAAYJ,IAEpCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,WAAY,cAAeN,EAAGC,EAAGC,GAGlE,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index c49a816..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2ddd109..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v,NI', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w,NJ', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C,NR', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 0cd9694..0972826 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-nan": "^0.1.0", - "@stdlib/assert-is-number": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.0", - "@stdlib/math-base-special-sqrt": "^0.1.0", - "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-constant-function": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.0", - "@stdlib/utils-noop": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/assert-is-uint32array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-uint32-max": "^0.1.0", - "@stdlib/process-env": "^0.1.0", - "@stdlib/random-base-minstd": "^0.0.6", - "@stdlib/random-base-minstd-shuffle": "^0.0.6", - "@stdlib/random-base-randu": "^0.0.8", - "@stdlib/stats-kstest": "^0.1.0", - "@stdlib/time-now": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d06f2a2 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From b34e18c36ca8168fd2807c40de0875281a3bdb73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 20:07:58 +0000 Subject: [PATCH 39/83] Update README.md for ESM bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index adb9c23..5fd0ee1 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@esm/index.mjs'; +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.1.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.1.0-esm/index.mjs'; ``` #### triangular( a, b, c ) @@ -397,7 +397,7 @@ var o = rand.toJSON(); - - - - From 7daf592434acd543f1accc7d92e0e4aa24f30e52 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 03:17:03 +0000 Subject: [PATCH 43/83] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 124 - test/test.factory.js | 985 ---- test/test.js | 124 - 50 files changed, 6206 insertions(+), 5959 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f342423..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T05:50:28.659Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 6fb7d10..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -452,7 +451,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -514,7 +513,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9bce72d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0bd3c83..29ef36b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4cc242e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.0-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.0-esm/index.mjs";function u(e,t,n){return!h(e)||j(e)?new TypeError(a("0p96v,NI",e)):!h(t)||j(t)?new TypeError(a("0p96w,NJ",t)):!h(n)||j(n)?new TypeError(a("0p97C,NR",n)):e<=n&&n<=t?null:new RangeError(a("0p99C,HP","a <= c <= b",e,t,n))}function g(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(h=arguments[3]))throw new TypeError(a("0p92V,FD",h));if(i(h,"prng")){if(!r(h.prng))throw new TypeError(a("0p96u,JI","prng",h.prng));j=h.prng}else j=m(h)}else j=m()}return e(f=void 0===v?P:R,"NAME","triangular"),h&&h.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",j)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",J),e(f,"PRNG",j),j=j.normalized),f;function w(){return j.seed}function x(){return j.seedLength}function N(){return j.stateLength}function E(){return j.byteLength}function L(){return j.state}function T(e){j.state=e}function J(){var e={type:"PRNG"};return e.name=f.NAME,e.state=p(j.state),e.params=void 0===v?[]:[v,b,y],e}function R(){return g(j,v,b,y)}function P(e,t,n){return l(e)||l(t)||l(n)||!(e<=n&&n<=t)?NaN:g(j,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7b79ac1 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v,NI', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w,NJ', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C,NR', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;u+CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,WAAYN,KAErCG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,WAAYL,KAErCE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,WAAYJ,IAEpCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,WAAY,cAAeN,EAAGC,EAAGC,GAGlE,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index c49a816..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2ddd109..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v,NI', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w,NJ', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C,NR', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 237dd9e..0972826 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-nan": "^0.1.0", - "@stdlib/assert-is-number": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.0", - "@stdlib/math-base-special-sqrt": "^0.1.0", - "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-constant-function": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.0", - "@stdlib/utils-noop": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/assert-is-uint32array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-uint32-max": "^0.1.0", - "@stdlib/process-env": "^0.1.0", - "@stdlib/random-base-minstd": "^0.1.0", - "@stdlib/random-base-minstd-shuffle": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/stats-kstest": "^0.1.0", - "@stdlib/time-now": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0676252 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 6cc2d99..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 3d4037153080812427eee5b62c6a47d6a229ff70 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 18:12:48 +0000 Subject: [PATCH 44/83] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c364ec8..feb6812 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.1.1", "@stdlib/math-base-special-sqrt": "^0.1.0", "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-constant-function": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", From ce1a67eaf1a437b58518587d701b8c6e41c56ab6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 20:32:53 +0000 Subject: [PATCH 45/83] Remove files --- index.d.ts | 243 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6425 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 29ef36b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4cc242e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.0-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.0-esm/index.mjs";function u(e,t,n){return!h(e)||j(e)?new TypeError(a("0p96v,NI",e)):!h(t)||j(t)?new TypeError(a("0p96w,NJ",t)):!h(n)||j(n)?new TypeError(a("0p97C,NR",n)):e<=n&&n<=t?null:new RangeError(a("0p99C,HP","a <= c <= b",e,t,n))}function g(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(h=arguments[3]))throw new TypeError(a("0p92V,FD",h));if(i(h,"prng")){if(!r(h.prng))throw new TypeError(a("0p96u,JI","prng",h.prng));j=h.prng}else j=m(h)}else j=m()}return e(f=void 0===v?P:R,"NAME","triangular"),h&&h.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",j)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",J),e(f,"PRNG",j),j=j.normalized),f;function w(){return j.seed}function x(){return j.seedLength}function N(){return j.stateLength}function E(){return j.byteLength}function L(){return j.state}function T(e){j.state=e}function J(){var e={type:"PRNG"};return e.name=f.NAME,e.state=p(j.state),e.params=void 0===v?[]:[v,b,y],e}function R(){return g(j,v,b,y)}function P(e,t,n){return l(e)||l(t)||l(n)||!(e<=n&&n<=t)?NaN:g(j,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b79ac1..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v,NI', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w,NJ', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C,NR', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;u+CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,WAAYN,KAErCG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,WAAYL,KAErCE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,WAAYJ,IAEpCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,WAAY,cAAeN,EAAGC,EAAGC,GAGlE,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0676252..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 85d2cc45dddcfa5ed6185ab39eeb774210b97430 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 20:37:19 +0000 Subject: [PATCH 46/83] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 124 - test/test.factory.js | 985 ---- test/test.js | 124 - 49 files changed, 6206 insertions(+), 5958 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 6fb7d10..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -452,7 +451,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -514,7 +513,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9bce72d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0bd3c83..29ef36b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..179c8aa --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.0-esm/index.mjs";function h(e,t,n){return!p(e)||g(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||g(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||g(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.","prng",p.prng));g=p.prng}else g=m(p)}else g=m()}return e(f=void 0===v?P:V,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),a),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",g)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",O),e(f,"PRNG",g),g=g.normalized),f;function w(){return g.seed}function x(){return g.seedLength}function N(){return g.stateLength}function E(){return g.byteLength}function L(){return g.state}function T(e){g.state=e}function O(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(g.state),e.params=void 0===v?[]:[v,b,y],e}function V(){return j(g,v,b,y)}function P(e,t,n){return d(e)||d(t)||d(n)||!(e<=n&&n<=t)?NaN:j(g,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..675a21c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/string-format';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;89CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2346fdb..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 99526d7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index feb6812..0972826 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-nan": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-sqrt": "^0.1.0", - "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-constant-function": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/assert-is-uint32array": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/process-env": "^0.1.1", - "@stdlib/random-base-minstd": "^0.1.0", - "@stdlib/random-base-minstd-shuffle": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/stats-kstest": "^0.1.0", - "@stdlib/time-now": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..699a601 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 6cc2d99..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 3df737d62d16e60fcb3d6c989099dc627ed0e822 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 18:35:19 +0000 Subject: [PATCH 47/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..c49a816 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V,FD', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V,FD', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..2ddd109 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); @@ -44,16 +44,16 @@ var isnan = require( '@stdlib/assert-is-nan' ); */ function validate( a, b, c ) { if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); + return new TypeError( format( '0p96v,NI', a ) ); } if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); + return new TypeError( format( '0p96w,NJ', b ) ); } if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); + return new TypeError( format( '0p97C,NR', c ) ); } if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); + return new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) ); } return null; } diff --git a/package.json b/package.json index 2120d32..1861aea 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.1.1", "@stdlib/math-base-special-sqrt": "^0.1.1", "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-constant-function": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", From 10e7357e5a280f4acb62c082b03531179ca9949d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 03:35:56 +0000 Subject: [PATCH 48/83] Remove files --- index.d.ts | 243 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6425 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 29ef36b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 179c8aa..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.0-esm/index.mjs";function h(e,t,n){return!p(e)||g(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||g(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||g(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.","prng",p.prng));g=p.prng}else g=m(p)}else g=m()}return e(f=void 0===v?P:V,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),a),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",g)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",O),e(f,"PRNG",g),g=g.normalized),f;function w(){return g.seed}function x(){return g.seedLength}function N(){return g.stateLength}function E(){return g.byteLength}function L(){return g.state}function T(e){g.state=e}function O(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(g.state),e.params=void 0===v?[]:[v,b,y],e}function V(){return j(g,v,b,y)}function P(e,t,n){return d(e)||d(t)||d(n)||!(e<=n&&n<=t)?NaN:j(g,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 675a21c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/string-format';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;89CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 699a601..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 010099a0a84afeb5b726afc17ce3a8402b431e73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 03:39:46 +0000 Subject: [PATCH 49/83] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ---- test/test.js | 124 - 50 files changed, 6206 insertions(+), 5876 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 760846e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T06:12:24.571Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 6fb7d10..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -452,7 +451,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -514,7 +513,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9bce72d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 0bd3c83..29ef36b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4694f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function u(e,t,n){return!h(e)||j(e)?new TypeError(a("0p96v,NI",e)):!h(t)||j(t)?new TypeError(a("0p96w,NJ",t)):!h(n)||j(n)?new TypeError(a("0p97C,NR",n)):e<=n&&n<=t?null:new RangeError(a("0p99C,HP","a <= c <= b",e,t,n))}function g(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(h=arguments[3]))throw new TypeError(a("0p92V,FD",h));if(i(h,"prng")){if(!r(h.prng))throw new TypeError(a("0p96u,JI","prng",h.prng));j=h.prng}else j=m(h)}else j=m()}return e(f=void 0===v?P:R,"NAME","triangular"),h&&h.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",j)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",J),e(f,"PRNG",j),j=j.normalized),f;function w(){return j.seed}function x(){return j.seedLength}function N(){return j.stateLength}function E(){return j.byteLength}function L(){return j.state}function T(e){j.state=e}function J(){var e={type:"PRNG"};return e.name=f.NAME,e.state=p(j.state),e.params=void 0===v?[]:[v,b,y],e}function R(){return g(j,v,b,y)}function P(e,t,n){return l(e)||l(t)||l(n)||!(e<=n&&n<=t)?NaN:g(j,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7b79ac1 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v,NI', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w,NJ', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C,NR', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;u+CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,WAAYN,KAErCG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,WAAYL,KAErCE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,WAAYJ,IAEpCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,WAAY,cAAeN,EAAGC,EAAGC,GAGlE,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index c49a816..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2ddd109..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v,NI', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w,NJ', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C,NR', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 1861aea..0972826 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-nan": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-sqrt": "^0.1.1", - "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-constant-function": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/assert-is-uint32array": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/process-env": "^0.1.1", - "@stdlib/random-base-minstd": "^0.1.0", - "@stdlib/random-base-minstd-shuffle": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/stats-kstest": "^0.1.0", - "@stdlib/time-now": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4531eda --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 241020438de7efdd71ad94fb34a9bd36d43e3b81 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:40:46 +0000 Subject: [PATCH 50/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..c49a816 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V,FD', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V,FD', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..2ddd109 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); @@ -44,16 +44,16 @@ var isnan = require( '@stdlib/assert-is-nan' ); */ function validate( a, b, c ) { if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); + return new TypeError( format( '0p96v,NI', a ) ); } if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); + return new TypeError( format( '0p96w,NJ', b ) ); } if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); + return new TypeError( format( '0p97C,NR', c ) ); } if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); + return new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) ); } return null; } diff --git a/package.json b/package.json index 53a0d43..040ca42 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.1.1", "@stdlib/math-base-special-sqrt": "^0.1.1", "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-constant-function": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", From 13272dcd2a78585feea7630c0a82903c3b2149ee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 13:15:25 +0000 Subject: [PATCH 51/83] Remove files --- index.d.ts | 243 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6425 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 29ef36b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; // tslint-disable-line max-line-length - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4694f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function u(e,t,n){return!h(e)||j(e)?new TypeError(a("0p96v,NI",e)):!h(t)||j(t)?new TypeError(a("0p96w,NJ",t)):!h(n)||j(n)?new TypeError(a("0p97C,NR",n)):e<=n&&n<=t?null:new RangeError(a("0p99C,HP","a <= c <= b",e,t,n))}function g(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(h=arguments[3]))throw new TypeError(a("0p92V,FD",h));if(i(h,"prng")){if(!r(h.prng))throw new TypeError(a("0p96u,JI","prng",h.prng));j=h.prng}else j=m(h)}else j=m()}return e(f=void 0===v?P:R,"NAME","triangular"),h&&h.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",j)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",J),e(f,"PRNG",j),j=j.normalized),f;function w(){return j.seed}function x(){return j.seedLength}function N(){return j.stateLength}function E(){return j.byteLength}function L(){return j.state}function T(e){j.state=e}function J(){var e={type:"PRNG"};return e.name=f.NAME,e.state=p(j.state),e.params=void 0===v?[]:[v,b,y],e}function R(){return g(j,v,b,y)}function P(e,t,n){return l(e)||l(t)||l(n)||!(e<=n&&n<=t)?NaN:g(j,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b79ac1..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v,NI', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w,NJ', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C,NR', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;u+CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,WAAYN,KAErCG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,WAAYL,KAErCE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,WAAYJ,IAEpCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,WAAY,cAAeN,EAAGC,EAAGC,GAGlE,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4531eda..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 924f17420bf4c096b7defd862fbfb511782f0e15 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 13:18:40 +0000 Subject: [PATCH 52/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ---- test/test.js | 124 - 50 files changed, 6206 insertions(+), 5871 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 55cc7ba..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T06:15:21.938Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 6fb7d10..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -452,7 +451,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -514,7 +513,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index fa5bf11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8210b4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 592f4a5..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9bce72d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 81e290c..940d9f0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4694f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function u(e,t,n){return!h(e)||j(e)?new TypeError(a("0p96v,NI",e)):!h(t)||j(t)?new TypeError(a("0p96w,NJ",t)):!h(n)||j(n)?new TypeError(a("0p97C,NR",n)):e<=n&&n<=t?null:new RangeError(a("0p99C,HP","a <= c <= b",e,t,n))}function g(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(h=arguments[3]))throw new TypeError(a("0p92V,FD",h));if(i(h,"prng")){if(!r(h.prng))throw new TypeError(a("0p96u,JI","prng",h.prng));j=h.prng}else j=m(h)}else j=m()}return e(f=void 0===v?P:R,"NAME","triangular"),h&&h.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",j)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",J),e(f,"PRNG",j),j=j.normalized),f;function w(){return j.seed}function x(){return j.seedLength}function N(){return j.stateLength}function E(){return j.byteLength}function L(){return j.state}function T(e){j.state=e}function J(){var e={type:"PRNG"};return e.name=f.NAME,e.state=p(j.state),e.params=void 0===v?[]:[v,b,y],e}function R(){return g(j,v,b,y)}function P(e,t,n){return l(e)||l(t)||l(n)||!(e<=n&&n<=t)?NaN:g(j,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7b79ac1 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v,NI', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w,NJ', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C,NR', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;u+CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,WAAYN,KAErCG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,WAAYL,KAErCE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,WAAYJ,IAEpCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,WAAY,cAAeN,EAAGC,EAAGC,GAGlE,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index c49a816..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V,FD', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u,JI', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2ddd109..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v,NI', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w,NJ', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C,NR', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 040ca42..0972826 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-nan": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-sqrt": "^0.1.1", - "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-constant-function": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/assert-is-uint32array": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/process-env": "^0.1.1", - "@stdlib/random-base-minstd": "^0.1.0", - "@stdlib/random-base-minstd-shuffle": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/stats-kstest": "^0.1.0", - "@stdlib/time-now": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e0c20cd --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From de4b760567b5a44db69c7e01b1ad2160a9bc4b30 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:52:27 +0000 Subject: [PATCH 53/83] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a8f4949..d84ac4f 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.1.1", "@stdlib/math-base-special-sqrt": "^0.1.1", "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-constant-function": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", From c24e28c71cc3a6653f63f812ead6b211d49b0c09 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:28:11 +0000 Subject: [PATCH 54/83] Remove files --- index.d.ts | 243 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6425 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 940d9f0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4694f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function u(e,t,n){return!h(e)||j(e)?new TypeError(a("0p96v,NI",e)):!h(t)||j(t)?new TypeError(a("0p96w,NJ",t)):!h(n)||j(n)?new TypeError(a("0p97C,NR",n)):e<=n&&n<=t?null:new RangeError(a("0p99C,HP","a <= c <= b",e,t,n))}function g(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(h=arguments[3]))throw new TypeError(a("0p92V,FD",h));if(i(h,"prng")){if(!r(h.prng))throw new TypeError(a("0p96u,JI","prng",h.prng));j=h.prng}else j=m(h)}else j=m()}return e(f=void 0===v?P:R,"NAME","triangular"),h&&h.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),d),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",j)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",J),e(f,"PRNG",j),j=j.normalized),f;function w(){return j.seed}function x(){return j.seedLength}function N(){return j.stateLength}function E(){return j.byteLength}function L(){return j.state}function T(e){j.state=e}function J(){var e={type:"PRNG"};return e.name=f.NAME,e.state=p(j.state),e.params=void 0===v?[]:[v,b,y],e}function R(){return g(j,v,b,y)}function P(e,t,n){return l(e)||l(t)||l(n)||!(e<=n&&n<=t)?NaN:g(j,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b79ac1..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v,NI', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w,NJ', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C,NR', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C,HP', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V,FD', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u,JI', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;u+CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,WAAYN,KAErCG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,WAAYL,KAErCE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,WAAYJ,IAEpCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,WAAY,cAAeN,EAAGC,EAAGC,GAGlE,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,WAAYQ,IAE1C,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,WAAY,OAAQQ,EAAKC,OAEvDN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e0c20cd..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b1349ef777e23f91016b6389ba394695c84b9341 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:28:53 +0000 Subject: [PATCH 55/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ---- test/test.js | 124 - 51 files changed, 6206 insertions(+), 5877 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index cf82755..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:45:41.443Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ae60ebc..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -452,7 +451,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -514,7 +513,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9bce72d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 81e290c..940d9f0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..321cbbe --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function h(e,t,n){return!p(e)||g(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||g(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||g(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.","prng",p.prng));g=p.prng}else g=m(p)}else g=m()}return e(f=void 0===v?P:V,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),a),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",g)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",O),e(f,"PRNG",g),g=g.normalized),f;function w(){return g.seed}function x(){return g.seedLength}function N(){return g.stateLength}function E(){return g.byteLength}function L(){return g.state}function T(e){g.state=e}function O(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(g.state),e.params=void 0===v?[]:[v,b,y],e}function V(){return j(g,v,b,y)}function P(e,t,n){return d(e)||d(t)||d(n)||!(e<=n&&n<=t)?NaN:j(g,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..675a21c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/string-format';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;89CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2346fdb..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 99526d7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index d84ac4f..0972826 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-nan": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-sqrt": "^0.1.1", - "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-constant-function": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/assert-is-uint32array": "^0.1.1", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/process-env": "^0.1.1", - "@stdlib/random-base-minstd": "^0.1.0", - "@stdlib/random-base-minstd-shuffle": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/stats-kstest": "^0.1.0", - "@stdlib/time-now": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..17cc283 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From d9ba87cba5ad022b9684147b9dedd736448466bc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Jan 2024 10:15:43 +0000 Subject: [PATCH 56/83] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a8f4949..d84ac4f 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.1.1", "@stdlib/math-base-special-sqrt": "^0.1.1", "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-constant-function": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", From 457acfc82f0a8f521b650fde867797160b041fd0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Jan 2024 10:16:35 +0000 Subject: [PATCH 57/83] Remove files --- index.d.ts | 243 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6425 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 940d9f0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface BinaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): BinaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 321cbbe..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function h(e,t,n){return!p(e)||g(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||g(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||g(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.","prng",p.prng));g=p.prng}else g=m(p)}else g=m()}return e(f=void 0===v?P:V,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),a),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",g)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",O),e(f,"PRNG",g),g=g.normalized),f;function w(){return g.seed}function x(){return g.seedLength}function N(){return g.stateLength}function E(){return g.byteLength}function L(){return g.state}function T(e){g.state=e}function O(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(g.state),e.params=void 0===v?[]:[v,b,y],e}function V(){return j(g,v,b,y)}function P(e,t,n){return d(e)||d(t)||d(n)||!(e<=n&&n<=t)?NaN:j(g,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 675a21c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/string-format';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;89CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 17cc283..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 456d4d503b0b2dd37274477ccb56455299759228 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Jan 2024 10:17:12 +0000 Subject: [PATCH 58/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ---- test/test.js | 124 - 50 files changed, 6206 insertions(+), 5876 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ae60ebc..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -452,7 +451,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -514,7 +513,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9bce72d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dc80cb6..fc6107f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..321cbbe --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function h(e,t,n){return!p(e)||g(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||g(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||g(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.","prng",p.prng));g=p.prng}else g=m(p)}else g=m()}return e(f=void 0===v?P:V,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),a),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",g)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",O),e(f,"PRNG",g),g=g.normalized),f;function w(){return g.seed}function x(){return g.seedLength}function N(){return g.stateLength}function E(){return g.byteLength}function L(){return g.state}function T(e){g.state=e}function O(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(g.state),e.params=void 0===v?[]:[v,b,y],e}function V(){return j(g,v,b,y)}function P(e,t,n){return d(e)||d(t)||d(n)||!(e<=n&&n<=t)?NaN:j(g,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..675a21c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/string-format';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;89CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2346fdb..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 99526d7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index d84ac4f..0972826 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-nan": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-sqrt": "^0.1.1", - "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-constant-function": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/assert-is-uint32array": "^0.1.1", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/process-env": "^0.1.1", - "@stdlib/random-base-minstd": "^0.1.0", - "@stdlib/random-base-minstd-shuffle": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/stats-kstest": "^0.1.0", - "@stdlib/time-now": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9786402 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 4ef4b5913c2dfcf94a1e5d3fd5216bf35927ca73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 15 Jan 2024 07:15:27 +0000 Subject: [PATCH 59/83] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a8f4949..d84ac4f 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.1.1", "@stdlib/math-base-special-sqrt": "^0.1.1", "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-constant-function": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", From 4fc65a3d6a0b9994c31d4817e5de7af253f76771 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 15 Jan 2024 07:18:07 +0000 Subject: [PATCH 60/83] Remove files --- index.d.ts | 243 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6425 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index fc6107f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface TernaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): TernaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 321cbbe..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function h(e,t,n){return!p(e)||g(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||g(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||g(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.","prng",p.prng));g=p.prng}else g=m(p)}else g=m()}return e(f=void 0===v?P:V,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),a),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",g)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",O),e(f,"PRNG",g),g=g.normalized),f;function w(){return g.seed}function x(){return g.seedLength}function N(){return g.stateLength}function E(){return g.byteLength}function L(){return g.state}function T(e){g.state=e}function O(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(g.state),e.params=void 0===v?[]:[v,b,y],e}function V(){return j(g,v,b,y)}function P(e,t,n){return d(e)||d(t)||d(n)||!(e<=n&&n<=t)?NaN:j(g,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 675a21c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/string-format';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;89CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9786402..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9103eaf96366a114bc765d4ac56c834a273102b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 15 Jan 2024 07:18:44 +0000 Subject: [PATCH 61/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ---- test/test.js | 124 - 50 files changed, 6209 insertions(+), 5879 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ae60ebc..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +459,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -522,15 +521,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm -[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular +[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular/tree/esm -[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular +[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9bce72d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dc80cb6..fc6107f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..321cbbe --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function h(e,t,n){return!p(e)||g(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||g(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||g(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.","prng",p.prng));g=p.prng}else g=m(p)}else g=m()}return e(f=void 0===v?P:V,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),a),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",g)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",O),e(f,"PRNG",g),g=g.normalized),f;function w(){return g.seed}function x(){return g.seedLength}function N(){return g.stateLength}function E(){return g.byteLength}function L(){return g.state}function T(e){g.state=e}function O(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(g.state),e.params=void 0===v?[]:[v,b,y],e}function V(){return j(g,v,b,y)}function P(e,t,n){return d(e)||d(t)||d(n)||!(e<=n&&n<=t)?NaN:j(g,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..675a21c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/string-format';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;89CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2346fdb..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 99526d7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index d84ac4f..0972826 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-nan": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-sqrt": "^0.1.1", - "@stdlib/random-base-mt19937": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-constant-function": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/assert-is-uint32array": "^0.1.1", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/process-env": "^0.1.1", - "@stdlib/random-base-minstd": "^0.1.0", - "@stdlib/random-base-minstd-shuffle": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/stats-kstest": "^0.1.0", - "@stdlib/time-now": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..18bb9f9 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From d5e088bb82aa72033bd46e7f0d491960dfb856f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 01:34:20 +0000 Subject: [PATCH 62/83] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8b52724..af60052 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.2.0", "@stdlib/math-base-special-sqrt": "^0.2.0", "@stdlib/random-base-mt19937": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-constant-function": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", From e213164a52bcdf24f163da5d7f7f4e963863cc25 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 05:00:25 +0000 Subject: [PATCH 63/83] Remove files --- index.d.ts | 243 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6425 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index fc6107f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface TernaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): TernaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 321cbbe..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.1.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.1.1-esm/index.mjs";function h(e,t,n){return!p(e)||g(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||g(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||g(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.","prng",p.prng));g=p.prng}else g=m(p)}else g=m()}return e(f=void 0===v?P:V,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),a),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",g)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",O),e(f,"PRNG",g),g=g.normalized),f;function w(){return g.seed}function x(){return g.seedLength}function N(){return g.stateLength}function E(){return g.byteLength}function L(){return g.state}function T(e){g.state=e}function O(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(g.state),e.params=void 0===v?[]:[v,b,y],e}function V(){return j(g,v,b,y)}function P(e,t,n){return d(e)||d(t)||d(n)||!(e<=n&&n<=t)?NaN:j(g,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 675a21c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/string-format';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;89CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 18bb9f9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7e3707ab6dd3bd87cba5d857894630bb4db9f6f4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 05:02:38 +0000 Subject: [PATCH 64/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 - lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ---- test/test.js | 124 - 50 files changed, 6209 insertions(+), 5888 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index f7038cf..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -462,7 +459,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -527,15 +524,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm -[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular +[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular/tree/esm -[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular +[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c284b1f..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-base-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-base-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-base-triangular/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dc80cb6..fc6107f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c5e7be7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.0-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.0-esm/index.mjs";function h(e,t,n){return!p(e)||g(e)?new TypeError(u("invalid argument. First argument must be a number and not NaN. Value: `%s`.",e)):!p(t)||g(t)?new TypeError(u("invalid argument. Second argument must be a number and not NaN. Value: `%s`.",t)):!p(n)||g(n)?new TypeError(u("invalid argument. Third argument must be a number and not NaN. Value: `%s`.",n)):e<=n&&n<=t?null:new RangeError(u("invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.","a <= c <= b",e,t,n))}function j(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(p=arguments[3]))throw new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",p));if(i(p,"prng")){if(!r(p.prng))throw new TypeError(u("invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.","prng",p.prng));g=p.prng}else g=m(p)}else g=m()}return e(f=void 0===v?P:V,"NAME","triangular"),p&&p.prng?(e(f,"seed",null),e(f,"seedLength",null),n(f,"state",o(null),a),e(f,"stateLength",null),e(f,"byteLength",null),e(f,"toJSON",o(null)),e(f,"PRNG",g)):(t(f,"seed",w),t(f,"seedLength",x),n(f,"state",L,T),t(f,"stateLength",N),t(f,"byteLength",E),e(f,"toJSON",O),e(f,"PRNG",g),g=g.normalized),f;function w(){return g.seed}function x(){return g.seedLength}function N(){return g.stateLength}function E(){return g.byteLength}function L(){return g.state}function T(e){g.state=e}function O(){var e={type:"PRNG"};return e.name=f.NAME,e.state=l(g.state),e.params=void 0===v?[]:[v,b,y],e}function V(){return j(g,v,b,y)}function P(e,t,n){return d(e)||d(t)||d(n)||!(e<=n&&n<=t)?NaN:j(g,e,t,n)}}var v=c();e(v,"factory",c);export{v as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..675a21c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/triangular.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/string-format';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","a","b","c","isNumber","isnan","TypeError","format","RangeError","triangular","rand","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","hasOwnProp","isFunction","setReadOnly","triangular2","triangular1","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","getSeed","getSeedLength","getState","setState","getStateLength","getStateSize","toJSON","normalized","seed","seedLength","stateLength","byteLength","state","s","out","name","NAME","typedarray2json","params","triangular0","NaN","main"],"mappings":";;89CA4CA,SAASA,EAAUC,EAAGC,EAAGC,GACxB,OAAMC,EAAUH,IAAOI,EAAOJ,GACtB,IAAIK,UAAWC,EAAQ,8EAA+EN,KAExGG,EAAUF,IAAOG,EAAOH,GACtB,IAAII,UAAWC,EAAQ,+EAAgFL,KAEzGE,EAAUD,IAAOE,EAAOF,GACtB,IAAIG,UAAWC,EAAQ,8EAA+EJ,IAEvGF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAIM,WAAYD,EAAQ,qGAAsG,cAAeN,EAAGC,EAAGC,GAG5J,CCrBA,SAASM,EAAYC,EAAMT,EAAGC,EAAGC,GAChC,IAAIQ,EAEAC,EAGJ,OAFAD,GAAMR,EAAIF,IAAMC,EAAID,IACpBW,EAAIF,KACKC,EAEDV,EAAIY,GADNX,EAAID,IAAME,EAAIF,GACEW,GAGfV,EAAIW,GADNX,EAAID,IAAMC,EAAIC,IACG,EAAMS,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAL,EACAM,EACAC,EACAhB,EACAC,EACAC,EAEJ,GAA0B,IAArBe,UAAUC,OACdT,EAAOU,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IACf,MACGN,EAAOU,EAAOL,EAEjB,KAAQ,CAKN,GADAE,EAAMjB,EAHNC,EAAIiB,UAAW,GACfhB,EAAIgB,UAAW,GACff,EAAIe,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAIZ,UAAWC,EAAQ,qEAAsEQ,IAEpG,GAAKO,EAAYP,EAAM,QAAW,CACjC,IAAMQ,EAAYR,EAAKC,MACtB,MAAM,IAAIV,UAAWC,EAAQ,8FAA+F,OAAQQ,EAAKC,OAE1IN,EAAOK,EAAKC,IAChB,MACIN,EAAOU,EAAOL,EAElB,MACGL,EAAOU,GAER,CA2BD,OArBAI,EAJCR,OADU,IAANf,EACGwB,EAEAC,EAEW,OAAQ,cAGtBX,GAAQA,EAAKC,MACjBQ,EAAaR,EAAM,OAAQ,MAC3BQ,EAAaR,EAAM,aAAc,MACjCW,EAAsBX,EAAM,QAASY,EAAkB,MAAQC,GAC/DL,EAAaR,EAAM,cAAe,MAClCQ,EAAaR,EAAM,aAAc,MACjCQ,EAAaR,EAAM,SAAUY,EAAkB,OAC/CJ,EAAaR,EAAM,OAAQN,KAE3BoB,EAAqBd,EAAM,OAAQe,GACnCD,EAAqBd,EAAM,aAAcgB,GACzCL,EAAsBX,EAAM,QAASiB,EAAUC,GAC/CJ,EAAqBd,EAAM,cAAemB,GAC1CL,EAAqBd,EAAM,aAAcoB,GACzCZ,EAAaR,EAAM,SAAUqB,GAC7Bb,EAAaR,EAAM,OAAQN,GAC3BA,EAAOA,EAAK4B,YAENtB,EAQP,SAASe,IACR,OAAOrB,EAAK6B,IACZ,CAQD,SAASP,IACR,OAAOtB,EAAK8B,UACZ,CAQD,SAASL,IACR,OAAOzB,EAAK+B,WACZ,CAQD,SAASL,IACR,OAAO1B,EAAKgC,UACZ,CAQD,SAAST,IACR,OAAOvB,EAAKiC,KACZ,CASD,SAAST,EAAUU,GAClBlC,EAAKiC,MAAQC,CACb,CAYD,SAASP,IACR,IAAIQ,EAAM,CACVA,KAAW,QAQX,OAPAA,EAAIC,KAAO9B,EAAK+B,KAChBF,EAAIF,MAAQK,EAAiBtC,EAAKiC,OAEjCE,EAAII,YADM,IAANhD,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEf0C,CACP,CAYD,SAASnB,IACR,OAAOwB,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CAuBD,SAASsB,EAAaxB,EAAGC,EAAGC,GAC3B,OACCE,EAAOJ,IACPI,EAAOH,IACPG,EAAOF,MACLF,GAAKE,GAAKA,GAAKD,GAEViD,IAEDD,EAAaxC,EAAMT,EAAGC,EAAGC,EAChC,CACF,CC/OG,IAACM,EAAaK,ICkBjBU,EAAA4B,EAAA,UAAAtC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2346fdb..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 99526d7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index af60052..06e1611 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-function": "^0.2.0", - "@stdlib/assert-is-nan": "^0.2.0", - "@stdlib/assert-is-number": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/math-base-assert-is-nan": "^0.2.0", - "@stdlib/math-base-special-sqrt": "^0.2.0", - "@stdlib/random-base-mt19937": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-constant-function": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.2.0", - "@stdlib/utils-noop": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.2.0", - "@stdlib/assert-is-uint32array": "^0.2.0", - "@stdlib/constants-uint32-max": "^0.2.0", - "@stdlib/process-env": "^0.2.0", - "@stdlib/random-base-minstd": "^0.1.0", - "@stdlib/random-base-minstd-shuffle": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/stats-kstest": "^0.2.0", - "@stdlib/time-now": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0b3ed52 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 3bfc81721196cabc92325d6aa754e5dda2708af1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:40:24 +0000 Subject: [PATCH 65/83] Update README.md for ESM bundle v0.2.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3d79fe1..77f3ac1 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@esm/index.mjs'; +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.0-esm/index.mjs'; ``` #### triangular( a, b, c ) @@ -397,7 +397,7 @@ var o = rand.toJSON(); - - - - From 1769f2c109f0fbc497d5af33124876ab7fa64391 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:39:47 +0000 Subject: [PATCH 69/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 51 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 -- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ----- test/test.js | 124 - 50 files changed, 4874 insertions(+), 5883 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 02b1e86..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -462,7 +459,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -527,15 +524,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm -[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular +[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular/tree/esm -[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular +[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c284b1f..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-base-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-base-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-base-triangular/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dc80cb6..fc6107f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..41d30e0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.1-esm/index.mjs";function u(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(j=arguments[3]))throw new TypeError(a("0p92V",j));if(i(j,"prng")){if(!r(j.prng))throw new TypeError(a("0p96u","prng",j.prng));g=j.prng}else g=m(j)}else g=m()}return e(c=void 0===b?function(e,t,n){if(l(e)||l(t)||l(n)||!(e<=n&&n<=t))return NaN;return u(g,e,t,n)}:function(){return u(g,b,y,w)},"NAME","triangular"),j&&j.prng?(e(c,"seed",null),e(c,"seedLength",null),n(c,"state",o(null),d),e(c,"stateLength",null),e(c,"byteLength",null),e(c,"toJSON",o(null)),e(c,"PRNG",g)):(t(c,"seed",(function(){return g.seed})),t(c,"seedLength",(function(){return g.seedLength})),n(c,"state",(function(){return g.state}),(function(e){g.state=e})),t(c,"stateLength",(function(){return g.stateLength})),t(c,"byteLength",(function(){return g.byteLength})),e(c,"toJSON",(function(){var e={type:"PRNG"};e.name=c.NAME,e.state=p(g.state),e.params=void 0===b?[]:[b,y,w];return e})),e(c,"PRNG",g),g=g.normalized),c}var c=g();e(c,"factory",g);export{c as default,g as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6293ecd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/triangular.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["triangular","rand","a","b","c","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","TypeError","format","hasOwnProp","isFunction","isNumber","isnan","RangeError","validate","setReadOnly","NaN","triangular0","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","seed","seedLength","state","s","stateLength","byteLength","out","name","NAME","typedarray2json","params","normalized","main"],"mappings":";;u+CAqCA,SAASA,EAAYC,EAAMC,EAAGC,EAAGC,GAChC,IAAIC,EAEAC,EAGJ,OAFAD,GAAMD,EAAIF,IAAMC,EAAID,IACpBI,EAAIL,KACKI,EAEDH,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACEI,GAGfH,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAME,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAR,EACAS,EACAC,EACAT,EACAC,EACAC,EAEJ,GAA0B,IAArBQ,UAAUC,OACdZ,EAAOa,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IACf,MACGT,EAAOa,EAAOL,EAEjB,KAAQ,CAKN,GADAE,ECzDF,SAAmBT,EAAGC,EAAGC,GACxB,OAAMgB,EAAUlB,IAAOmB,EAAOnB,GACtB,IAAIc,UAAWC,EAAQ,QAASf,KAElCkB,EAAUjB,IAAOkB,EAAOlB,GACtB,IAAIa,UAAWC,EAAQ,QAASd,KAElCiB,EAAUhB,IAAOiB,EAAOjB,GACtB,IAAIY,UAAWC,EAAQ,QAASb,IAEjCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAImB,WAAYL,EAAQ,QAAS,cAAef,EAAGC,EAAGC,GAG/D,CD2CQmB,CAHNrB,EAAIU,UAAW,GACfT,EAAIS,UAAW,GACfR,EAAIQ,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IAChB,MACIT,EAAOa,EAAOL,EAElB,MACGR,EAAOa,GAER,CA2BD,OArBAU,EAJCd,OADU,IAANR,EAmJL,SAAsBA,EAAGC,EAAGC,GAC3B,GACCiB,EAAOnB,IACPmB,EAAOlB,IACPkB,EAAOjB,MACLF,GAAKE,GAAKA,GAAKD,GAEjB,OAAOsB,IAER,OAAOC,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAnCD,WACC,OAAOsB,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAvHkB,OAAQ,cAGtBK,GAAQA,EAAKC,MACjBc,EAAad,EAAM,OAAQ,MAC3Bc,EAAad,EAAM,aAAc,MACjCiB,EAAsBjB,EAAM,QAASkB,EAAkB,MAAQC,GAC/DL,EAAad,EAAM,cAAe,MAClCc,EAAad,EAAM,aAAc,MACjCc,EAAad,EAAM,SAAUkB,EAAkB,OAC/CJ,EAAad,EAAM,OAAQT,KAE3B6B,EAAqBpB,EAAM,QAiB5B,WACC,OAAOT,EAAK8B,IACZ,IAlBAD,EAAqBpB,EAAM,cA0B5B,WACC,OAAOT,EAAK+B,UACZ,IA3BAL,EAAsBjB,EAAM,SAuD7B,WACC,OAAOT,EAAKgC,KACZ,IASD,SAAmBC,GAClBjC,EAAKgC,MAAQC,CACb,IAnEAJ,EAAqBpB,EAAM,eAkC5B,WACC,OAAOT,EAAKkC,WACZ,IAnCAL,EAAqBpB,EAAM,cA2C5B,WACC,OAAOT,EAAKmC,UACZ,IA5CAZ,EAAad,EAAM,UA6EpB,WACC,IAAI2B,EAAM,CACVA,KAAW,QACXA,EAAIC,KAAO5B,EAAK6B,KAChBF,EAAIJ,MAAQO,EAAiBvC,EAAKgC,OAEjCI,EAAII,YADM,IAANvC,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEtB,OAAOiC,CACP,IAvFAb,EAAad,EAAM,OAAQT,GAC3BA,EAAOA,EAAKyC,YAENhC,CAoIR,CE/OG,IAACV,EAAaQ,ICkBjBgB,EAAAmB,EAAA,UAAAnC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1a199aa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2836c0b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f61d186..c2ce925 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-nan": "^0.2.1", - "@stdlib/assert-is-number": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-special-sqrt": "^0.2.1", - "@stdlib/random-base-mt19937": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-constant-function": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/assert-is-uint32array": "^0.2.1", - "@stdlib/constants-uint32-max": "^0.2.1", - "@stdlib/process-env": "^0.2.1", - "@stdlib/random-base-minstd": "^0.2.0", - "@stdlib/random-base-minstd-shuffle": "^0.2.0", - "@stdlib/random-base-randu": "^0.2.0", - "@stdlib/stats-kstest": "^0.2.1", - "@stdlib/time-now": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..53d4c2e --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From ba34cc375501e1207e50204b86c025efefcdd9d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:16:57 +0000 Subject: [PATCH 70/83] Update README.md for ESM bundle v0.2.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0752b31..106d721 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@esm/index.mjs'; +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.1-esm/index.mjs'; ``` #### triangular( a, b, c ) @@ -397,7 +397,7 @@ var o = rand.toJSON(); - - - - From f44503edd32bd71174ac8cc1f6839b1f635d6f64 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 14:20:27 +0000 Subject: [PATCH 74/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 51 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 -- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ----- test/test.js | 124 - 51 files changed, 4874 insertions(+), 5885 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7722fe7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T06:13:21.003Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 02b1e86..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -462,7 +459,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -527,15 +524,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm -[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular +[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular/tree/esm -[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular +[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c284b1f..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-base-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-base-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-base-triangular/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dc80cb6..fc6107f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3bed0da --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.1-esm/index.mjs";function u(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(j=arguments[3]))throw new TypeError(a("0p92V",j));if(i(j,"prng")){if(!r(j.prng))throw new TypeError(a("0p96u","prng",j.prng));g=j.prng}else g=m(j)}else g=m()}return e(c=void 0===b?function(e,t,n){if(l(e)||l(t)||l(n)||!(e<=n&&n<=t))return NaN;return u(g,e,t,n)}:function(){return u(g,b,y,w)},"NAME","triangular"),j&&j.prng?(e(c,"seed",null),e(c,"seedLength",null),n(c,"state",o(null),d),e(c,"stateLength",null),e(c,"byteLength",null),e(c,"toJSON",o(null)),e(c,"PRNG",g)):(t(c,"seed",(function(){return g.seed})),t(c,"seedLength",(function(){return g.seedLength})),n(c,"state",(function(){return g.state}),(function(e){g.state=e})),t(c,"stateLength",(function(){return g.stateLength})),t(c,"byteLength",(function(){return g.byteLength})),e(c,"toJSON",(function(){var e={type:"PRNG"};e.name=c.NAME,e.state=p(g.state),e.params=void 0===b?[]:[b,y,w];return e})),e(c,"PRNG",g),g=g.normalized),c}var c=g();e(c,"factory",g);export{c as default,g as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6293ecd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/triangular.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["triangular","rand","a","b","c","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","TypeError","format","hasOwnProp","isFunction","isNumber","isnan","RangeError","validate","setReadOnly","NaN","triangular0","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","seed","seedLength","state","s","stateLength","byteLength","out","name","NAME","typedarray2json","params","normalized","main"],"mappings":";;u+CAqCA,SAASA,EAAYC,EAAMC,EAAGC,EAAGC,GAChC,IAAIC,EAEAC,EAGJ,OAFAD,GAAMD,EAAIF,IAAMC,EAAID,IACpBI,EAAIL,KACKI,EAEDH,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACEI,GAGfH,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAME,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAR,EACAS,EACAC,EACAT,EACAC,EACAC,EAEJ,GAA0B,IAArBQ,UAAUC,OACdZ,EAAOa,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IACf,MACGT,EAAOa,EAAOL,EAEjB,KAAQ,CAKN,GADAE,ECzDF,SAAmBT,EAAGC,EAAGC,GACxB,OAAMgB,EAAUlB,IAAOmB,EAAOnB,GACtB,IAAIc,UAAWC,EAAQ,QAASf,KAElCkB,EAAUjB,IAAOkB,EAAOlB,GACtB,IAAIa,UAAWC,EAAQ,QAASd,KAElCiB,EAAUhB,IAAOiB,EAAOjB,GACtB,IAAIY,UAAWC,EAAQ,QAASb,IAEjCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAImB,WAAYL,EAAQ,QAAS,cAAef,EAAGC,EAAGC,GAG/D,CD2CQmB,CAHNrB,EAAIU,UAAW,GACfT,EAAIS,UAAW,GACfR,EAAIQ,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IAChB,MACIT,EAAOa,EAAOL,EAElB,MACGR,EAAOa,GAER,CA2BD,OArBAU,EAJCd,OADU,IAANR,EAmJL,SAAsBA,EAAGC,EAAGC,GAC3B,GACCiB,EAAOnB,IACPmB,EAAOlB,IACPkB,EAAOjB,MACLF,GAAKE,GAAKA,GAAKD,GAEjB,OAAOsB,IAER,OAAOC,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAnCD,WACC,OAAOsB,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAvHkB,OAAQ,cAGtBK,GAAQA,EAAKC,MACjBc,EAAad,EAAM,OAAQ,MAC3Bc,EAAad,EAAM,aAAc,MACjCiB,EAAsBjB,EAAM,QAASkB,EAAkB,MAAQC,GAC/DL,EAAad,EAAM,cAAe,MAClCc,EAAad,EAAM,aAAc,MACjCc,EAAad,EAAM,SAAUkB,EAAkB,OAC/CJ,EAAad,EAAM,OAAQT,KAE3B6B,EAAqBpB,EAAM,QAiB5B,WACC,OAAOT,EAAK8B,IACZ,IAlBAD,EAAqBpB,EAAM,cA0B5B,WACC,OAAOT,EAAK+B,UACZ,IA3BAL,EAAsBjB,EAAM,SAuD7B,WACC,OAAOT,EAAKgC,KACZ,IASD,SAAmBC,GAClBjC,EAAKgC,MAAQC,CACb,IAnEAJ,EAAqBpB,EAAM,eAkC5B,WACC,OAAOT,EAAKkC,WACZ,IAnCAL,EAAqBpB,EAAM,cA2C5B,WACC,OAAOT,EAAKmC,UACZ,IA5CAZ,EAAad,EAAM,UA6EpB,WACC,IAAI2B,EAAM,CACVA,KAAW,QACXA,EAAIC,KAAO5B,EAAK6B,KAChBF,EAAIJ,MAAQO,EAAiBvC,EAAKgC,OAEjCI,EAAII,YADM,IAANvC,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEtB,OAAOiC,CACP,IAvFAb,EAAad,EAAM,OAAQT,GAC3BA,EAAOA,EAAKyC,YAENhC,CAoIR,CE/OG,IAACV,EAAaQ,ICkBjBgB,EAAAmB,EAAA,UAAAnC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1a199aa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2836c0b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee5e8fb..c2ce925 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-nan": "^0.2.1", - "@stdlib/assert-is-number": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-special-sqrt": "^0.2.1", - "@stdlib/random-base-mt19937": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-constant-function": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/assert-is-uint32array": "^0.2.1", - "@stdlib/constants-uint32-max": "^0.2.1", - "@stdlib/process-env": "^0.2.1", - "@stdlib/random-base-minstd": "^0.2.1", - "@stdlib/random-base-minstd-shuffle": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/stats-kstest": "^0.2.1", - "@stdlib/time-now": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..62ee6dd --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 07c4e6b59ca70bd3b3ee5a09b5eb6184b5c5964a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:52:34 +0000 Subject: [PATCH 75/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..1a199aa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..2836c0b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); @@ -44,16 +44,16 @@ var isnan = require( '@stdlib/assert-is-nan' ); */ function validate( a, b, c ) { if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); + return new TypeError( format( '0p96v', a ) ); } if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); + return new TypeError( format( '0p96w', b ) ); } if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); + return new TypeError( format( '0p97C', c ) ); } if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); + return new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) ); } return null; } diff --git a/package.json b/package.json index f18f3c3..ee5e8fb 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.2.1", "@stdlib/math-base-special-sqrt": "^0.2.1", "@stdlib/random-base-mt19937": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-constant-function": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", From 6af3736324620c3db8f52bd3a01a4ceff6e5456d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:25:46 +0000 Subject: [PATCH 76/83] Remove files --- index.d.ts | 243 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5090 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index fc6107f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface TernaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): TernaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3bed0da..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.1-esm/index.mjs";function u(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(j=arguments[3]))throw new TypeError(a("0p92V",j));if(i(j,"prng")){if(!r(j.prng))throw new TypeError(a("0p96u","prng",j.prng));g=j.prng}else g=m(j)}else g=m()}return e(c=void 0===b?function(e,t,n){if(l(e)||l(t)||l(n)||!(e<=n&&n<=t))return NaN;return u(g,e,t,n)}:function(){return u(g,b,y,w)},"NAME","triangular"),j&&j.prng?(e(c,"seed",null),e(c,"seedLength",null),n(c,"state",o(null),d),e(c,"stateLength",null),e(c,"byteLength",null),e(c,"toJSON",o(null)),e(c,"PRNG",g)):(t(c,"seed",(function(){return g.seed})),t(c,"seedLength",(function(){return g.seedLength})),n(c,"state",(function(){return g.state}),(function(e){g.state=e})),t(c,"stateLength",(function(){return g.stateLength})),t(c,"byteLength",(function(){return g.byteLength})),e(c,"toJSON",(function(){var e={type:"PRNG"};e.name=c.NAME,e.state=p(g.state),e.params=void 0===b?[]:[b,y,w];return e})),e(c,"PRNG",g),g=g.normalized),c}var c=g();e(c,"factory",g);export{c as default,g as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6293ecd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/triangular.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["triangular","rand","a","b","c","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","TypeError","format","hasOwnProp","isFunction","isNumber","isnan","RangeError","validate","setReadOnly","NaN","triangular0","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","seed","seedLength","state","s","stateLength","byteLength","out","name","NAME","typedarray2json","params","normalized","main"],"mappings":";;u+CAqCA,SAASA,EAAYC,EAAMC,EAAGC,EAAGC,GAChC,IAAIC,EAEAC,EAGJ,OAFAD,GAAMD,EAAIF,IAAMC,EAAID,IACpBI,EAAIL,KACKI,EAEDH,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACEI,GAGfH,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAME,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAR,EACAS,EACAC,EACAT,EACAC,EACAC,EAEJ,GAA0B,IAArBQ,UAAUC,OACdZ,EAAOa,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IACf,MACGT,EAAOa,EAAOL,EAEjB,KAAQ,CAKN,GADAE,ECzDF,SAAmBT,EAAGC,EAAGC,GACxB,OAAMgB,EAAUlB,IAAOmB,EAAOnB,GACtB,IAAIc,UAAWC,EAAQ,QAASf,KAElCkB,EAAUjB,IAAOkB,EAAOlB,GACtB,IAAIa,UAAWC,EAAQ,QAASd,KAElCiB,EAAUhB,IAAOiB,EAAOjB,GACtB,IAAIY,UAAWC,EAAQ,QAASb,IAEjCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAImB,WAAYL,EAAQ,QAAS,cAAef,EAAGC,EAAGC,GAG/D,CD2CQmB,CAHNrB,EAAIU,UAAW,GACfT,EAAIS,UAAW,GACfR,EAAIQ,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IAChB,MACIT,EAAOa,EAAOL,EAElB,MACGR,EAAOa,GAER,CA2BD,OArBAU,EAJCd,OADU,IAANR,EAmJL,SAAsBA,EAAGC,EAAGC,GAC3B,GACCiB,EAAOnB,IACPmB,EAAOlB,IACPkB,EAAOjB,MACLF,GAAKE,GAAKA,GAAKD,GAEjB,OAAOsB,IAER,OAAOC,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAnCD,WACC,OAAOsB,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAvHkB,OAAQ,cAGtBK,GAAQA,EAAKC,MACjBc,EAAad,EAAM,OAAQ,MAC3Bc,EAAad,EAAM,aAAc,MACjCiB,EAAsBjB,EAAM,QAASkB,EAAkB,MAAQC,GAC/DL,EAAad,EAAM,cAAe,MAClCc,EAAad,EAAM,aAAc,MACjCc,EAAad,EAAM,SAAUkB,EAAkB,OAC/CJ,EAAad,EAAM,OAAQT,KAE3B6B,EAAqBpB,EAAM,QAiB5B,WACC,OAAOT,EAAK8B,IACZ,IAlBAD,EAAqBpB,EAAM,cA0B5B,WACC,OAAOT,EAAK+B,UACZ,IA3BAL,EAAsBjB,EAAM,SAuD7B,WACC,OAAOT,EAAKgC,KACZ,IASD,SAAmBC,GAClBjC,EAAKgC,MAAQC,CACb,IAnEAJ,EAAqBpB,EAAM,eAkC5B,WACC,OAAOT,EAAKkC,WACZ,IAnCAL,EAAqBpB,EAAM,cA2C5B,WACC,OAAOT,EAAKmC,UACZ,IA5CAZ,EAAad,EAAM,UA6EpB,WACC,IAAI2B,EAAM,CACVA,KAAW,QACXA,EAAIC,KAAO5B,EAAK6B,KAChBF,EAAIJ,MAAQO,EAAiBvC,EAAKgC,OAEjCI,EAAII,YADM,IAANvC,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEtB,OAAOiC,CACP,IAvFAb,EAAad,EAAM,OAAQT,GAC3BA,EAAOA,EAAKyC,YAENhC,CAoIR,CE/OG,IAACV,EAAaQ,ICkBjBgB,EAAAmB,EAAA,UAAAnC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 62ee6dd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f9c33bdd7bd349e52a1890277977bff4297e3743 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:26:00 +0000 Subject: [PATCH 77/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 51 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 -- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ----- test/test.js | 124 - 51 files changed, 4874 insertions(+), 5888 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4e97123..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:29:00.689Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 02b1e86..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -462,7 +459,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -527,15 +524,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm -[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular +[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular/tree/esm -[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular +[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c284b1f..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-base-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-base-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-base-triangular/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dc80cb6..fc6107f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3bed0da --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.1-esm/index.mjs";function u(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(j=arguments[3]))throw new TypeError(a("0p92V",j));if(i(j,"prng")){if(!r(j.prng))throw new TypeError(a("0p96u","prng",j.prng));g=j.prng}else g=m(j)}else g=m()}return e(c=void 0===b?function(e,t,n){if(l(e)||l(t)||l(n)||!(e<=n&&n<=t))return NaN;return u(g,e,t,n)}:function(){return u(g,b,y,w)},"NAME","triangular"),j&&j.prng?(e(c,"seed",null),e(c,"seedLength",null),n(c,"state",o(null),d),e(c,"stateLength",null),e(c,"byteLength",null),e(c,"toJSON",o(null)),e(c,"PRNG",g)):(t(c,"seed",(function(){return g.seed})),t(c,"seedLength",(function(){return g.seedLength})),n(c,"state",(function(){return g.state}),(function(e){g.state=e})),t(c,"stateLength",(function(){return g.stateLength})),t(c,"byteLength",(function(){return g.byteLength})),e(c,"toJSON",(function(){var e={type:"PRNG"};e.name=c.NAME,e.state=p(g.state),e.params=void 0===b?[]:[b,y,w];return e})),e(c,"PRNG",g),g=g.normalized),c}var c=g();e(c,"factory",g);export{c as default,g as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6293ecd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/triangular.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["triangular","rand","a","b","c","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","TypeError","format","hasOwnProp","isFunction","isNumber","isnan","RangeError","validate","setReadOnly","NaN","triangular0","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","seed","seedLength","state","s","stateLength","byteLength","out","name","NAME","typedarray2json","params","normalized","main"],"mappings":";;u+CAqCA,SAASA,EAAYC,EAAMC,EAAGC,EAAGC,GAChC,IAAIC,EAEAC,EAGJ,OAFAD,GAAMD,EAAIF,IAAMC,EAAID,IACpBI,EAAIL,KACKI,EAEDH,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACEI,GAGfH,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAME,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAR,EACAS,EACAC,EACAT,EACAC,EACAC,EAEJ,GAA0B,IAArBQ,UAAUC,OACdZ,EAAOa,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IACf,MACGT,EAAOa,EAAOL,EAEjB,KAAQ,CAKN,GADAE,ECzDF,SAAmBT,EAAGC,EAAGC,GACxB,OAAMgB,EAAUlB,IAAOmB,EAAOnB,GACtB,IAAIc,UAAWC,EAAQ,QAASf,KAElCkB,EAAUjB,IAAOkB,EAAOlB,GACtB,IAAIa,UAAWC,EAAQ,QAASd,KAElCiB,EAAUhB,IAAOiB,EAAOjB,GACtB,IAAIY,UAAWC,EAAQ,QAASb,IAEjCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAImB,WAAYL,EAAQ,QAAS,cAAef,EAAGC,EAAGC,GAG/D,CD2CQmB,CAHNrB,EAAIU,UAAW,GACfT,EAAIS,UAAW,GACfR,EAAIQ,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IAChB,MACIT,EAAOa,EAAOL,EAElB,MACGR,EAAOa,GAER,CA2BD,OArBAU,EAJCd,OADU,IAANR,EAmJL,SAAsBA,EAAGC,EAAGC,GAC3B,GACCiB,EAAOnB,IACPmB,EAAOlB,IACPkB,EAAOjB,MACLF,GAAKE,GAAKA,GAAKD,GAEjB,OAAOsB,IAER,OAAOC,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAnCD,WACC,OAAOsB,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAvHkB,OAAQ,cAGtBK,GAAQA,EAAKC,MACjBc,EAAad,EAAM,OAAQ,MAC3Bc,EAAad,EAAM,aAAc,MACjCiB,EAAsBjB,EAAM,QAASkB,EAAkB,MAAQC,GAC/DL,EAAad,EAAM,cAAe,MAClCc,EAAad,EAAM,aAAc,MACjCc,EAAad,EAAM,SAAUkB,EAAkB,OAC/CJ,EAAad,EAAM,OAAQT,KAE3B6B,EAAqBpB,EAAM,QAiB5B,WACC,OAAOT,EAAK8B,IACZ,IAlBAD,EAAqBpB,EAAM,cA0B5B,WACC,OAAOT,EAAK+B,UACZ,IA3BAL,EAAsBjB,EAAM,SAuD7B,WACC,OAAOT,EAAKgC,KACZ,IASD,SAAmBC,GAClBjC,EAAKgC,MAAQC,CACb,IAnEAJ,EAAqBpB,EAAM,eAkC5B,WACC,OAAOT,EAAKkC,WACZ,IAnCAL,EAAqBpB,EAAM,cA2C5B,WACC,OAAOT,EAAKmC,UACZ,IA5CAZ,EAAad,EAAM,UA6EpB,WACC,IAAI2B,EAAM,CACVA,KAAW,QACXA,EAAIC,KAAO5B,EAAK6B,KAChBF,EAAIJ,MAAQO,EAAiBvC,EAAKgC,OAEjCI,EAAII,YADM,IAANvC,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEtB,OAAOiC,CACP,IAvFAb,EAAad,EAAM,OAAQT,GAC3BA,EAAOA,EAAKyC,YAENhC,CAoIR,CE/OG,IAACV,EAAaQ,ICkBjBgB,EAAAmB,EAAA,UAAAnC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1a199aa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2836c0b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee5e8fb..c2ce925 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-nan": "^0.2.1", - "@stdlib/assert-is-number": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-special-sqrt": "^0.2.1", - "@stdlib/random-base-mt19937": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-constant-function": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/assert-is-uint32array": "^0.2.1", - "@stdlib/constants-uint32-max": "^0.2.1", - "@stdlib/process-env": "^0.2.1", - "@stdlib/random-base-minstd": "^0.2.1", - "@stdlib/random-base-minstd-shuffle": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/stats-kstest": "^0.2.1", - "@stdlib/time-now": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..62ee6dd --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From bdc4c569fc4e24d164c75e8b9431d245da0ce24f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 04:05:19 +0000 Subject: [PATCH 78/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..1a199aa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..2836c0b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); @@ -44,16 +44,16 @@ var isnan = require( '@stdlib/assert-is-nan' ); */ function validate( a, b, c ) { if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); + return new TypeError( format( '0p96v', a ) ); } if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); + return new TypeError( format( '0p96w', b ) ); } if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); + return new TypeError( format( '0p97C', c ) ); } if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); + return new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) ); } return null; } diff --git a/package.json b/package.json index f18f3c3..ee5e8fb 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.2.1", "@stdlib/math-base-special-sqrt": "^0.2.1", "@stdlib/random-base-mt19937": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-constant-function": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", From bcc7a63dfaa8d947911ecb59d5052ad7f73d56d7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:38:10 +0000 Subject: [PATCH 79/83] Remove files --- index.d.ts | 243 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5090 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index fc6107f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface TernaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): TernaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3bed0da..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.1-esm/index.mjs";function u(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(j=arguments[3]))throw new TypeError(a("0p92V",j));if(i(j,"prng")){if(!r(j.prng))throw new TypeError(a("0p96u","prng",j.prng));g=j.prng}else g=m(j)}else g=m()}return e(c=void 0===b?function(e,t,n){if(l(e)||l(t)||l(n)||!(e<=n&&n<=t))return NaN;return u(g,e,t,n)}:function(){return u(g,b,y,w)},"NAME","triangular"),j&&j.prng?(e(c,"seed",null),e(c,"seedLength",null),n(c,"state",o(null),d),e(c,"stateLength",null),e(c,"byteLength",null),e(c,"toJSON",o(null)),e(c,"PRNG",g)):(t(c,"seed",(function(){return g.seed})),t(c,"seedLength",(function(){return g.seedLength})),n(c,"state",(function(){return g.state}),(function(e){g.state=e})),t(c,"stateLength",(function(){return g.stateLength})),t(c,"byteLength",(function(){return g.byteLength})),e(c,"toJSON",(function(){var e={type:"PRNG"};e.name=c.NAME,e.state=p(g.state),e.params=void 0===b?[]:[b,y,w];return e})),e(c,"PRNG",g),g=g.normalized),c}var c=g();e(c,"factory",g);export{c as default,g as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6293ecd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/triangular.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["triangular","rand","a","b","c","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","TypeError","format","hasOwnProp","isFunction","isNumber","isnan","RangeError","validate","setReadOnly","NaN","triangular0","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","seed","seedLength","state","s","stateLength","byteLength","out","name","NAME","typedarray2json","params","normalized","main"],"mappings":";;u+CAqCA,SAASA,EAAYC,EAAMC,EAAGC,EAAGC,GAChC,IAAIC,EAEAC,EAGJ,OAFAD,GAAMD,EAAIF,IAAMC,EAAID,IACpBI,EAAIL,KACKI,EAEDH,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACEI,GAGfH,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAME,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAR,EACAS,EACAC,EACAT,EACAC,EACAC,EAEJ,GAA0B,IAArBQ,UAAUC,OACdZ,EAAOa,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IACf,MACGT,EAAOa,EAAOL,EAEjB,KAAQ,CAKN,GADAE,ECzDF,SAAmBT,EAAGC,EAAGC,GACxB,OAAMgB,EAAUlB,IAAOmB,EAAOnB,GACtB,IAAIc,UAAWC,EAAQ,QAASf,KAElCkB,EAAUjB,IAAOkB,EAAOlB,GACtB,IAAIa,UAAWC,EAAQ,QAASd,KAElCiB,EAAUhB,IAAOiB,EAAOjB,GACtB,IAAIY,UAAWC,EAAQ,QAASb,IAEjCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAImB,WAAYL,EAAQ,QAAS,cAAef,EAAGC,EAAGC,GAG/D,CD2CQmB,CAHNrB,EAAIU,UAAW,GACfT,EAAIS,UAAW,GACfR,EAAIQ,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IAChB,MACIT,EAAOa,EAAOL,EAElB,MACGR,EAAOa,GAER,CA2BD,OArBAU,EAJCd,OADU,IAANR,EAmJL,SAAsBA,EAAGC,EAAGC,GAC3B,GACCiB,EAAOnB,IACPmB,EAAOlB,IACPkB,EAAOjB,MACLF,GAAKE,GAAKA,GAAKD,GAEjB,OAAOsB,IAER,OAAOC,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAnCD,WACC,OAAOsB,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAvHkB,OAAQ,cAGtBK,GAAQA,EAAKC,MACjBc,EAAad,EAAM,OAAQ,MAC3Bc,EAAad,EAAM,aAAc,MACjCiB,EAAsBjB,EAAM,QAASkB,EAAkB,MAAQC,GAC/DL,EAAad,EAAM,cAAe,MAClCc,EAAad,EAAM,aAAc,MACjCc,EAAad,EAAM,SAAUkB,EAAkB,OAC/CJ,EAAad,EAAM,OAAQT,KAE3B6B,EAAqBpB,EAAM,QAiB5B,WACC,OAAOT,EAAK8B,IACZ,IAlBAD,EAAqBpB,EAAM,cA0B5B,WACC,OAAOT,EAAK+B,UACZ,IA3BAL,EAAsBjB,EAAM,SAuD7B,WACC,OAAOT,EAAKgC,KACZ,IASD,SAAmBC,GAClBjC,EAAKgC,MAAQC,CACb,IAnEAJ,EAAqBpB,EAAM,eAkC5B,WACC,OAAOT,EAAKkC,WACZ,IAnCAL,EAAqBpB,EAAM,cA2C5B,WACC,OAAOT,EAAKmC,UACZ,IA5CAZ,EAAad,EAAM,UA6EpB,WACC,IAAI2B,EAAM,CACVA,KAAW,QACXA,EAAIC,KAAO5B,EAAK6B,KAChBF,EAAIJ,MAAQO,EAAiBvC,EAAKgC,OAEjCI,EAAII,YADM,IAANvC,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEtB,OAAOiC,CACP,IAvFAb,EAAad,EAAM,OAAQT,GAC3BA,EAAOA,EAAKyC,YAENhC,CAoIR,CE/OG,IAACV,EAAaQ,ICkBjBgB,EAAAmB,EAAA,UAAAnC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 62ee6dd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ebc547601fbd1ddd0c410d3d6ba16c1659438b7f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:38:29 +0000 Subject: [PATCH 80/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 51 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 -- examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 -- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ----- test/test.js | 124 - 50 files changed, 4874 insertions(+), 5889 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 02b1e86..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -462,7 +459,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -527,15 +524,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm -[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular +[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular/tree/esm -[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular +[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c284b1f..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-base-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-base-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-base-triangular/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dc80cb6..fc6107f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3bed0da --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.1-esm/index.mjs";function u(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(j=arguments[3]))throw new TypeError(a("0p92V",j));if(i(j,"prng")){if(!r(j.prng))throw new TypeError(a("0p96u","prng",j.prng));g=j.prng}else g=m(j)}else g=m()}return e(c=void 0===b?function(e,t,n){if(l(e)||l(t)||l(n)||!(e<=n&&n<=t))return NaN;return u(g,e,t,n)}:function(){return u(g,b,y,w)},"NAME","triangular"),j&&j.prng?(e(c,"seed",null),e(c,"seedLength",null),n(c,"state",o(null),d),e(c,"stateLength",null),e(c,"byteLength",null),e(c,"toJSON",o(null)),e(c,"PRNG",g)):(t(c,"seed",(function(){return g.seed})),t(c,"seedLength",(function(){return g.seedLength})),n(c,"state",(function(){return g.state}),(function(e){g.state=e})),t(c,"stateLength",(function(){return g.stateLength})),t(c,"byteLength",(function(){return g.byteLength})),e(c,"toJSON",(function(){var e={type:"PRNG"};e.name=c.NAME,e.state=p(g.state),e.params=void 0===b?[]:[b,y,w];return e})),e(c,"PRNG",g),g=g.normalized),c}var c=g();e(c,"factory",g);export{c as default,g as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6293ecd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/triangular.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["triangular","rand","a","b","c","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","TypeError","format","hasOwnProp","isFunction","isNumber","isnan","RangeError","validate","setReadOnly","NaN","triangular0","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","seed","seedLength","state","s","stateLength","byteLength","out","name","NAME","typedarray2json","params","normalized","main"],"mappings":";;u+CAqCA,SAASA,EAAYC,EAAMC,EAAGC,EAAGC,GAChC,IAAIC,EAEAC,EAGJ,OAFAD,GAAMD,EAAIF,IAAMC,EAAID,IACpBI,EAAIL,KACKI,EAEDH,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACEI,GAGfH,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAME,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAR,EACAS,EACAC,EACAT,EACAC,EACAC,EAEJ,GAA0B,IAArBQ,UAAUC,OACdZ,EAAOa,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IACf,MACGT,EAAOa,EAAOL,EAEjB,KAAQ,CAKN,GADAE,ECzDF,SAAmBT,EAAGC,EAAGC,GACxB,OAAMgB,EAAUlB,IAAOmB,EAAOnB,GACtB,IAAIc,UAAWC,EAAQ,QAASf,KAElCkB,EAAUjB,IAAOkB,EAAOlB,GACtB,IAAIa,UAAWC,EAAQ,QAASd,KAElCiB,EAAUhB,IAAOiB,EAAOjB,GACtB,IAAIY,UAAWC,EAAQ,QAASb,IAEjCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAImB,WAAYL,EAAQ,QAAS,cAAef,EAAGC,EAAGC,GAG/D,CD2CQmB,CAHNrB,EAAIU,UAAW,GACfT,EAAIS,UAAW,GACfR,EAAIQ,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IAChB,MACIT,EAAOa,EAAOL,EAElB,MACGR,EAAOa,GAER,CA2BD,OArBAU,EAJCd,OADU,IAANR,EAmJL,SAAsBA,EAAGC,EAAGC,GAC3B,GACCiB,EAAOnB,IACPmB,EAAOlB,IACPkB,EAAOjB,MACLF,GAAKE,GAAKA,GAAKD,GAEjB,OAAOsB,IAER,OAAOC,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAnCD,WACC,OAAOsB,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAvHkB,OAAQ,cAGtBK,GAAQA,EAAKC,MACjBc,EAAad,EAAM,OAAQ,MAC3Bc,EAAad,EAAM,aAAc,MACjCiB,EAAsBjB,EAAM,QAASkB,EAAkB,MAAQC,GAC/DL,EAAad,EAAM,cAAe,MAClCc,EAAad,EAAM,aAAc,MACjCc,EAAad,EAAM,SAAUkB,EAAkB,OAC/CJ,EAAad,EAAM,OAAQT,KAE3B6B,EAAqBpB,EAAM,QAiB5B,WACC,OAAOT,EAAK8B,IACZ,IAlBAD,EAAqBpB,EAAM,cA0B5B,WACC,OAAOT,EAAK+B,UACZ,IA3BAL,EAAsBjB,EAAM,SAuD7B,WACC,OAAOT,EAAKgC,KACZ,IASD,SAAmBC,GAClBjC,EAAKgC,MAAQC,CACb,IAnEAJ,EAAqBpB,EAAM,eAkC5B,WACC,OAAOT,EAAKkC,WACZ,IAnCAL,EAAqBpB,EAAM,cA2C5B,WACC,OAAOT,EAAKmC,UACZ,IA5CAZ,EAAad,EAAM,UA6EpB,WACC,IAAI2B,EAAM,CACVA,KAAW,QACXA,EAAIC,KAAO5B,EAAK6B,KAChBF,EAAIJ,MAAQO,EAAiBvC,EAAKgC,OAEjCI,EAAII,YADM,IAANvC,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEtB,OAAOiC,CACP,IAvFAb,EAAad,EAAM,OAAQT,GAC3BA,EAAOA,EAAKyC,YAENhC,CAoIR,CE/OG,IAACV,EAAaQ,ICkBjBgB,EAAAmB,EAAA,UAAAnC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1a199aa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2836c0b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee5e8fb..c2ce925 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-nan": "^0.2.1", - "@stdlib/assert-is-number": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-special-sqrt": "^0.2.1", - "@stdlib/random-base-mt19937": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-constant-function": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/assert-is-uint32array": "^0.2.1", - "@stdlib/constants-uint32-max": "^0.2.1", - "@stdlib/process-env": "^0.2.1", - "@stdlib/random-base-minstd": "^0.2.1", - "@stdlib/random-base-minstd-shuffle": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/stats-kstest": "^0.2.1", - "@stdlib/time-now": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..62ee6dd --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 66b995bf764fed2ef9cf75e3de255dd7afdc6df9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 02:33:08 +0000 Subject: [PATCH 81/83] Transform error messages --- lib/factory.js | 10 +++++----- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2346fdb..1a199aa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -31,7 +31,7 @@ var noop = require( '@stdlib/utils-noop' ); var randu = require( '@stdlib/random-base-mt19937' ).factory; var isnan = require( '@stdlib/math-base-assert-is-nan' ); var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var triangular0 = require( './triangular.js' ); @@ -85,11 +85,11 @@ function factory() { } else if ( arguments.length === 1 ) { opts = arguments[ 0 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); } rand = opts.prng; } else { @@ -106,11 +106,11 @@ function factory() { if ( arguments.length > 3 ) { opts = arguments[ 3 ]; if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + throw new TypeError( format( '0p92V', opts ) ); } if ( hasOwnProp( opts, 'prng' ) ) { if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); + throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); } rand = opts.prng; } else { diff --git a/lib/validate.js b/lib/validate.js index 99526d7..2836c0b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -21,7 +21,7 @@ // MODULES // var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isnan = require( '@stdlib/assert-is-nan' ); @@ -44,16 +44,16 @@ var isnan = require( '@stdlib/assert-is-nan' ); */ function validate( a, b, c ) { if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); + return new TypeError( format( '0p96v', a ) ); } if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); + return new TypeError( format( '0p96w', b ) ); } if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); + return new TypeError( format( '0p97C', c ) ); } if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); + return new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) ); } return null; } diff --git a/package.json b/package.json index 5882b84..286d9c5 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/math-base-assert-is-nan": "^0.2.2", "@stdlib/math-base-special-sqrt": "^0.2.2", "@stdlib/random-base-mt19937": "^0.2.1", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-constant-function": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From b2a260e8585f352676bc3517990077e517afcb9e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 03:22:48 +0000 Subject: [PATCH 82/83] Remove files --- index.d.ts | 243 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5090 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index fc6107f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,243 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import * as random from '@stdlib/types/random'; - -/** -* Interface defining `factory` options. -*/ -interface Options { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. - */ - copy?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Generator name. - */ - readonly NAME: string; - - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937; - - /** - * PRNG seed length. - */ - readonly seedLength: number; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937; - - /** - * PRNG state length. - */ - readonly stateLength: number; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number; - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * @returns JSON representation - */ - toJSON(): string; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution with pre-specified parameter values. -*/ -interface NullaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @returns pseudorandom number - */ - (): number; -} - -/** -* Interface for generating pseudorandom numbers from a triangular distribution without pre-specified parameter values. -*/ -interface TernaryFunction extends PRNG { - /** - * Returns a pseudorandom number drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - */ - ( a: number, b: number, c: number ): number; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns pseudorandom number drawn from a triangular distribution. - * - * ## Notes - * - * - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - * - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @returns pseudorandom number - * - * @example - * var v = triangular( 2.0, 5.0, 3.33 ); - * // returns - * - * @example - * var v = triangular( 1.0, 2.0, 1.8 ); - * // returns NaN - */ - ( a: number, b: number, c: number ): number; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When provided `a`, `b`, and `c`, the returned PRNG returns random variates drawn from the specified distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws arguments must satisfy `a <= c <= b` - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory( 1.0, 3.0, 1.5 ); - * var v = rand(); - * // returns - * - * @example - * var rand = triangular.factory( 1.0, 2.0, 1.5, { - * 'seed': 297 - * }); - * var v = rand(); - * // returns - */ - factory( a: number, b: number, c: number, options?: Options ): NullaryFunction; - - /** - * Returns a pseudorandom number generator for generating random numbers from a triangular distribution. - * - * ## Notes - * - * - When not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, and `c` be provided at each invocation. - * - * @param options - function options - * @param options.prng - pseudorandom number generator which generates uniformly distributed pseudorandom numbers - * @param options.seed - pseudorandom number generator seed - * @param options.state - pseudorandom number generator state - * @param options.copy - boolean indicating whether to copy a provided pseudorandom number generator state (default: true) - * @throws must provide a valid state - * @returns pseudorandom number generator - * - * @example - * var rand = triangular.factory(); - * var v = rand( 1.0, 3.0, 1.5 ); - * // returns - * - * @example - * var rand = triangular.factory({ - * 'seed': 297 - * }); - * var v = rand( 1.0, 2.0, 1.5 ); - * // returns - */ - factory( options?: Options ): TernaryFunction; -} - -/** -* Returns pseudorandom number drawn from a triangular distribution. -* -* ## Notes -* -* - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. -* - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. -* -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @returns pseudorandom number -* -* @example -* var v = triangular( 2.0, 5.0, 3.33 ); -* // returns -* -* @example -* var rand = triangular.factory({ -* 'seed': 297 -* }); -* var v = rand( 1.0, 2.0, 1.5 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3bed0da..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.1-esm/index.mjs";function u(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(j=arguments[3]))throw new TypeError(a("0p92V",j));if(i(j,"prng")){if(!r(j.prng))throw new TypeError(a("0p96u","prng",j.prng));g=j.prng}else g=m(j)}else g=m()}return e(c=void 0===b?function(e,t,n){if(l(e)||l(t)||l(n)||!(e<=n&&n<=t))return NaN;return u(g,e,t,n)}:function(){return u(g,b,y,w)},"NAME","triangular"),j&&j.prng?(e(c,"seed",null),e(c,"seedLength",null),n(c,"state",o(null),d),e(c,"stateLength",null),e(c,"byteLength",null),e(c,"toJSON",o(null)),e(c,"PRNG",g)):(t(c,"seed",(function(){return g.seed})),t(c,"seedLength",(function(){return g.seedLength})),n(c,"state",(function(){return g.state}),(function(e){g.state=e})),t(c,"stateLength",(function(){return g.stateLength})),t(c,"byteLength",(function(){return g.byteLength})),e(c,"toJSON",(function(){var e={type:"PRNG"};e.name=c.NAME,e.state=p(g.state),e.params=void 0===b?[]:[b,y,w];return e})),e(c,"PRNG",g),g=g.normalized),c}var c=g();e(c,"factory",g);export{c as default,g as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6293ecd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/triangular.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["triangular","rand","a","b","c","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","TypeError","format","hasOwnProp","isFunction","isNumber","isnan","RangeError","validate","setReadOnly","NaN","triangular0","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","seed","seedLength","state","s","stateLength","byteLength","out","name","NAME","typedarray2json","params","normalized","main"],"mappings":";;u+CAqCA,SAASA,EAAYC,EAAMC,EAAGC,EAAGC,GAChC,IAAIC,EAEAC,EAGJ,OAFAD,GAAMD,EAAIF,IAAMC,EAAID,IACpBI,EAAIL,KACKI,EAEDH,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACEI,GAGfH,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAME,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAR,EACAS,EACAC,EACAT,EACAC,EACAC,EAEJ,GAA0B,IAArBQ,UAAUC,OACdZ,EAAOa,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IACf,MACGT,EAAOa,EAAOL,EAEjB,KAAQ,CAKN,GADAE,ECzDF,SAAmBT,EAAGC,EAAGC,GACxB,OAAMgB,EAAUlB,IAAOmB,EAAOnB,GACtB,IAAIc,UAAWC,EAAQ,QAASf,KAElCkB,EAAUjB,IAAOkB,EAAOlB,GACtB,IAAIa,UAAWC,EAAQ,QAASd,KAElCiB,EAAUhB,IAAOiB,EAAOjB,GACtB,IAAIY,UAAWC,EAAQ,QAASb,IAEjCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAImB,WAAYL,EAAQ,QAAS,cAAef,EAAGC,EAAGC,GAG/D,CD2CQmB,CAHNrB,EAAIU,UAAW,GACfT,EAAIS,UAAW,GACfR,EAAIQ,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IAChB,MACIT,EAAOa,EAAOL,EAElB,MACGR,EAAOa,GAER,CA2BD,OArBAU,EAJCd,OADU,IAANR,EAmJL,SAAsBA,EAAGC,EAAGC,GAC3B,GACCiB,EAAOnB,IACPmB,EAAOlB,IACPkB,EAAOjB,MACLF,GAAKE,GAAKA,GAAKD,GAEjB,OAAOsB,IAER,OAAOC,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAnCD,WACC,OAAOsB,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAvHkB,OAAQ,cAGtBK,GAAQA,EAAKC,MACjBc,EAAad,EAAM,OAAQ,MAC3Bc,EAAad,EAAM,aAAc,MACjCiB,EAAsBjB,EAAM,QAASkB,EAAkB,MAAQC,GAC/DL,EAAad,EAAM,cAAe,MAClCc,EAAad,EAAM,aAAc,MACjCc,EAAad,EAAM,SAAUkB,EAAkB,OAC/CJ,EAAad,EAAM,OAAQT,KAE3B6B,EAAqBpB,EAAM,QAiB5B,WACC,OAAOT,EAAK8B,IACZ,IAlBAD,EAAqBpB,EAAM,cA0B5B,WACC,OAAOT,EAAK+B,UACZ,IA3BAL,EAAsBjB,EAAM,SAuD7B,WACC,OAAOT,EAAKgC,KACZ,IASD,SAAmBC,GAClBjC,EAAKgC,MAAQC,CACb,IAnEAJ,EAAqBpB,EAAM,eAkC5B,WACC,OAAOT,EAAKkC,WACZ,IAnCAL,EAAqBpB,EAAM,cA2C5B,WACC,OAAOT,EAAKmC,UACZ,IA5CAZ,EAAad,EAAM,UA6EpB,WACC,IAAI2B,EAAM,CACVA,KAAW,QACXA,EAAIC,KAAO5B,EAAK6B,KAChBF,EAAIJ,MAAQO,EAAiBvC,EAAKgC,OAEjCI,EAAII,YADM,IAANvC,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEtB,OAAOiC,CACP,IAvFAb,EAAad,EAAM,OAAQT,GAC3BA,EAAOA,EAAKyC,YAENhC,CAoIR,CE/OG,IAACV,EAAaQ,ICkBjBgB,EAAAmB,EAAA,UAAAnC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 62ee6dd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 47dd264d9bde591ed28a61e088640c6917b89798 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 03:23:08 +0000 Subject: [PATCH 83/83] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 178 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 105 - benchmark/benchmark.js | 111 - benchmark/benchmark.to_json.js | 48 - benchmark/r/DESCRIPTION | 10 - benchmark/r/benchmark.R | 116 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 190 - docs/types/test.ts | 249 - examples/index.js | 50 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 286 -- lib/index.js | 65 - lib/main.js | 47 - lib/triangular.js | 55 - lib/validate.js | 64 - package.json | 76 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 985 ---- test/test.js | 124 - 52 files changed, 4874 insertions(+), 6181 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/r/DESCRIPTION delete mode 100644 benchmark/r/benchmark.R delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/triangular.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b64306a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T02:18:06.370Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index b275b5a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 02b1e86..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 18 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -462,7 +459,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -527,15 +524,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm -[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular +[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular/tree/esm -[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular +[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c284b1f..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-base-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-base-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-base-triangular/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\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"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dc80cb6..fc6107f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..753b7e9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.2-esm/index.mjs";function u(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(j=arguments[3]))throw new TypeError(a("0p92V",j));if(i(j,"prng")){if(!r(j.prng))throw new TypeError(a("0p96u","prng",j.prng));g=j.prng}else g=m(j)}else g=m()}return e(c=void 0===b?function(e,t,n){if(l(e)||l(t)||l(n)||!(e<=n&&n<=t))return NaN;return u(g,e,t,n)}:function(){return u(g,b,y,w)},"NAME","triangular"),j&&j.prng?(e(c,"seed",null),e(c,"seedLength",null),n(c,"state",o(null),d),e(c,"stateLength",null),e(c,"byteLength",null),e(c,"toJSON",o(null)),e(c,"PRNG",g)):(t(c,"seed",(function(){return g.seed})),t(c,"seedLength",(function(){return g.seedLength})),n(c,"state",(function(){return g.state}),(function(e){g.state=e})),t(c,"stateLength",(function(){return g.stateLength})),t(c,"byteLength",(function(){return g.byteLength})),e(c,"toJSON",(function(){var e={type:"PRNG"};e.name=c.NAME,e.state=p(g.state),e.params=void 0===b?[]:[b,y,w];return e})),e(c,"PRNG",g),g=g.normalized),c}var c=g();e(c,"factory",g);export{c as default,g as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6293ecd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/triangular.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\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 {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\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.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.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.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.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.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.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["triangular","rand","a","b","c","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","TypeError","format","hasOwnProp","isFunction","isNumber","isnan","RangeError","validate","setReadOnly","NaN","triangular0","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","seed","seedLength","state","s","stateLength","byteLength","out","name","NAME","typedarray2json","params","normalized","main"],"mappings":";;u+CAqCA,SAASA,EAAYC,EAAMC,EAAGC,EAAGC,GAChC,IAAIC,EAEAC,EAGJ,OAFAD,GAAMD,EAAIF,IAAMC,EAAID,IACpBI,EAAIL,KACKI,EAEDH,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACEI,GAGfH,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAME,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAR,EACAS,EACAC,EACAT,EACAC,EACAC,EAEJ,GAA0B,IAArBQ,UAAUC,OACdZ,EAAOa,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IACf,MACGT,EAAOa,EAAOL,EAEjB,KAAQ,CAKN,GADAE,ECzDF,SAAmBT,EAAGC,EAAGC,GACxB,OAAMgB,EAAUlB,IAAOmB,EAAOnB,GACtB,IAAIc,UAAWC,EAAQ,QAASf,KAElCkB,EAAUjB,IAAOkB,EAAOlB,GACtB,IAAIa,UAAWC,EAAQ,QAASd,KAElCiB,EAAUhB,IAAOiB,EAAOjB,GACtB,IAAIY,UAAWC,EAAQ,QAASb,IAEjCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAImB,WAAYL,EAAQ,QAAS,cAAef,EAAGC,EAAGC,GAG/D,CD2CQmB,CAHNrB,EAAIU,UAAW,GACfT,EAAIS,UAAW,GACfR,EAAIQ,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IAChB,MACIT,EAAOa,EAAOL,EAElB,MACGR,EAAOa,GAER,CA2BD,OArBAU,EAJCd,OADU,IAANR,EAmJL,SAAsBA,EAAGC,EAAGC,GAC3B,GACCiB,EAAOnB,IACPmB,EAAOlB,IACPkB,EAAOjB,MACLF,GAAKE,GAAKA,GAAKD,GAEjB,OAAOsB,IAER,OAAOC,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAnCD,WACC,OAAOsB,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAvHkB,OAAQ,cAGtBK,GAAQA,EAAKC,MACjBc,EAAad,EAAM,OAAQ,MAC3Bc,EAAad,EAAM,aAAc,MACjCiB,EAAsBjB,EAAM,QAASkB,EAAkB,MAAQC,GAC/DL,EAAad,EAAM,cAAe,MAClCc,EAAad,EAAM,aAAc,MACjCc,EAAad,EAAM,SAAUkB,EAAkB,OAC/CJ,EAAad,EAAM,OAAQT,KAE3B6B,EAAqBpB,EAAM,QAiB5B,WACC,OAAOT,EAAK8B,IACZ,IAlBAD,EAAqBpB,EAAM,cA0B5B,WACC,OAAOT,EAAK+B,UACZ,IA3BAL,EAAsBjB,EAAM,SAuD7B,WACC,OAAOT,EAAKgC,KACZ,IASD,SAAmBC,GAClBjC,EAAKgC,MAAQC,CACb,IAnEAJ,EAAqBpB,EAAM,eAkC5B,WACC,OAAOT,EAAKkC,WACZ,IAnCAL,EAAqBpB,EAAM,cA2C5B,WACC,OAAOT,EAAKmC,UACZ,IA5CAZ,EAAad,EAAM,UA6EpB,WACC,IAAI2B,EAAM,CACVA,KAAW,QACXA,EAAIC,KAAO5B,EAAK6B,KAChBF,EAAIJ,MAAQO,EAAiBvC,EAAKgC,OAEjCI,EAAII,YADM,IAANvC,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEtB,OAAOiC,CACP,IAvFAb,EAAad,EAAM,OAAQT,GAC3BA,EAAOA,EAAKyC,YAENhC,CAoIR,CE/OG,IAACV,EAAaQ,ICkBjBgB,EAAAmB,EAAA,UAAAnC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1a199aa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( '0p92V', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( '0p96u', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2836c0b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( '0p96v', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( '0p96w', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( '0p97C', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 286d9c5..c2ce925 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-nan": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-sqrt": "^0.2.2", - "@stdlib/random-base-mt19937": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-constant-function": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/assert-is-uint32array": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/process-env": "^0.2.2", - "@stdlib/random-base-minstd": "^0.2.1", - "@stdlib/random-base-minstd-shuffle": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/stats-kstest": "^0.2.2", - "@stdlib/time-now": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dc929a3 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -});