UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 4.19 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import t from"./../../utils/define-nonenumerable-read-only-property.js";import e from"./../../utils/define-nonenumerable-read-only-accessor.js";import r from"./../../utils/define-nonenumerable-read-write-accessor.js";import n from"./../../assert/has-own-property.js";import o from"./../../assert/is-plain-object.js";import i from"./../../assert/is-uint32array.js";import a from"./../../assert/is-boolean.js";import s from"./../../assert/is-function.js";import p from"./../../utils/constant-function.js";import m from"./../../utils/noop.js";import u from"./../../math/base/assert/is-nan.js";import l from"./poisson.js";import f from"./gamma.js";import g from"./../../blas/base/gcopy.js";import c from"./../../array/uint32.js";import y from"./../../utils/copy.js";import d from"./../../array/to-json.js";import b from"./../../assert/is-positive-number.js";import h from"./../../assert/is-number.js";import v from"./../../assert/is-nan.js";var w=b.isPrimitive,j=h.isPrimitive,E=v;function N(t,e){return w(t)?!j(e)||E(e)?new TypeError("invalid argument. Second argument must be a number primitive and not `NaN`. Value: `"+e+"`."):e<=0||e>=1?new RangeError("invalid argument. Second argument must be on the interval `(0,1)`. Value: `"+e+"`."):null:new TypeError("invalid argument. First argument must be a positive number. Value: `"+t+"`.")}var T=t,O=e,L=r,P=n,V=o,A=i,R=a.isPrimitive,S=s,G=p,M=m,U=u,J=l.factory,x=f.factory,F=g,k=c,q=y,z=d,B=N;function C(){var t,e,r,n,o,i,a,s,p,m;if(a=!0,0===arguments.length)r=J(n={copy:!1});else if(1===arguments.length){if(!V(n=arguments[0]))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+n+"`.");if(P(n,"copy")&&!R(n.copy))throw new TypeError("invalid option. `copy` option must be a boolean. Option: `"+n.copy+"`.");if(P(n,"prng")){if(!S(n.prng))throw new TypeError("invalid option. `prng` option must be a pseudorandom number generator function. Option: `"+n.prng+"`.");r=J({prng:n.prng})}else{if(P(n,"state")&&!A(n.state))throw new TypeError("invalid option. `state` option must be a Uint32Array. Option: `"+n.state+"`.");!1===(n=q(n,1)).copy?a=!1:n.state&&(n.state=F(n.state.length,n.state,1,new k(n.state.length),1)),n.copy=!1,r=J(n)}}else{if(s=B(m=arguments[0],p=arguments[1]))throw s;if(arguments.length>2){if(!V(n=arguments[2]))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+n+"`.");if(P(n,"copy")&&!R(n.copy))throw new TypeError("invalid option. `copy` option must be a boolean. Option: `"+n.copy+"`.");if(P(n,"prng")){if(!S(n.prng))throw new TypeError("invalid option. `prng` option must be a pseudorandom number generator function. Option: `"+n.prng+"`.");r=J({prng:n.prng})}else{if(P(n,"state")&&!A(n.state))throw new TypeError("invalid option. `state` option must be a Uint32Array. Option: `"+n.state+"`.");!1===(n=q(n,1)).copy?a=!1:n.state&&(n.state=F(n.state.length,n.state,1,new k(n.state.length),1)),n.copy=!1,r=J(n)}}else r=J(n={copy:!1})}return n&&n.prng?t=void 0===m?x({prng:n.prng}):x(m,p/(1-p),{prng:n.prng}):(n.state?e=n.state:(e=r.state,r.state=e),t=void 0===m?x({state:e,copy:!1}):x(m,p/(1-p),{state:e,copy:!1})),o=void 0===m?h:b,i=r.PRNG,T(o,"NAME","negative-binomial"),n&&n.prng?(T(o,"seed",null),T(o,"seedLength",null),L(o,"state",G(null),M),T(o,"stateLength",null),T(o,"byteLength",null),T(o,"toJSON",G(null))):(O(o,"seed",u),O(o,"seedLength",l),L(o,"state",c,y),O(o,"stateLength",f),O(o,"byteLength",g),T(o,"toJSON",d)),T(o,"PRNG",i),o;function u(){return i.seed}function l(){return i.seedLength}function f(){return i.stateLength}function g(){return i.byteLength}function c(){return i.state}function y(t){if(!A(t))throw new TypeError("invalid argument. Must provide a Uint32Array. Value: `"+t+"`.");a&&(t=F(t.length,t,1,new k(t.length),1)),i.state=t}function d(){var t={type:"PRNG"};return t.name=o.NAME,t.state=z(i.state),t.params=void 0===m?[]:[m,p],t}function b(){return r(t())}function h(e,n){return U(e)||U(n)||n<=0||n>=1?NaN:r(t(e,n/(1-n)))}}var D=C,H=D(),I=t,K=H,Q=C;I(K,"factory",Q);export default K; //# sourceMappingURL=negative-binomial.js.map