|
24 | 24 | # dimension constants
|
25 | 25 | MEDIUM_X = 10000
|
26 | 26 | LARGE_X = 100000000
|
| 27 | +SMALL_X = 100 |
27 | 28 | SMALL_Y = 50
|
28 | 29 | LARGE_SIZE = LARGE_X * SMALL_Y
|
29 | 30 |
|
@@ -79,6 +80,88 @@ def test_ndarray_random_randint():
|
79 | 80 | assert a.__gt__(low) and a.__lt__(high)
|
80 | 81 |
|
81 | 82 |
|
| 83 | +@with_seed() |
| 84 | +def test_ndarray_random_exponential(): |
| 85 | + scale_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 86 | + a = nd.random.exponential(scale=scale_array, shape=(SMALL_X, SMALL_Y)) |
| 87 | + assert a.shape == (MEDIUM_X, SMALL_Y, SMALL_X, SMALL_Y) |
| 88 | + assert a[-1][0][0][0] >= 0 |
| 89 | + |
| 90 | + |
| 91 | +@with_seed() |
| 92 | +def test_ndarray_random_gamma(): |
| 93 | + alpha_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 94 | + beta_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 95 | + a = nd.random.gamma(alpha=alpha_array, beta=beta_array, |
| 96 | + shape=(SMALL_X, SMALL_Y)) |
| 97 | + assert a.shape == (MEDIUM_X, SMALL_Y, SMALL_X, SMALL_Y) |
| 98 | + assert a[-1][0][0][0] >= 0 |
| 99 | + |
| 100 | + |
| 101 | +@with_seed() |
| 102 | +def test_ndarray_random_multinomial(): |
| 103 | + # test 1 shape dimension |
| 104 | + probs = nd.random.uniform(shape=(LARGE_X, SMALL_Y)) |
| 105 | + a = nd.random.multinomial(probs) |
| 106 | + assert a.shape == (LARGE_X,) |
| 107 | + assert a[-1] >= 0 |
| 108 | + # test for NDArray multi-dimension shape |
| 109 | + a = nd.random.multinomial(probs, shape=(SMALL_X, SMALL_Y)) |
| 110 | + assert a.shape == (LARGE_X, SMALL_X, SMALL_Y) |
| 111 | + assert a[-1][0][0] >= 0 |
| 112 | + # test log_likelihood output shape |
| 113 | + a = nd.random.multinomial(probs, shape=(SMALL_X, SMALL_Y), get_prob=True) |
| 114 | + assert a[0].shape == (LARGE_X, SMALL_X, SMALL_Y) and a[0].shape == a[1].shape |
| 115 | + assert a[-1][0][0] >= 0 |
| 116 | + |
| 117 | + |
| 118 | +@with_seed() |
| 119 | +def test_ndarray_random_generalized_negative_binomial(): |
| 120 | + alpha_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 121 | + mu_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 122 | + a = nd.random.generalized_negative_binomial(mu=mu_array, alpha=alpha_array, |
| 123 | + shape=(SMALL_X, SMALL_Y)) |
| 124 | + assert a.shape == (MEDIUM_X, SMALL_Y, SMALL_X, SMALL_Y) |
| 125 | + assert a[-1][0][0][0] >= 0 |
| 126 | + |
| 127 | + |
| 128 | +@with_seed() |
| 129 | +def test_ndarray_random_negative_binomial(): |
| 130 | + k_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 131 | + p_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 132 | + a = nd.random.negative_binomial(k=k_array, p=p_array, |
| 133 | + shape=(SMALL_X, SMALL_Y)) |
| 134 | + assert a.shape == (MEDIUM_X, SMALL_Y, SMALL_X, SMALL_Y) |
| 135 | + assert a[-1][0][0][0] >= 0 |
| 136 | + |
| 137 | + |
| 138 | +@with_seed() |
| 139 | +def test_ndarray_random_normal(): |
| 140 | + scale_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 141 | + loc_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 142 | + a = nd.random.normal(loc=loc_array, scale=scale_array, |
| 143 | + shape=(SMALL_X, SMALL_Y)) |
| 144 | + assert a.shape == (MEDIUM_X, SMALL_Y, SMALL_X, SMALL_Y) |
| 145 | + assert a[-1][0][0][0] >= 0 |
| 146 | + |
| 147 | + |
| 148 | +@with_seed() |
| 149 | +def test_ndarray_random_poisson(): |
| 150 | + lambda_array = nd.random.uniform(shape=(MEDIUM_X, SMALL_Y)) |
| 151 | + a = nd.random.poisson(lam=lambda_array, shape=(SMALL_X, SMALL_Y)) |
| 152 | + assert a.shape == (MEDIUM_X, SMALL_Y, SMALL_X, SMALL_Y) |
| 153 | + assert a[-1][0][0][0] >= 0 |
| 154 | + |
| 155 | + |
| 156 | +@with_seed() |
| 157 | +def test_ndarray_random_randn(): |
| 158 | + a = nd.random.randn(LARGE_X, SMALL_Y) |
| 159 | + assert a.shape == (LARGE_X, SMALL_Y) |
| 160 | + assert a[-1][0] >= 0 |
| 161 | + # TODO: Once PR for randn ndarray dtype for loc,scale param merged |
| 162 | + # Add check for (x,y,m,n) where x,y shape of loc,scale and m,n input shape |
| 163 | + |
| 164 | + |
82 | 165 | def test_ndarray_empty():
|
83 | 166 | a = nd.empty((LARGE_X, SMALL_Y))
|
84 | 167 | assert a.shape == (LARGE_X, SMALL_Y)
|
|
0 commit comments