import numpy.random as rnd from numpy import * import numpy as np @test def test_Philox_integers(seed, low, expected, high=None, size=None, e=False): gen = rnd.Generator(rnd.Philox(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_Philox_integers(74, 5, 0) test_Philox_integers(74, 987.4, 105) test_Philox_integers(74, 98, 193, high=987) test_Philox_integers(74, 89, 9, e=True) test_Philox_integers(74, -1218, -1077, high=98) test_Philox_integers(74, -5, np.array([1, 19, 13]), 55, size=3) test_Philox_integers(74, -5, np.array([1, 19, 14]), 55, size=3, e=True) test_Philox_integers(74, np.array([7, 49, 17]), np.array([14, 60, 36]), 78) test_Philox_integers(74, -99, np.array([-81, -23, -36]), np.array([77, 89, 101])) test_Philox_integers(74, np.array([7, 49, 17]), np.array([14, 65, 43]), np.array([77, 89, 101])) @test def test_Philox_random(seed, expected, size=None): gen = rnd.Generator(rnd.Philox(seed)) if size is None: assert gen.random() == expected else: assert (round(gen.random(size), 8) == round(expected, 8)).all() test_Philox_random(0, 0.014067035665647709) test_Philox_random(1, 0.0668020093396563) test_Philox_random(1234, 0.5572569371365311) test_Philox_random( 1234, np.array([0.55725694, 0.22373624, 0.29333458, 0.57975576, 0.81181516]), size=5) test_Philox_random(74, np.array([[0.40856838, 0.47485863, 0.99389396], [0.15559785, 0.87641347, 0.49119767]]), size=(2, 3)) @test def test_Philox_choice(seed, a, expected, size=None, r=True, p=None, axis=0, shuffle=True): gen = rnd.Generator(rnd.Philox(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_Philox_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([7.99, 5.55, 11.33]), 3) test_Philox_choice( 318, np.array([5, 4, 2, 6, 7, 8, 2, 12, 1, 55, 33, 7, 78, 15, 43]), 43) test_Philox_choice(318, np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), np.array([6, 10, 12]), 3, False) test_Philox_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 ]), -8.31) test_Philox_choice(318, np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]), np.array([[10, 11, 12], [7, 8, 9]]), 2) test_Philox_choice(74, np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]), np.array([1, 2, 3])) test_Philox_choice(74, 1, 0) test_Philox_choice(74, np.array([13, -4]), -4, p=np.array([0.3, 0.7])) test_Philox_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_Philox_choice(74, np.array([13, -4, 3, 18]), 13, p=np.array([0.5, 0.3, 0.1, 0.1]), shuffle=True) @test def test_Philox_bytes(seed, length, expected): gen = rnd.Generator(rnd.Philox(seed)) check = gen.bytes(length) == expected assert check test_Philox_bytes(555, 10, "\x86\xb5\xa3\xf8\xa9d\xdb\xa0,\xd2") @test def test_Philox_shuffle(seed, x, expected, axis=0): gen = rnd.Generator(rnd.Philox(seed)) gen.shuffle(x, axis) assert (x == expected).all() test_Philox_shuffle(876, np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), np.array([2, 8, 9, 0, 3, 4, 7, 1, 6, 5])) test_Philox_shuffle(111, np.array([5.43, 6.56, 1.22, 4.3221, 7.88, 0.9352]), np.array([7.88, 1.22, 6.56, 0.9352, 4.3221, 5.43])) test_Philox_shuffle(1234, np.array([3.14]), np.array([3.14])) test_Philox_shuffle(74, np.arange(9).reshape((3, 3)), np.array([[3, 4, 5], [6, 7, 8], [0, 1, 2]])) test_Philox_shuffle(74, np.arange(9).reshape((3, 3)), np.array([[1, 2, 0], [4, 5, 3], [7, 8, 6]]), axis=1) @test def test_Philox_permutation(seed, x, expected, axis=0): gen = rnd.Generator(rnd.Philox(seed)) assert (gen.permutation(x, axis) == expected).all() test_Philox_permutation(12345, 10, np.array([8, 9, 6, 4, 3, 2, 7, 1, 5, 0])) test_Philox_permutation(1234, np.array([1.124, 4.7532, 9.1246, 12.53243, 15.64324]), np.array([12.53243, 15.64324, 9.1246, 1.124, 4.7532])) test_Philox_permutation( 4321, np.arange(24).reshape(3, 8), np.array([[8, 9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22, 23], [0, 1, 2, 3, 4, 5, 6, 7]])) test_Philox_permutation(74, np.arange(9).reshape((3, 3)), np.array([[1, 2, 0], [4, 5, 3], [7, 8, 6]]), axis=1) @test def test_Philox_permuted(seed, x, expected, axis=None): gen = rnd.Generator(rnd.Philox(seed)) arr = gen.permuted(x, axis) assert (arr == expected).all() test_Philox_permuted(4321, np.array([1.124, 4.7532, 9.1246, 12.53243, 15.64324]), np.array([15.64324, 4.7532, 9.1246, 1.124, 12.53243])) test_Philox_permuted( 4321, np.arange(24).reshape(3, 8), np.array([[14, 21, 10, 17, 16, 12, 19, 5], [13, 20, 6, 0, 7, 15, 4, 9], [18, 22, 1, 23, 3, 2, 8, 11]])) @test def test_Philox_beta(seed, a, b, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_beta(4321, -7, 0, error) test_Philox_beta(4321, 0.2, 0.1, 0.0001674971842261576) test_Philox_beta(4321, 10, 14, 0.3991628907366655) test_Philox_beta(4321, 167, 2041, np.array([0.07344472, 0.08315303, 0.08115929, 0.07195913]), 4) test_Philox_beta(139, 14.32, 4, 0.828761259380857) test_Philox_beta(457, 12.87, 9.21, 0.53629054859836) test_Philox_beta( 457, np.array([12.87, 1.32, 4.532, 1.34, 8.432]), 9.21, np.array([0.53629055, 0.31970199, 0.61013405, 0.06910402, 0.58929108])) test_Philox_beta( 457, 32.14, np.array([9.21, 0.21, 14.32, 41.21, 5.55]), np.array([0.78367830, 0.99976162, 0.83007856, 0.44624419, 0.89121140])) test_Philox_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.53629055, 0.99558555, 0.45404014, 0.01310910, 0.71423699])) @test def test_Philox_binomial(seed, n, p, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_binomial(139, -2, .33, error) test_Philox_binomial(139, 28400, .66, 18735) test_Philox_binomial(139, 14.76, .33, 8) test_Philox_binomial(139, 0, .33, 0) test_Philox_binomial(139, 14, 0, 0) test_Philox_binomial(147, 10, .5, np.array([5, 4, 5, 4, 3, 7, 7, 4, 2, 4]), 10) test_Philox_binomial(457, np.array([12, 1, 4, 7, 8]), 0.11, np.array([2, 0, 0, 0, 1])) test_Philox_binomial(457, 12, np.array([0.11, 0.21, 0.32, 0.43]), np.array([2, 1, 3, 4])) test_Philox_binomial(457, np.array([12, 1, 4, 7, 8]), np.array([0.11, 0.21, 0.32, 0.43, 0.55]), np.array([2, 0, 1, 2, 4])) @test def test_Philox_chisquare(seed, df, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_chisquare(457, 12.12, 4.987326814746572) test_Philox_chisquare(457, 24.12, np.array([13.45189670, 17.54542500]), 2) test_Philox_chisquare( 457, np.array([23, 42, 34, 17]), np.array([12.61672185, 33.30496035, 39.938353210, 7.36364561])) test_Philox_chisquare( 457, np.array([274.23, 325.42, 352.34, 825.17]), np.array([234.89812766, 301.20489918, 372.23635244, 745.94706704])) @test def test_Philox_dirichlet(seed, alpha, expected, size=None): gen = rnd.Generator(rnd.Philox(seed)) assert (round(gen.dirichlet(alpha, size), 8) == round(expected, 8)).all() test_Philox_dirichlet( 457, np.array([278.23, 325.42, 352.34, 825.17]), np.array([0.14758409, 0.18205838, 0.21640768, 0.45394985])) test_Philox_dirichlet( 874, np.array([10, 5, 3]), np.array([[0.63748511, 0.22927703, 0.13323785], [0.38843058, 0.41643801, 0.19513141]]), 2) #test_Philox_dirichlet(1234, np.array([]), np.array([])) test_Philox_dirichlet(74, np.array([0.01, 0.05]), np.array([3.93720652e-33, 1.00000000])) @test def test_Philox_exponential(seed, scale, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_exponential(74, 1, 0.677350334467786) test_Philox_exponential(874, 3, 2.0459069098380795) test_Philox_exponential(874, 724.952, 494.39476870031183) test_Philox_exponential( 874, np.array([278.23, 325.42, 352.34, 825.17]), np.array([189.74422651, 10.21851605, 301.34973289, 110.59639221])) test_Philox_exponential( 874, 724.952, np.array([ 494.39476870, 22.76422361, 620.03772368, 97.16431247, 1148.46168532, 1852.86020050, 2203.97929230 ]), 7) @test def test_Philox_f(seed, dfnum, dfden, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_f(874, 12, 4.21, 1.5606440016521452) test_Philox_f( 874, np.array([14, 15, 16, 17, 18]), 4.21, np.array([1.51159613, 2.12468474, 1.13710348, 2.75465007, 2.48772155])) test_Philox_f( 874, 2557, 0.92, np.array([0.640902440, 1.79388925, 18.24367928, 20.97090336, 14.06117768]), 5) test_Philox_f(874, 7343, np.array([12.52, 0.92, 231.52]), np.array([0.95066689, 1.78861180, 0.96449548])) @test def test_Philox_gamma(seed, shape, expected, scale=1.0, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_gamma(318, 564, 569.4970306954932) test_Philox_gamma(318, 564, 3132.2336688252126, 5.5) test_Philox_gamma(318, 564, np.array([3132.23366883, 1304.85485375]), np.array([5.5, 2.2])) test_Philox_gamma( 318, 564, np.array([2348.28398877, 2445.67462449, 2219.17838471, 2465.85102355]), 4.123435, 4) test_Philox_gamma( 318, np.array([19, 17, 45, 52, 21]), np.array( [168.35816137, 188.93243525, 322.08095866, 533.31906573, 175.15726538]), 8.527) test_Philox_gamma( 318, np.array([19, 17, 45, 52, 21]), np.array( [21.71853847, 97.49064326, 75.54379234, 475.34008438, 202.74448332]), np.array([1.1, 4.4, 2, 7.6, 9.87])) @test def test_Philox_geometric(seed, p, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_geometric(457, 0.35, 3) test_Philox_geometric(457, 0.2, 6) test_Philox_geometric(2000, 1, 1) test_Philox_geometric(12654, 0.5, np.array([1., 1., 1., 1.]), 4) test_Philox_geometric(12654, np.array([0.01, 0.6, 0.45, 0.33]), np.array([102, 1, 2, 2])) @test def test_Philox_gumbel(seed, expected, loc=0.0, scale=1.0, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_gumbel(1234, 0.20485472765439966) test_Philox_gumbel(1234, 12.2048547276544, 12) test_Philox_gumbel(1234, 24.992276773836757, scale=122) test_Philox_gumbel(1234, np.array([0.20485473, 1.37332713, 1.05786017]), size=3) test_Philox_gumbel(1234, np.array([1.00485473, 2.54332713, 1.18786017, 265.59280948]), loc=np.array([0.8, 1.17, 0.13, 265.45])) test_Philox_gumbel(1234, np.array([2.41728579, 70.27314942, 63.60913187, 0.92112117]), scale=np.array([11.8, 51.17, 60.13, 6.45])) @test def test_Philox_hypergeometric(seed, ngood, nbad, nsample, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_hypergeometric(1234, 11, 12, 9, 4) test_Philox_hypergeometric(1234, 100, 300, 200, 46) #test_Philox_hypergeometric(1234, 100.31, 300.55, 200.2, 46) test_Philox_hypergeometric(1234, 100, 300, np.array([200, 201, 222, 221]), np.array([46, 48, 54, 46])) test_Philox_hypergeometric(1234, 100, np.array([301, 303, 304, 344, 355]), 200, np.array([46, 52, 51, 55, 47])) test_Philox_hypergeometric(1234, np.array([100, 111, 112, 122]), 300, 200, np.array([46, 56, 56, 68])) test_Philox_hypergeometric(1234, 100, 700, 450, np.array([61, 54, 54, 46, 64]), 5) @test def test_Philox_laplace(seed, expected, loc=0.0, scale=1.0, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_laplace(1234, 0.12161849017455835) test_Philox_laplace(1234, 12.121618490174559, 12) test_Philox_laplace(1234, 14.83745580129612, scale=122) test_Philox_laplace(1234, np.array([0.12161849, -0.80414025, -0.53329424]), size=3) test_Philox_laplace(1234, np.array( [0.92161849, 0.36585975, -0.40329424, 265.62377203]), loc=np.array([0.8, 1.17, 0.13, 265.45])) test_Philox_laplace(1234, np.array( [1.43509818, -41.14785663, -32.06698241, 1.12082962]), scale=np.array([11.8, 51.17, 60.13, 6.45])) @test def test_Philox_logistic(seed, expected, loc=0.0, scale=1.0, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_logistic(1234, 0.23003681281754018) test_Philox_logistic(1234, 12.23003681281754, 12) test_Philox_logistic(1234, 28.064491163739902, scale=122) test_Philox_logistic(1234, np.array([0.23003681, -1.24402451, -0.87924346]), size=3) test_Philox_logistic(1234, np.array( [1.03003681, -0.07402451, -0.74924346, 25.77177085]), loc=np.array([0.8, 1.17, 0.13, 25.45])) test_Philox_logistic(1234, np.array( [2.71443439, -63.65673441, -52.86890896, 2.07542198]), scale=np.array([11.8, 51.17, 60.13, 6.45])) @test def test_Philox_lognormal(seed, expected, mean=0.0, sigma=1.0, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_lognormal(1234, 0.46906380361126687) test_Philox_lognormal(1234, 76342.3815189564, 12) test_Philox_lognormal(1234, 0.22002085185826914, sigma=2) test_Philox_lognormal(1234, np.array([0.4690638, 5.02772598, 1.96860722]), size=3) test_Philox_lognormal(1234, np.array( [1.04392069, 16.19929610, 2.24190578, 668.12967098]), mean=np.array([0.8, 1.17, 0.13, 5.45])) test_Philox_lognormal(1234, np.array( [0.25598673, 33.26414553, 1.69607119, 4.61355770]), sigma=np.array([1.8, 2.17, 0.78, 1.45])) @test def test_Philox_logseries(seed, p, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_logseries(457, 0.35, 1) test_Philox_logseries(2000, 0, 1) test_Philox_logseries(457, 0.5, np.array([1., 2., 2., 2.]), 4) test_Philox_logseries(457, np.array([0.01, 0.6, 0.45, 0.33]), np.array([1, 2, 1, 1])) @test def test_Philox_multinomial(seed, n, pvals, expected, size=None): gen = rnd.Generator(rnd.Philox(seed)) assert (round(gen.multinomial(n, pvals, size), 8) == expected).all() test_Philox_multinomial(457, 20, [1 / 6.], np.array([20])) test_Philox_multinomial(457, 20.6, [1 / 6.], np.array([20])) test_Philox_multinomial(457, 20, [1 / 6.] * 6, np.array([4, 1, 3, 3, 5, 4])) test_Philox_multinomial( 457, 20, [1 / 6] * 6, np.array([[4, 1, 3, 3, 5, 4], [2, 3, 2, 8, 2, 3], [2, 5, 1, 5, 2, 5]]), 3) #test_Philox_multinomial(457, 1, np.array([[.1, .5, .4 ], [.3, .7, .0]]), np.array([[0, 1, 0], [0, 1, 0]])) #test_Philox_multinomial(457, -1, [1/6.], error) @test def test_Philox_multivariate_hypergeometric(seed, colors, nsample, expected, size=None, method='marginals'): gen = rnd.Generator(rnd.Philox(seed)) assert (gen.multivariate_hypergeometric(colors, nsample, size, method) == expected).all() test_Philox_multivariate_hypergeometric(457, np.array([16, 8, 4]), 15, np.array([7, 4, 4])) test_Philox_multivariate_hypergeometric(457, np.array([16, 8, 4]), 15, np.array([[7, 4, 4], [6, 7, 2], [6, 6, 3]]), size=3) test_Philox_multivariate_hypergeometric(457, np.array([16, 8, 4]), 0, np.array([0, 0, 0])) test_Philox_multivariate_hypergeometric(457, np.array([16, 8, 4]), 8, np.array([6, 1, 1]), method='count') @test def test_Philox_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.Philox(seed)) assert (round( gen.multivariate_normal(mean, cov, size, check_valid=check_valid, tol=tol, method=m), 8) == expected).all() test_Philox_multivariate_normal(1234, (1, 2), np.array([[1, 0], [0, 1]]), np.array([0.24298352, 3.61496779])) test_Philox_multivariate_normal(5432, (1, 2), np.array([[1, 0], [0, 1]]), np.array([1.31546928, 1.83957609]), m='cholesky') @test def test_Philox_negative_binomial(seed, n, p, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_negative_binomial(139, 28400, .66, 14627) test_Philox_negative_binomial(139, 14.76, .33, 27) #test_Philox_negative_binomial(139, 14, 0, error) test_Philox_negative_binomial(147, 10, .5, np.array([6, 10, 21]), 3) test_Philox_negative_binomial(457, np.array([12, 1, 4, 7, 8]), 0.11, np.array([51, 10, 23, 42, 65])) test_Philox_negative_binomial(457, 12, np.array([0.11, 0.21, 0.32, 0.43]), np.array([[51, 51, 27, 9]])) @test def test_Philox_noncentral_chisquare(seed, df, nonc, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_noncentral_chisquare(457, 0.1, 0.2, 1.3412155895288272e-19) test_Philox_noncentral_chisquare(457, 5, 0, 0.9667491310888645) test_Philox_noncentral_chisquare(457, 99, 7, 77.93117603431178) test_Philox_noncentral_chisquare( 457, 14.2, 0.5, np.array([5.74888694, 17.17099047, 7.53364203]), 3) test_Philox_noncentral_chisquare( 457, np.array([8, 7.1, 45.3]), 0.6, np.array([1.97336093, 9.18958927, 30.29737961])) test_Philox_noncentral_chisquare( 457, 0.6, np.array([8, 7.1, 45.3]), np.array([8.95858437, 1.28791705, 46.52231840])) @test def test_Philox_noncentral_f(seed, dfnum, dfden, nonc, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_noncentral_f(874, 3, 20, 3, 2.792477829917526) test_Philox_noncentral_f(874, 3, 20, 0, 2.2362415189878746) test_Philox_noncentral_f( 874, np.array([14, 15, 16, 17, 18]), 4.21, 6.7, np.array([1.04484935, 1.21683455, 1.13983240, 3.66570463, 0.57133496])) test_Philox_noncentral_f( 874, 27, 5.92, 3.1, np.array([0.82984208, 1.01215833, 0.94357663, 2.19740092, 0.48883215]), 5) test_Philox_noncentral_f( 874, 27, np.array([5.92, 8.13, 9.53, 33.14]), 3.1, np.array([0.82984208, 1.09159907, 0.97830503, 1.43588432])) test_Philox_noncentral_f( 874, 743, 8.24, np.array([0.11, 0.21, 0.32, 0.43]), np.array([0.62498462, 0.65443537, 0.81711437, 1.64557267])) @test def test_Philox_normal(seed, expected, loc=0.0, scale=1.0, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_normal(1234, -0.7570164779736382) test_Philox_normal(1234, 11.242983522026362, 12) test_Philox_normal(1234, -92.35601031278387, scale=122) test_Philox_normal(1234, np.array([-0.75701648, 1.61496779, 0.67732630]), size=3) test_Philox_normal(1234, np.array([0.04298352, 2.78496779, 0.80732630, 26.50448227]), loc=np.array([0.8, 1.17, 0.13, 25.45])) test_Philox_normal(1234, np.array( [-8.93279444, 82.63790185, 40.72763043, 6.80141066]), scale=np.array([11.8, 51.17, 60.13, 6.45])) @test def test_Philox_pareto(seed, a, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_pareto(1234, 3, 0.5653481922908028) test_Philox_pareto( 1234, 5, np.array([0.30847845, 0.09324970, 0.02876564, 0.04935884, 0.94079746]), 5) test_Philox_pareto( 1234, np.array([3, 13, 4, 23.2, 5.6]), np.array([0.56534819, 0.03488493, 0.03608542, 0.01043758, 0.80769515])) @test def test_Philox_poisson(seed, expected, lam=1.0, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_poisson(1234, 0, 0) test_Philox_poisson(1234, 1) test_Philox_poisson(1234, 2, 3) test_Philox_poisson(1234, 15, 14.65) test_Philox_poisson(1234, np.array([37., 9., 11., 67., 27.]), np.array([35.62, 9.23, 9.57, 76.79, 21.74])) test_Philox_poisson(1234, np.array([829., 806., 853., 800., 821.]), 824.14, 5) @test def test_Philox_power(seed, a, expected, size=None): gen = rnd.Generator(rnd.Philox(seed)) if size is None: if isinstance(a, float) or isinstance(a, int): assert gen.power(a) == expected else: assert (round(gen.power(a), 8) == expected).all() else: assert (round(gen.power(a, size), 8) == expected).all() test_Philox_power(1234, 1, 0.7392843317079527) test_Philox_power(1234, 45.11, 0.9933260132890823) test_Philox_power(1234, 6, np.array([0.95090088, 0.84330415, 0.71374101]), 3) test_Philox_power( 1234, np.array([5.4, 1.1, 78, 19.34, 99999999999999]), np.array( array([0.94559645, 0.39470958, 0.97439242, 0.92339234, 1.00000000]))) @test def test_Philox_rayleigh(seed, expected, scale=1.0, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_rayleigh(1234, error, -1) test_Philox_rayleigh(1234, 1.6397102542808777) test_Philox_rayleigh(1234, 4.919130762842633, 3) test_Philox_rayleigh(1234, 24.021755225214857, 14.65) test_Philox_rayleigh(1234, np.array([1.63971025, 0.94421734, 0.53253802, 0.69411344]), size=4) test_Philox_rayleigh( 1234, np.array([8.85443537, 1.03863908, 41.53796574, 13.42415392, 144.71897760]), np.array([5.4, 1.1, 78, 19.34, 56.2])) @test def test_Philox_standard_cauchy(seed, expected, size=None): gen = rnd.Generator(rnd.Philox(seed)) if size is None: assert gen.standard_cauchy() == expected else: assert (round(gen.standard_cauchy(size), 8) == round(expected, 8)).all() test_Philox_standard_cauchy(1234, -0.46875020188678784) test_Philox_standard_cauchy( 1234, np.array([-0.46875020, 0.64233067, -0.70952735, -18.92416824]), 4) @test def test_Philox_standard_exponential(seed, expected, size=None, m='zig'): gen = rnd.Generator(rnd.Philox(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_Philox_standard_exponential(1234, 1.34432485899693) test_Philox_standard_exponential( 1234, np.array([1.34432486, 0.44577319, 0.14179837, 0.24089673]), 4) test_Philox_standard_exponential(1234, 0.8147656707345036, m='inv') @test def test_Philox_standard_gamma(seed, shape, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_standard_gamma(318, 1, 0.15235906502561086) test_Philox_standard_gamma(1234, 0, 0) test_Philox_standard_gamma(1234, 0.5, 0.3145070093753639) test_Philox_standard_gamma(1234, 3, 1.6116492009757368) test_Philox_standard_gamma( 1234, 0.5, np.array([0.31450701, 0.08604517, 0.97731355, 0.05278714]), 4) test_Philox_standard_gamma( 1234, np.array([4.5, 2, 7.7, 81.15]), np.array([2.80456639, 2.70292948, 5.81000297, 62.55816392])) @test def test_Philox_standard_normal(seed, expected, size=None): gen = rnd.Generator(rnd.Philox(seed)) if size is None: assert gen.standard_normal(size) == expected else: assert (round(gen.standard_normal(size), 8) == expected).all() test_Philox_standard_normal(1234, -0.7570164779736382) test_Philox_standard_normal(1234, np.array([-0.75701648, 1.61496779, 0.67732630]), 3) @test def test_Philox_standard_t(seed, df, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_standard_t(1234, 3, -0.4679940382376999) test_Philox_standard_t(1234, 1, -2.3925113365078903) test_Philox_standard_t(1234, 0.5, -7.561408056322522) test_Philox_standard_t(1234, 0.5, np.array([-7.56140806, 0.78219204, -1.00719952]), 3) test_Philox_standard_t(1234, np.array([99, 5.6, 11.43]), np.array([-0.67980828, 1.38799933, -2.21798311])) @test def test_Philox_triangular(seed, left, mode, right, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_triangular(1234, -3, 0, 8, 1.758094078569811) test_Philox_triangular(1234, np.array([-1, -4.2, -3.2]), -0.2, 77, np.array([25.36646799, 7.24243359, 10.85412666])) test_Philox_triangular( 1234, -4, np.array([0.1, 0.5, 3, 6, 7.9]), 8, np.array([1.52141664, -0.52411783, 0.96387999, 4.34090471, 6.76694962])) test_Philox_triangular(1234, -77, 0, np.array([0.1, 11, 789]), np.array([-19.48246129, -38.06368345, 94.12871014])) test_Philox_triangular( 1234, 2, 10, 53, np.array([21.84016148, 11.74049890, 13.63355147, 22.64220666]), size=4) @test def test_Philox_uniform(seed, expected, low=0.0, high=1.0, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_uniform(1234, 10.572569371365311, 5, 15) test_Philox_uniform(1234, 0.601531243422878, 0.1) test_Philox_uniform(1234, 67.9853463306568, high=122) test_Philox_uniform(1234, np.array([0.55725694, 0.22373624, 0.29333458]), size=3) test_Philox_uniform(1234, np.array( [25.25365940, 12.39692198, 17.44004855, 29.03071891]), low=np.array([0.4, 3., 6., 7.]), high=45.) test_Philox_uniform( 1234, np.array([31.20638848, 3.57977980, 12.90672144, 1.79724286, 0.16236303]), high=np.array([56., 16., 44., 3.1, 0.2])) @test def test_Philox_vonmises(seed, mu, kappa, expected, size=None): gen = rnd.Generator(rnd.Philox(seed)) if size is None: if (isinstance(mu, float) or isinstance(mu, int)) and (isinstance( kappa, float) or isinstance(kappa, int)): assert 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_Philox_vonmises(1234, 0, 4, -0.581040612761238) test_Philox_vonmises(1234, 0.1, 0.2, -1.4566350588891002) test_Philox_vonmises(1234, -1, 0, 0.3597559461503576) test_Philox_vonmises(1234, 0, 5, np.array([-0.52295031, 0.56024213, -0.16818327]), size=3) test_Philox_vonmises( 1234, np.array([43.09, 18.62, 42, 16.94]), 5, np.array([-1.41524746, 0.33068621, -2.15048042, -1.76019478])) test_Philox_vonmises( 1234, 4, np.array([0, 0.1, 7.67, 99]), np.array([0.35975595, -1.64210258, -2.41918436, -2.24951773])) @test def test_Philox_wald(seed, mean, scale, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_wald(1234, 0.1, 0.1, 0.04771066895204586) test_Philox_wald(1234, 3, 2, 1.2236223738845495) test_Philox_wald(1234, 3, 2, np.array([1.22362237, 1.33799709, 1.42908304]), 3) test_Philox_wald(1234, np.array([0.1, 0.5, 1, 4]), 0.5, np.array([0.07139433, 0.25713553, 0.42732171, 0.09772811])) test_Philox_wald(1234, 0.5, np.array([0.1, 0.5, 1, 4]), np.array([0.10751922, 0.25713553, 0.77217339, 1.07087709])) test_Philox_wald(1234, np.array([0.1, 0.5, 1, 4]), np.array([3, 2, 1, 8]), np.array([0.08710099, 0.35693113, 1.84037068, 0.95321118])) @test def test_Philox_weibull(seed, a, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_weibull(1234, 0, 0) test_Philox_weibull(1234, 0.1, 19.277126441209486) test_Philox_weibull(1234, 1, 1.34432485899693) test_Philox_weibull(1234, 1, np.array([1.34432486, 0.44577319, 0.14179837]), 3) test_Philox_weibull(1234, np.array([17.8, 4.32]), np.array([1.01676207, 0.82942358])) @test def test_Philox_zipf(seed, a, expected, size=None): gen = rnd.Generator(rnd.Philox(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_Philox_zipf(1234, 1.1, 3455) test_Philox_zipf(1234, 3, 1) test_Philox_zipf(1234, 45, np.array([1, 1, 1]), 3) test_Philox_zipf(1234, np.array([17.8, 4.32]), np.array([1, 1]))