Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs/1336 NumPy-backward compatibility of statistics tests #1337

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions heat/core/tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,25 +1181,37 @@ def test_percentile(self):
# test list q and writing to output buffer
q = [0.1, 2.3, 15.9, 50.0, 84.1, 97.7, 99.9]
axis = 2
p_np = np.percentile(x_np, q, axis=axis, method="lower", keepdims=True)
try:
p_np = np.percentile(x_np, q, axis=axis, method="lower", keepdims=True)
except TypeError:
p_np = np.percentile(x_np, q, axis=axis, interpolation="lower", keepdims=True)
p_ht = ht.percentile(x_ht, q, axis=axis, interpolation="lower", keepdims=True)
out = ht.empty(p_np.shape, dtype=ht.float64, split=None, device=x_ht.device)
ht.percentile(x_ht, q, axis=axis, out=out, interpolation="lower", keepdims=True)
self.assertEqual(p_ht.numpy()[5].all(), p_np[5].all())
self.assertEqual(out.numpy()[2].all(), p_np[2].all())
self.assertTrue(p_ht.shape == p_np.shape)
axis = None
p_np = np.percentile(x_np, q, axis=axis, method="higher")
try:
p_np = np.percentile(x_np, q, axis=axis, method="higher")
except TypeError:
p_np = np.percentile(x_np, q, axis=axis, interpolation="higher")
p_ht = ht.percentile(x_ht, q, axis=axis, interpolation="higher")
self.assertEqual(p_ht.numpy()[6], p_np[6])
self.assertTrue(p_ht.shape == p_np.shape)
p_np = np.percentile(x_np, q, axis=axis, method="nearest")
try:
p_np = np.percentile(x_np, q, axis=axis, method="nearest")
except TypeError:
p_np = np.percentile(x_np, q, axis=axis, interpolation="nearest")
p_ht = ht.percentile(x_ht, q, axis=axis, interpolation="nearest")
self.assertEqual(p_ht.numpy()[2], p_np[2])

# test split q
q_ht = ht.array(q, split=0, comm=x_ht.comm)
p_np = np.percentile(x_np, q, axis=axis, method="midpoint")
try:
p_np = np.percentile(x_np, q, axis=axis, method="midpoint")
except TypeError:
p_np = np.percentile(x_np, q, axis=axis, interpolation="midpoint")
p_ht = ht.percentile(x_ht, q_ht, axis=axis, interpolation="midpoint")
self.assertEqual(p_ht.numpy()[4], p_np[4])

Expand Down
Loading