import numpy.random as rnd from numpy import * import numpy as np @test def test_PCG64_integers(seed, low, expected, high=None, size=None, e=False): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(low, int) or isinstance(low, float)) and (high is None or isinstance( high, int) or isinstance(high, float)): assert gen.integers(low, high, endpoint=e) == expected else: assert (gen.integers(low, high, endpoint=e) == expected).all() else: assert (gen.integers(low, high, size, endpoint=e) == expected).all() test_PCG64_integers(1234, 5, 4) test_PCG64_integers(5678, 987.4, 43) test_PCG64_integers(5678, 98, 137, high=987) test_PCG64_integers(74, 89, 17, e=True) test_PCG64_integers(74, -1218, -958, high=98) test_PCG64_integers(74, -5, np.array([6, 48, 17]), 55, size=3) test_PCG64_integers(74, -5, np.array([7, 49, 17]), 55, size=3, e=True) test_PCG64_integers(5678, np.array([7, 49, 17]), np.array([10, 75, 43]), 78) test_PCG64_integers(5678, -99, np.array([-92, 74, -13]), np.array([77, 89, 101])) test_PCG64_integers(5678, np.array([7, 49, 17]), np.array([10, 85, 53]), np.array([77, 89, 101])) @test def test_PCG64_random(seed, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: assert gen.random() == expected else: assert (round(gen.random(size), 8) == round(expected, 8)).all() test_PCG64_random(0, 0.6369616873214543) test_PCG64_random(1, 0.5118216247002567) test_PCG64_random(1234, 0.9766997666981422) test_PCG64_random( 1234567, np.array([0.99365208, 0.00776825, 0.23769419, 0.77242113, 0.30128085]), size=5) test_PCG64_random(74, np.array([[0.89437827, 0.52072095, 0.67640414], [0.66919894, 0.56483809, 0.5245347]]), size=(2, 3)) @test def test_PCG64_choice(seed, a, expected, size=None, r=True, p=None, axis=0, shuffle=True): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if isinstance(a, int): assert gen.choice(a, size, r, p, axis, shuffle) == expected elif staticlen(a.shape) == 1: assert gen.choice(a, size, r, p, axis, shuffle) == expected else: assert (round(gen.choice(a, size, r, p, axis, shuffle), 8) == expected).all() else: assert (round(gen.choice(a, size, r, p, axis, shuffle), 8) == expected).all() test_PCG64_choice( 621, np.array([ 1.34, 2.15, 3.21, 4.78, 5.55, 6.42, 7.99, 8.31, 9.61, 10.75, 11.33, 12.93 ]), np.array([4.78, 7.99, 8.31]), 3) test_PCG64_choice( 318, np.array([5, 4, 2, 6, 7, 8, 2, 12, 1, 55, 33, 7, 78, 15, 43]), 4) test_PCG64_choice(318, np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), np.array([11, 2, 12]), 3, False) test_PCG64_choice( 4589, np.array([ -1.34, -2.15, -3.21, -4.78, -5.55, -6.42, -7.99, -8.31, -9.61, -10.75, -11.33, -12.93 ]), -7.99) test_PCG64_choice(318, np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]), np.array([[1, 2, 3], [10, 11, 12]]), 2) test_PCG64_choice(74, np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]), np.array([1, 2, 3])) test_PCG64_choice(74, 1, 0) test_PCG64_choice(74, np.array([13, -4]), -4, p=np.array([0.3, 0.7])) test_PCG64_choice(74, np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]), np.array([[1], [4], [7], [10]]), axis=1) test_PCG64_choice(74, np.array([13, -4, 3, 18]), 3, p=np.array([0.5, 0.3, 0.1, 0.1]), shuffle=True) @test def test_PCG64_bytes(seed, length, expected): gen = rnd.Generator(rnd.PCG64(seed)) check = gen.bytes(length) == expected assert check test_PCG64_bytes(555, 10, "\xbe^\x97g\x10\xa4;7z\x95") @test def test_PCG64_shuffle(seed, x, expected, axis=0): gen = rnd.Generator(rnd.PCG64(seed)) gen.shuffle(x, axis) assert (x == expected).all() test_PCG64_shuffle(876, np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), np.array([6, 3, 5, 9, 7, 8, 1, 2, 4, 0])) test_PCG64_shuffle(111, np.array([5.43, 6.56, 1.22, 4.3221, 7.88, 0.9352]), np.array([0.9352, 6.56, 5.43, 7.88, 1.22, 4.3221])) test_PCG64_shuffle(1234, np.array([3.14]), np.array([3.14])) test_PCG64_shuffle(74, np.arange(9).reshape((3, 3)), np.array([[6, 7, 8], [3, 4, 5], [0, 1, 2]])) test_PCG64_shuffle(74, np.arange(9).reshape((3, 3)), np.array([[2, 1, 0], [5, 4, 3], [8, 7, 6]]), axis=1) @test def test_PCG64_permutation(seed, x, expected, axis=0): gen = rnd.Generator(rnd.PCG64(seed)) assert (gen.permutation(x, axis) == expected).all() test_PCG64_permutation(12345, 10, np.array([4, 8, 1, 3, 7, 9, 6, 0, 2, 5])) test_PCG64_permutation(1234, np.array([1.124, 4.7532, 9.1246, 12.53243, 15.64324]), np.array([1.124, 15.64324, 4.7532, 12.53243, 9.1246])) test_PCG64_permutation( 4321, np.arange(24).reshape(3, 8), np.array([[16, 17, 18, 19, 20, 21, 22, 23], [8, 9, 10, 11, 12, 13, 14, 15], [0, 1, 2, 3, 4, 5, 6, 7]])) test_PCG64_permutation(74, np.arange(9).reshape((3, 3)), np.array([[2, 1, 0], [5, 4, 3], [8, 7, 6]]), axis=1) @test def test_PCG64_permuted(seed, x, expected, axis=None): gen = rnd.Generator(rnd.PCG64(seed)) arr = gen.permuted(x, axis) assert (arr == expected).all() test_PCG64_permuted(4321, np.array([1.124, 4.7532, 9.1246, 12.53243, 15.64324]), np.array([1.124, 4.7532, 9.1246, 12.53243, 15.64324])) test_PCG64_permuted( 4321, np.arange(24).reshape(3, 8), np.array([[17, 6, 2, 12, 8, 10, 23, 7], [11, 13, 4, 19, 22, 5, 18, 21], [14, 1, 9, 0, 16, 3, 15, 20]])) @test def test_PCG64_beta(seed, a, b, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(a, int) or isinstance(a, float)) and (isinstance( b, int) or isinstance(b, float)): assert gen.beta(a, b) == expected else: assert (round(gen.beta(a, b), 8) == expected).all() else: assert (round(gen.beta(a, b, size), 8) == expected).all() #test_PCG64_beta(4321, -7, 0, error) test_PCG64_beta(4321, 0.2, 0.1, 2.2810297427691828e-12) test_PCG64_beta(4321, 10, 14, 0.4269214782557806) test_PCG64_beta(4321, 167, 2041, np.array([0.07569048, 0.08132162, 0.07432054, 0.07364077]), 4) test_PCG64_beta(139, 14.32, 4, 0.7753363939635708) test_PCG64_beta(457, 12.87, 9.21, 0.5055315480345436) test_PCG64_beta( 457, np.array([12.87, 1.32, 4.532, 1.34, 8.432]), 9.21, np.array([0.50553155, 0.01362657, 0.34461015, 0.17758410, 0.47101973])) test_PCG64_beta( 457, 32.14, np.array([9.21, 0.21, 14.32, 41.21, 5.55]), np.array([0.72323361, 0.99185115, 0.76192197, 0.44454895, 0.86813848])) test_PCG64_beta( 457, np.array([12.87, 1.32, 4.532, 1.34, 8.432]), np.array([9.21, 0.21, 14.32, 41.21, 5.55]), np.array([0.50553155, 0.36824135, 0.22202680, 0.05385470, 0.61055151])) @test def test_PCG64_binomial(seed, n, p, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(n, int) or isinstance(n, float)) and (isinstance( p, int) or isinstance(p, float)): assert gen.binomial(n, p) == expected else: assert (gen.binomial(n, p) == expected).all() else: assert (gen.binomial(n, p, size) == expected).all() #test_PCG64_binomial(139, -2, .33, 0) test_PCG64_binomial(139, 28400, .66, 18748) test_PCG64_binomial(139, 14.76, .33, 4) test_PCG64_binomial(139, 0, .33, 0) test_PCG64_binomial(139, 14, 0, 0) test_PCG64_binomial(147, 10, .5, np.array([9, 6, 6, 5, 6, 4, 3, 6, 5, 3]), 10) test_PCG64_binomial(457, np.array([12, 1, 4, 7, 8]), 0.11, np.array([1, 0, 0, 1, 0])) test_PCG64_binomial(457, 12, np.array([0.11, 0.21, 0.32, 0.43]), np.array([1, 4, 2, 6])) test_PCG64_binomial(457, np.array([12, 1, 4, 7, 8]), np.array([0.11, 0.21, 0.32, 0.43, 0.55]), np.array([1, 1, 0, 3, 5])) @test def test_PCG64_chisquare(seed, df, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(df, float) or isinstance(df, int)): assert gen.chisquare(df) == expected else: assert (round(gen.chisquare(df), 8) == expected).all() else: assert (round(gen.chisquare(df, size), 8) == expected).all() test_PCG64_chisquare(457, 12.12, 11.12088340114576) test_PCG64_chisquare(457, 24.12, np.array([22.97619518, 30.58538001]), 2) test_PCG64_chisquare( 457, np.array([23, 42, 34, 17]), np.array([21.86780618, 50.59339837, 22.36475303, 15.23606778])) test_PCG64_chisquare( 457, np.array([274.23, 325.42, 352.34, 825.17]), np.array([271.92587239, 349.58892133, 312.74784926, 816.55165763])) @test def test_PCG64_dirichlet(seed, alpha, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) assert (round(gen.dirichlet(alpha, size), 8) == round(expected, 8)).all() test_PCG64_dirichlet( 457, np.array([278.23, 325.42, 352.34, 825.17]), np.array([0.15699856, 0.19433008, 0.18390472, 0.46476664])) test_PCG64_dirichlet( 874, np.array([10, 5, 3]), np.array([[0.70264987, 0.16185327, 0.13549686], [0.35554736, 0.40690167, 0.23755097]]), 2) #test_PCG64_dirichlet(1234, np.array([]), np.array([])) test_PCG64_dirichlet(74, np.array([0.01, 0.05]), np.array([0.86854699, 0.13145301])) @test def test_PCG64_exponential(seed, scale, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(scale, float) or isinstance(scale, int)): assert gen.exponential(scale) == expected else: assert (round(gen.exponential(scale), 8) == expected).all() else: assert (round(gen.exponential(scale, size), 8) == expected).all() test_PCG64_exponential(74, 1, 1.693462457917779) test_PCG64_exponential(874, 3, 0.7277035588087964) test_PCG64_exponential(874, 724.952, 175.85005012185152) test_PCG64_exponential( 874, np.array([278.23, 325.42, 352.34, 825.17]), np.array([67.48965372, 681.9977866, 102.20548868, 71.49681695])) test_PCG64_exponential( 874, 724.952, np.array([ 175.85005012, 1519.31552882, 210.29140441, 62.81343292, 679.83990463, 351.19474068, 1802.19789426 ]), 7) @test def test_PCG64_f(seed, dfnum, dfden, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(dfnum, float) or isinstance(dfnum, int)) and (isinstance(dfden, float) or isinstance(dfden, int)): assert gen.f(dfnum, dfden) == expected else: assert (round(gen.f(dfnum, dfden), 8) == expected).all() else: assert (round(gen.f(dfnum, dfden, size), 8) == expected).all() test_PCG64_f(874, 12, 4.21, 3.428479552488479) test_PCG64_f( 874, np.array([14, 15, 16, 17, 18]), 4.21, np.array([3.34933794, 4.77314128, 0.96677047, 2.93878710, 0.50349151])) test_PCG64_f( 874, 2557, 0.92, np.array([14.97080143, 0.35262364, 1.69187013, 0.88598733, 41.64594068]), 5) test_PCG64_f(874, 7343, np.array([12.52, 0.92, 231.52]), np.array([1.53233839, 0.3528156, 0.94834774])) @test def test_PCG64_gamma(seed, shape, expected, scale=1.0, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(shape, float) or isinstance(shape, int)) and (isinstance(scale, float) or isinstance(scale, int)): assert gen.gamma(shape, scale) == expected else: assert (round(gen.gamma(shape, scale), 8) == expected).all() else: assert (round(gen.gamma(shape, scale, size), 8) == expected).all() test_PCG64_gamma(318, 564, 575.499699177782) test_PCG64_gamma(318, 564, 3165.2483454778007, 5.5) test_PCG64_gamma(318, 564, np.array([3165.24834548, 1172.04010906]), np.array([5.5, 2.2])) test_PCG64_gamma( 318, 564, np.array([2373.03560208, 2196.74145777, 2459.45823200, 2409.61200879]), 4.123435, 4) test_PCG64_gamma( 318, np.array([19, 17, 45, 52, 21]), np.array( [178.11061929, 100.74725160, 463.44439870, 495.50634389, 194.23053272]), 8.527) test_PCG64_gamma( 318, np.array([19, 17, 45, 52, 21]), np.array( [22.97662498, 51.98638525, 108.70045707, 441.63811581, 224.82178468]), np.array([1.1, 4.4, 2, 7.6, 9.87])) @test def test_PCG64_geometric(seed, p, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if isinstance(p, float) or isinstance(p, int): assert gen.geometric(p) == expected else: assert (gen.geometric(p) == expected).all() else: assert (gen.geometric(p, size) == expected).all() test_PCG64_geometric(457, 0.35, 2) test_PCG64_geometric(457, 0.2, 8) test_PCG64_geometric(2000, 1, 1) test_PCG64_geometric(12654, 0.5, np.array([2., 1., 2., 1.]), 4) test_PCG64_geometric(12654, np.array([0.01, 0.6, 0.45, 0.33]), np.array([93, 1, 4, 2])) @test def test_PCG64_gumbel(seed, expected, loc=0.0, scale=1.0, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(loc, float) or isinstance(loc, int)) and (isinstance( scale, float) or isinstance(scale, int)): assert gen.gumbel(loc, scale) == expected else: assert (round(gen.gumbel(loc, scale), 8) == expected).all() else: assert (round(gen.gumbel(loc, scale, size), 8) == expected).all() test_PCG64_gumbel(1234, -1.3242306166629008) test_PCG64_gumbel(1234, 10.6757693833371, 12) test_PCG64_gumbel(1234, -161.55613523287388, scale=122) test_PCG64_gumbel(1234, np.array([-1.32423062, 0.73740935, -0.94279743]), size=3) test_PCG64_gumbel(1234, np.array( [-0.52423062, 1.90740935, -0.81279743, 266.64272045]), loc=np.array([0.8, 1.17, 0.13, 265.45])) test_PCG64_gumbel(1234, np.array( [-15.62592128, 37.73323651, -56.69040968, 7.69304687]), scale=np.array([11.8, 51.17, 60.13, 6.45])) @test def test_PCG64_hypergeometric(seed, ngood, nbad, nsample, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(ngood, int) or isinstance(ngood, float)) and ( isinstance(nbad, int) or isinstance(nbad, float)) and ( isinstance(nsample, int) or isinstance(nsample, float)): assert gen.hypergeometric(ngood, nbad, nsample) == expected else: assert (gen.hypergeometric(ngood, nbad, nsample) == expected).all() else: assert (gen.hypergeometric(ngood, nbad, nsample, size) == expected).all() test_PCG64_hypergeometric(1234, 11, 12, 9, 4) test_PCG64_hypergeometric(1234, 100, 300, 200, 49) #test_PCG64_hypergeometric(1234, 100.31, 300.55, 200.2, 49) test_PCG64_hypergeometric(1234, 100, 300, np.array([200, 201, 222, 221]), np.array([49, 52, 62, 53])) test_PCG64_hypergeometric(1234, 100, np.array([301, 303, 304, 344, 355]), 200, np.array([49, 43, 52, 47, 41])) test_PCG64_hypergeometric(1234, np.array([100, 111, 112, 122]), 300, 200, np.array([49, 52, 48, 60])) test_PCG64_hypergeometric(1234, 100, 700, 450, np.array([57, 63, 58, 54, 54]), 5) @test def test_PCG64_laplace(seed, expected, loc=0.0, scale=1.0, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(loc, float) or isinstance(loc, int)) and (isinstance( scale, float) or isinstance(scale, int)): assert gen.laplace(loc, scale) == expected else: assert (round(gen.laplace(loc, scale), 8) == expected).all() else: assert (round(gen.laplace(loc, scale, size), 8) == expected).all() test_PCG64_laplace(1234, 3.0661447249453975) test_PCG64_laplace(1234, 15.066144724945397, 12) test_PCG64_laplace(1234, 374.0696564433385, scale=122) test_PCG64_laplace(1234, np.array([3.06614472, -0.27392189, 1.87400564]), size=3) test_PCG64_laplace(1234, np.array([3.86614472, 0.89607811, 2.00400564, 264.80256176]), loc=np.array([0.8, 1.17, 0.13, 265.45])) test_PCG64_laplace(1234, np.array( [36.18050775, -14.01658291, 112.68395923, -4.17597664]), scale=np.array([11.8, 51.17, 60.13, 6.45])) @test def test_PCG64_logistic(seed, expected, loc=0.0, scale=1.0, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(loc, float) or isinstance(loc, int)) and (isinstance( scale, float) or isinstance(scale, int)): assert gen.logistic(loc, scale) == expected else: assert (round(gen.logistic(loc, scale), 8) == expected).all() else: assert (round(gen.logistic(loc, scale, size), 8) == expected).all() test_PCG64_logistic(1234, 3.7357159301091363) test_PCG64_logistic(1234, 15.735715930109137, 12) test_PCG64_logistic(1234, 455.7573434733146, scale=122) test_PCG64_logistic(1234, np.array([3.73571593, -0.48871751, 2.48729352]), size=3) test_PCG64_logistic(1234, np.array( [4.53571593, 0.68128249, 2.61729352, 264.41280935]), loc=np.array([0.8, 1.17, 0.13, 265.45])) test_PCG64_logistic( 1234, np.array([44.08144798, -25.00767521, 149.56095922, -6.68987968]), scale=np.array([11.8, 51.17, 60.13, 6.45])) @test def test_PCG64_lognormal(seed, expected, mean=0.0, sigma=1.0, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(mean, float) or isinstance(mean, int)) and (isinstance( sigma, float) or isinstance(sigma, int)): assert gen.lognormal(mean, sigma) == expected else: assert (round(gen.lognormal(mean, sigma), 8) == expected).all() else: assert (round(gen.lognormal(mean, sigma, size), 8) == expected).all() test_PCG64_lognormal(1234, 0.20112336451311477) test_PCG64_lognormal(1234, 32733.791240820276, 12) test_PCG64_lognormal(1234, 0.04045060775307524, sigma=2) test_PCG64_lognormal(1234, np.array([0.20112336, 1.06619892, 2.09780445]), size=3) test_PCG64_lognormal(1234, np.array( [0.44760828, 3.43528508, 2.38903925, 271.13563493]), mean=np.array([0.8, 1.17, 0.13, 5.45])) test_PCG64_lognormal(1234, np.array( [0.05574842, 26.57557603, 1.10110681, 2.67618908]), sigma=np.array([1.8, 51.17, 0.13, 6.45])) @test def test_PCG64_logseries(seed, p, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if isinstance(p, float) or isinstance(p, int): assert gen.logseries(p) == expected else: assert (gen.logseries(p) == expected).all() else: assert (gen.logseries(p, size) == expected).all() test_PCG64_logseries(457, 0.35, 1) test_PCG64_logseries(2000, 0, 1) test_PCG64_logseries(457, 0.5, np.array([2., 3., 2., 1.]), 4) test_PCG64_logseries(457, np.array([0.01, 0.6, 0.45, 0.33]), np.array([1, 1, 3, 2])) @test def test_PCG64_multinomial(seed, n, pvals, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) assert (round(gen.multinomial(n, pvals, size), 8) == expected).all() test_PCG64_multinomial(457, 20, [1 / 6.], np.array([20])) test_PCG64_multinomial(457, 20.6, [1 / 6.], np.array([20])) test_PCG64_multinomial(457, 20, [1 / 6.] * 6, np.array([3, 5, 1, 4, 2, 5])) test_PCG64_multinomial( 457, 20, [1 / 6] * 6, np.array([[3, 5, 1, 4, 2, 5], [5, 4, 3, 6, 0, 2], [4, 2, 2, 3, 6, 3]]), 3) #test_PCG64_multinomial(457, 1, np.array([[.1, .5, .4 ], [.3, .7, .0]]), np.array([[0, 0, 1], [0, 1, 0]])) #test_PCG64_multinomial(457, -1, [1/6.], 0) @test def test_PCG64_multivariate_hypergeometric(seed, colors, nsample, expected, size=None, method='marginals'): gen = rnd.Generator(rnd.PCG64(seed)) assert (gen.multivariate_hypergeometric(colors, nsample, size, method) == expected).all() test_PCG64_multivariate_hypergeometric(457, np.array([16, 8, 4]), 15, np.array([8, 5, 2])) test_PCG64_multivariate_hypergeometric(457, np.array([16, 8, 4]), 15, np.array([[8, 5, 2], [9, 4, 2], [8, 5, 2]]), size=3) test_PCG64_multivariate_hypergeometric(457, np.array([16, 8, 4]), 0, np.array([0, 0, 0])) test_PCG64_multivariate_hypergeometric(457, np.array([16, 8, 4]), 8, np.array([4, 3, 1]), method='count') @test def test_PCG64_multivariate_normal(seed, mean, cov, expected, size=None, check_valid: Static[str] = 'warn', tol: float = 1e-8, m: Static[str] = 'svd'): gen = rnd.Generator(rnd.PCG64(seed)) assert (round( gen.multivariate_normal(mean, cov, size, check_valid=check_valid, tol=tol, method=m), 8) == expected).all() test_PCG64_multivariate_normal(1234, (1, 2), np.array([[1, 0], [0, 1]]), np.array([-0.60383681, 2.06409991])) test_PCG64_multivariate_normal(5432, (1, 2), np.array([[1, 0], [0, 1]]), np.array([1.46547576, 1.68314218]), m='cholesky') @test def test_PCG64_negative_binomial(seed, n, p, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(n, int) or isinstance(n, float)) and (isinstance( p, int) or isinstance(p, float)): assert gen.negative_binomial(n, p) == expected else: assert (gen.negative_binomial(n, p) == expected).all() else: assert (gen.negative_binomial(n, p, size) == expected).all() test_PCG64_negative_binomial(139, 28400, .66, 14407) test_PCG64_negative_binomial(139, 14.76, .33, 17) #test_PCG64_negative_binomial(139, 14, 0, error) test_PCG64_negative_binomial(147, 10, .5, np.array([6, 1, 7, 14, 6, 8, 10, 5, 8, 12]), 10) test_PCG64_negative_binomial(457, np.array([12, 1, 4, 7, 8]), 0.11, np.array([75, 4, 8, 40, 64])) test_PCG64_negative_binomial(457, 12, np.array([0.11, 0.21, 0.32, 0.43]), np.array([[75, 30, 19, 28]])) @test def test_PCG64_noncentral_chisquare(seed, df, nonc, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(df, int) or isinstance(df, float)) and (isinstance( nonc, int) or isinstance(nonc, float)): assert gen.noncentral_chisquare(df, nonc) == expected else: assert (round(gen.noncentral_chisquare(df, nonc), 8) == expected).all() else: assert (round(gen.noncentral_chisquare(df, nonc, size), 8) == expected).all() test_PCG64_noncentral_chisquare(457, 0.1, 0.2, 0.061552060427800606) test_PCG64_noncentral_chisquare(457, 5, 0, 4.130095429396157) test_PCG64_noncentral_chisquare(457, 99, 7, 109.29213518232945) test_PCG64_noncentral_chisquare( 457, 14.2, 0.5, np.array([14.93361759, 16.34617163, 11.73437051]), 3) test_PCG64_noncentral_chisquare(457, np.array([8, 7.1, 45.3]), 0.6, np.array([9.06347808, 8.17895956, 41.9335875])) test_PCG64_noncentral_chisquare( 457, 0.6, np.array([8, 7.1, 45.3]), np.array([2.07706000, 16.39779665, 54.01862096])) @test def test_PCG64_noncentral_f(seed, dfnum, dfden, nonc, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(dfnum, float) or isinstance(dfnum, int)) and ( isinstance(dfden, int) or isinstance(dfden, float)) and (isinstance(nonc, int) or isinstance(nonc, float)): assert gen.noncentral_f(dfnum, dfden, nonc) == expected else: assert (round(gen.noncentral_f(dfnum, dfden, nonc), 8) == expected).all() else: assert (round(gen.noncentral_f(dfnum, dfden, nonc, size), 8) == expected).all() test_PCG64_noncentral_f(874, 3, 20, 3, 0.9479155644253658) test_PCG64_noncentral_f(874, 3, 20, 0, 2.563595388305448) test_PCG64_noncentral_f( 874, np.array([14, 15, 16, 17, 18]), 4.21, 6.7, np.array([1.41231957, 1.18112963, 2.53826028, 1.35162988, 4.92394815])) test_PCG64_noncentral_f( 874, 27, 5.92, 3.1, np.array([1.16488560, 0.84874875, 1.91535224, 1.22666518, 2.94041668]), 5) test_PCG64_noncentral_f( 874, 27, np.array([5.92, 8.13, 9.53, 33.14]), 3.1, np.array([1.16488560, 0.86567470, 1.67032973, 1.38249851])) test_PCG64_noncentral_f( 874, 743, 8.24, np.array([0.11, 0.21, 0.32, 0.43]), np.array([0.95109146, 0.79144400, 1.53122749, 0.87951980])) @test def test_PCG64_normal(seed, expected, loc=0.0, scale=1.0, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(loc, float) or isinstance(loc, int)) and (isinstance( scale, float) or isinstance(scale, int)): assert gen.normal(loc, scale) == expected else: assert (round(gen.normal(loc, scale), 8) == expected).all() else: assert (round(gen.normal(loc, scale, size), 8) == expected).all() test_PCG64_normal(1234, -1.6038368053963015) test_PCG64_normal(1234, 10.396163194603698, 12) test_PCG64_normal(1234, -195.66809025834877, scale=122) test_PCG64_normal(1234, np.array([-1.60383681, 0.06409991, 0.74089130]), size=3) test_PCG64_normal(1234, np.array([-0.80383681, 1.23409991, 0.87089130, 265.60261919]), loc=np.array([0.8, 1.17, 0.13, 265.45])) test_PCG64_normal(1234, np.array([-18.92527430, 3.27999260, 44.54979362, 0.98439380]), scale=np.array([11.8, 51.17, 60.13, 6.45])) @test def test_PCG64_pareto(seed, a, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if isinstance(a, float) or isinstance(a, int): assert gen.pareto(a) == expected else: assert (round(gen.pareto(a), 8) == expected).all() else: assert (round(gen.pareto(a, size), 8) == expected).all() test_PCG64_pareto(1234, 3, 0.66181450621784) test_PCG64_pareto( 1234, 5, np.array([0.35628053, 0.15364923, 0.43703957, 0.17654679, 0.21708714]), 5) test_PCG64_pareto( 1234, np.array([3, 13, 4, 23.2, 5.6]), np.array([0.66181451, 0.05651224, 0.57338827, 0.03566071, 0.19173602])) @test def test_PCG64_poisson(seed, expected, lam=1.0, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if isinstance(lam, float) or isinstance(lam, int): assert gen.poisson(lam) == expected else: assert (round(gen.poisson(lam), 8) == expected).all() else: assert (round(gen.poisson(lam, size), 8) == expected).all() test_PCG64_poisson(1234, 0, 0) test_PCG64_poisson(1234, 2) test_PCG64_poisson(1234, 4, 3) test_PCG64_poisson(1234, 21, 14.65) test_PCG64_poisson(1234, np.array([46., 11., 8., 78., 18.]), np.array([35.62, 9.23, 9.57, 76.79, 21.74])) test_PCG64_poisson(1234, np.array([875., 809., 801., 904., 819.]), 824.14, 5) @test def test_PCG64_power(seed, a, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if isinstance(a, float) or isinstance(a, int): assert np.isclose(gen.power(a), expected) else: assert (round(gen.power(a), 8) == expected).all() else: assert (round(gen.power(a, size), 8) == expected).all() test_PCG64_power(1234, 1, 0.7821024420483678) test_PCG64_power(1234, 45.11, 0.9945665870769975) test_PCG64_power(1234, 6, np.array([0.95986600, 0.89402992, 0.97074617]), 3) test_PCG64_power( 1234, np.array([5.4, 1.1, 78, 19.34, 99999999999999]), np.array( array([0.95550730, 0.54280964, 0.99771874, 0.97014457, 1.00000000]))) @test def test_PCG64_rayleigh(seed, expected, scale=1.0, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if isinstance(scale, float) or isinstance(scale, int): assert gen.rayleigh(scale) == expected else: assert (round(gen.rayleigh(scale), 8) == expected).all() else: assert (round(gen.rayleigh(scale, size), 8) == expected).all() #test_PCG64_rayleigh(1234, error, -1) test_PCG64_rayleigh(1234, 1.7456977082484888) test_PCG64_rayleigh(1234, 5.237093124745466, 3) test_PCG64_rayleigh(1234, 25.57447142584036, 14.65) test_PCG64_rayleigh(1234, np.array([1.74569771, 1.19553403, 1.90416686, 1.27508312]), size=4) test_PCG64_rayleigh( 1234, np.array([9.42676762, 1.31508743, 148.52501510, 24.66010757, 78.77235752]), np.array([5.4, 1.1, 78, 19.34, 56.2])) @test def test_PCG64_standard_cauchy(seed, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: assert gen.standard_cauchy() == expected else: assert (round(gen.standard_cauchy(size), 8) == round(expected, 8)).all() test_PCG64_standard_cauchy(1234, -25.020888566279826) test_PCG64_standard_cauchy( 1234, np.array([-25.02088857, 4.85450931, 0.29650342, -1.56410960]), 4) @test def test_PCG64_standard_exponential(seed, expected, size=None, m='zig'): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: assert gen.standard_exponential(method=m) == expected else: assert (round(gen.standard_exponential(size, method=m), 8) == expected).all() test_PCG64_standard_exponential(1234, 1.5237302442920129) test_PCG64_standard_exponential( 1234, np.array([1.52373024, 0.71465080, 1.81292572, 0.81291848]), 4) test_PCG64_standard_exponential(1234, 3.75929190550534, m='inv') @test def test_PCG64_standard_gamma(seed, shape, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if isinstance(shape, float) or isinstance(shape, int): assert gen.standard_gamma(shape) == expected else: assert (round(gen.standard_gamma(shape), 8) == expected).all() else: assert (round(gen.standard_gamma(shape, size), 8) == expected).all() test_PCG64_standard_gamma(318, 1, 1.5074447843195276) test_PCG64_standard_gamma(1234, 0, 0) test_PCG64_standard_gamma(1234, 0.5, 2.0649771071013165) test_PCG64_standard_gamma(1234, 3, 0.8114738755097568) test_PCG64_standard_gamma( 1234, 0.5, np.array([2.06497711, 0.10182293, 0.05845094, 3.30020422]), 4) test_PCG64_standard_gamma( 1234, np.array([4.5, 2, 7.7, 81.15]), np.array([1.67542406, 2.81779395, 9.96848401, 68.23797589])) @test def test_PCG64_standard_normal(seed, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: assert gen.standard_normal(size) == expected else: assert (round(gen.standard_normal(size), 8) == expected).all() test_PCG64_standard_normal(1234, -1.6038368053963015) test_PCG64_standard_normal(1234, np.array([-1.60383681, 0.06409991, 0.74089130]), 3) @test def test_PCG64_standard_t(seed, df, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if isinstance(df, float) or isinstance(df, int): assert gen.standard_t(df) == expected else: assert (round(gen.standard_t(df), 8) == expected).all() else: assert (round(gen.standard_t(df, size), 8) == expected).all() test_PCG64_standard_t(1234, 3, -1.7659223883243176) test_PCG64_standard_t(1234, 1, -2.982894800105467) test_PCG64_standard_t(1234, 0.5, -5.547734880855075) test_PCG64_standard_t(1234, 0.5, np.array([-5.54773488, 0.74943429, -7.28743863]), 3) test_PCG64_standard_t(1234, np.array([99, 5.6, 11.43]), np.array([-1.60193665, 0.12632228, -1.25887551])) @test def test_PCG64_triangular(seed, left, mode, right, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(left, int) or isinstance(left, float)) and (isinstance( mode, int) or isinstance(mode, float)) and (isinstance( right, int) or isinstance(right, float)): assert gen.triangular(left, mode, right) == expected else: assert (round(gen.triangular(left, mode, right), 8) == expected).all() else: assert (round(gen.triangular(left, mode, right, size), 8) == expected).all() test_PCG64_triangular(1234, -3, 0, 8, 6.56807104556005) test_PCG64_triangular(1234, np.array([-1, -4.2, -3.2]), -0.2, 77, np.array([65.15497215, 14.66758622, 55.20054270])) test_PCG64_triangular( 1234, -4, np.array([0.1, 0.5, 3, 6, 7.9]), 8, np.array([6.51377589, 0.53123947, 5.85402098, 1.60384608, 2.75033776])) test_PCG64_triangular(1234, -77, 0, np.array([0.1, 11, 789]), np.array([-0.85294815, -26.24365753, 559.99377111])) test_PCG64_triangular( 1234, 2, 10, 53, np.array([45.85175465, 16.13225321, 40.02614131, 12.76185250]), size=4) @test def test_PCG64_uniform(seed, expected, low=0.0, high=1.0, size=None): gen = rnd.Generator(rnd.PCG64(seed)) result = round(gen.uniform(low, high, size), 8) if size is None: if (isinstance(low, int) or isinstance(low, float)) and (isinstance( high, int) or isinstance(high, float)): assert result == round(expected, 8) else: assert (result == expected).all() else: assert (result == expected).all() test_PCG64_uniform(1234, 14.766997666981421, 5, 15) test_PCG64_uniform(1234, 0.9790297900283279, 0.1) test_PCG64_uniform(1234, 119.15737153717335, high=122) test_PCG64_uniform(1234, np.array([0.97669977, 0.38019574, 0.92324623]), size=3) test_PCG64_uniform(1234, np.array( [43.96080959, 18.96822087, 42.00660312, 16.94431211]), low=np.array([0.4, 3., 6., 7.]), high=45.) test_PCG64_uniform( 1234, np.array([54.69518694, 6.08313176, 40.62283429, 0.81124651, 0.06381941]), high=np.array([56., 16., 44., 3.1, 0.2])) @test def test_PCG64_vonmises(seed, mu, kappa, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(mu, float) or isinstance(mu, int)) and (isinstance( kappa, float) or isinstance(kappa, int)): assert np.isclose(gen.vonmises(mu, kappa), expected) else: assert (round(gen.vonmises(mu, kappa), 8) == expected).all() else: assert (round(gen.vonmises(mu, kappa, size), 8) == expected).all() test_PCG64_vonmises(1234, 0, 4, -0.27173852171597135) test_PCG64_vonmises(1234, 0.1, 0.2, -3.130535859602788) test_PCG64_vonmises(1234, -1, 0, 2.9951929700537034) test_PCG64_vonmises(1234, 0, 5, np.array([-0.24351687, 0.19570655, 0.75861058]), size=3) test_PCG64_vonmises( 1234, np.array([43.09, 18.62, 42, 16.94]), 5, np.array([-1.13581402, -0.03384937, -1.22368657, -1.74692310])) test_PCG64_vonmises( 1234, 4, np.array([0, 0.1, 7.67, 99]), np.array([2.99519297, 2.89617923, -2.48027841, -2.23901495])) @test def test_PCG64_wald(seed, mean, scale, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(mean, float) or isinstance(mean, int)) and (isinstance( scale, float) or isinstance(scale, int)): assert gen.wald(mean, scale) == expected else: assert (round(gen.wald(mean, scale), 8) == expected).all() else: assert (round(gen.wald(mean, scale, size), 8) == expected).all() test_PCG64_wald(1234, 0.1, 0.1, 0.023030951620822665) test_PCG64_wald(1234, 3, 2, 0.527940495568358) test_PCG64_wald(1234, 3, 2, np.array([0.52794050, 1.24578624, 1.08842697]), 3) test_PCG64_wald(1234, np.array([0.1, 0.5, 1, 4]), 0.5, np.array([0.04952415, 0.24218309, 0.31472446, 0.20571985])) test_PCG64_wald(1234, 0.5, np.array([0.1, 0.5, 1, 4]), np.array([0.03379779, 0.24218309, 0.27395511, 0.29813439])) test_PCG64_wald(1234, np.array([0.1, 0.5, 1, 4]), np.array([3, 2, 1, 8]), np.array([0.07469306, 0.34593420, 0.43217476, 1.46696504])) @test def test_PCG64_weibull(seed, a, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(a, float) or isinstance(a, int)): assert gen.weibull(a) == expected else: assert (round(gen.weibull(a), 8) == expected).all() else: assert (round(gen.weibull(a, size), 8) == expected).all() test_PCG64_weibull(1234, 0, 0) test_PCG64_weibull(1234, 0.1, 67.46536569583394) test_PCG64_weibull(1234, 1, 1.5237302442920129) test_PCG64_weibull(1234, 1, np.array([1.52373024, 0.71465080, 1.81292572]), 3) test_PCG64_weibull(1234, np.array([17.8, 4.32]), np.array([1.02394289, 0.92517830])) @test def test_PCG64_zipf(seed, a, expected, size=None): gen = rnd.Generator(rnd.PCG64(seed)) if size is None: if (isinstance(a, float) or isinstance(a, int)): assert gen.zipf(a) == expected else: assert (gen.zipf(a) == expected).all() else: assert (gen.zipf(a, size) == expected).all() test_PCG64_zipf(1234, 1.1, 21202999555633256) test_PCG64_zipf(1234, 3, 6) test_PCG64_zipf(1234, 45, np.array([1, 1, 1]), 3) test_PCG64_zipf(1234, np.array([17.8, 4.32]), np.array([1, 2]))