Skip to content

Commit bd1e873

Browse files
committed
add random_uniform test (wip)
1 parent d70f155 commit bd1e873

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

sharpy/random/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
def uniform(low, high, size, device='', team=1):
66
data = np.random.uniform(low, high, size)
7+
# TODO handle 0 dim
78
if isinstance(data, float):
89
return data
910
return fromfunction(lambda *index: data[index], data.shape, dtype=float64, device=device, team=team)

test/test_random.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,23 @@ def test_random_rand(shape, seed):
2222
assert isinstance(sp_data, float) and sp_data == np_data
2323
else:
2424
assert np.allclose(sp.to_numpy(sp_data), np_data)
25+
26+
# @pytest.mark.parametrize("low,high", [(0, 1), (4, 10), (-100, 100)])
27+
# def test_random_uniform(low, high, shape, seed):
28+
# sp.random.seed(seed)
29+
# sp_data = sp.random.uniform(low, high, shape)
30+
31+
# np.random.seed(seed)
32+
# np_data = np.random.uniform(low, high, shape)
33+
34+
# print('np', np_data)
35+
# print('sp', sp_data)
36+
37+
# # if isinstance(np_data, float):
38+
# # assert isinstance(sp_data, float) and sp_data == np_data
39+
# # else:
40+
# # assert np.allclose(sp.to_numpy(sp_data), np_data)
41+
42+
sp.init()
43+
test_random_uniform(0, 1, (), 0)
44+
sp.fini()

0 commit comments

Comments
 (0)