Skip to content

Commit

Permalink
allclose detail + misc tests improvements (#457)
Browse files Browse the repository at this point in the history
* rename tests_tools -> utils

* parametrize window tests

* remove superfluous asserts module

* use utils.allclose

* update test_view.py to AAA

* parametrize unary ufunc tests

* paramterize test_trilu.py

* parametrize test_transform.py

* simplify test_squeeze.py, update to AAA

* Apply suggestions from code review

* use ~close insead of not close

* fix transpose test

* formatting

* typo

* Update tests/integration/utils/comparisons.py
  • Loading branch information
bryevdv authored Jul 25, 2022
1 parent 9a01628 commit 63a8cf0
Show file tree
Hide file tree
Showing 48 changed files with 502 additions and 415 deletions.
7 changes: 4 additions & 3 deletions tests/integration/test_2d_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pytest
from utils.comparisons import allclose

import cunumeric as num

Expand All @@ -32,14 +33,14 @@ def test_sum():
def test_random():
bnp = np.random.random((2, 3))
b = num.array(bnp)
assert np.allclose(num.sum(b), np.sum(bnp))
assert allclose(num.sum(b), np.sum(bnp))


def test_randn():
af = np.random.randn(4, 5)
bf = num.array(af)
assert np.allclose(af.mean(0), bf.mean(0))
assert np.allclose(af.mean(), bf.mean())
assert allclose(af.mean(0), bf.mean(0))
assert allclose(af.mean(), bf.mean())


if __name__ == "__main__":
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/test_3d_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pytest
from utils.comparisons import allclose

import cunumeric as num

Expand All @@ -24,11 +25,11 @@
def test_sum():
b = np.random.random((10, 12, 13))
a = num.array(b)
assert np.allclose(a, b)
assert allclose(a, b)

lg_sum = num.sum(a)
np_sum = np.sum(b)
assert np.allclose(np_sum, lg_sum)
assert allclose(np_sum, lg_sum)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_advanced_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np
import pytest
from test_tools.generators import mk_seq_array
from utils.generators import mk_seq_array

import cunumeric as num
from legate.core import LEGATE_MAX_DIM
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_binary_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

import numpy as np
import pytest
from utils.comparisons import allclose

import cunumeric as num


def check_result(op, in_np, out_np, out_num):
result = np.allclose(out_np, out_num) and out_np.dtype == out_num.dtype
result = allclose(out_np, out_num) and out_np.dtype == out_num.dtype
if not result:
print(f"cunumeric.{op} failed the test")
print("Inputs:")
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_bincount.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pytest
from utils.comparisons import allclose

import cunumeric as num

Expand Down Expand Up @@ -44,7 +45,7 @@ def test_bincount_weights(dtype):

out_np = np.bincount(v_np, weights=w_np)
out_num = num.bincount(v_num, weights=w_num)
assert num.allclose(out_np, out_num)
assert allclose(out_np, out_num)


if __name__ == "__main__":
Expand Down
9 changes: 5 additions & 4 deletions tests/integration/test_cholesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pytest
from utils.comparisons import allclose

import cunumeric as num

Expand All @@ -24,7 +25,7 @@
def test_diagonal():
a = num.eye(10) * 10.0
b = num.linalg.cholesky(a)
assert num.allclose(b**2.0, a)
assert allclose(b**2.0, a)


@pytest.mark.parametrize("n", SIZES)
Expand All @@ -33,7 +34,7 @@ def test_real(n):
b = a + a.T + num.eye(n) * n
c = num.linalg.cholesky(b)
c_np = np.linalg.cholesky(b.__array__())
assert num.allclose(c, c_np)
assert allclose(c, c_np)


@pytest.mark.parametrize("n", SIZES)
Expand All @@ -42,13 +43,13 @@ def test_complex(n):
b = a + a.T.conj() + num.eye(n) * n
c = num.linalg.cholesky(b)
c_np = np.linalg.cholesky(b.__array__())
assert num.allclose(c, c_np)
assert allclose(c, c_np)

d = num.empty((2, n, n))
d[1] = b
c = num.linalg.cholesky(d[1])
c_np = np.linalg.cholesky(d[1].__array__())
assert num.allclose(c, c_np)
assert allclose(c, c_np)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import numpy as np
import pytest
from test_tools.generators import mk_seq_array
from utils.generators import mk_seq_array

import cunumeric as num
from legate.core import LEGATE_MAX_DIM
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import numpy as np
import pytest
import scipy.signal as sig
from utils.comparisons import allclose

import cunumeric as num

Expand All @@ -34,7 +35,7 @@ def check_convolve(a, v):
else:
out_np = np.convolve(anp, vnp, mode="same")

assert num.allclose(out, out_np)
assert allclose(out, out_np)


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
import pytest
from cunumeric.utils import dot_modes
from test_tools.contractions import check_default
from utils.contractions import check_default

from legate.core import LEGATE_MAX_DIM

Expand Down
7 changes: 4 additions & 3 deletions tests/integration/test_einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import numpy as np
import pytest
from test_tools.generators import mk_0to1_array, permutes_to
from utils.comparisons import allclose
from utils.generators import mk_0to1_array, permutes_to

import cunumeric as cn

Expand Down Expand Up @@ -231,12 +232,12 @@ def check_np_vs_cn(expr, mk_input, mk_output=None, **kwargs):
or kwargs.get("dtype") == np.float16
else 1e-05
)
assert np.allclose(np_res, cn_res, rtol=rtol)
assert allclose(np_res, cn_res, rtol=rtol)
if mk_output is not None:
for cn_out in mk_output(cn, out_shape):
cn.einsum(expr, *cn_inputs, out=cn_out, **kwargs)
rtol_out = 1e-02 if cn_out.dtype == np.float16 else rtol
assert np.allclose(cn_out, cn_res, rtol=rtol_out)
assert allclose(cn_out, cn_res, rtol=rtol_out)


@pytest.mark.parametrize("expr", gen_expr())
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_fft_c2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import numpy as np
import pytest
from utils.comparisons import allclose as _allclose

import cunumeric as num

Expand All @@ -29,7 +30,7 @@ def allclose(A, B):
l2 = np.sqrt(np.sum(l2) / np.sum(A * np.conj(A)))
return l2 < 1e-6
else:
return np.allclose(A, B)
return _allclose(A, B)


def check_1d_c2c(N, dtype=np.float64):
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_fft_c2r.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pytest
from utils.comparisons import allclose as _allclose

import cunumeric as num

Expand All @@ -27,7 +28,7 @@ def allclose(A, B):
l2 = np.sqrt(np.sum(l2) / np.sum(A * np.conj(A)))
return l2 < 1e-6
else:
return np.allclose(A, B)
return _allclose(A, B)


def check_1d_c2r(N, dtype=np.float64):
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_fft_hermitian.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pytest
from utils.comparisons import allclose as _allclose

import cunumeric as num

Expand All @@ -27,7 +28,7 @@ def allclose(A, B):
l2 = np.sqrt(np.sum(l2) / np.sum(A * np.conj(A)))
return l2 < 1e-6
else:
return np.allclose(A, B)
return _allclose(A, B)


def check_1d_hfft(N, dtype=np.float64):
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_fft_r2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pytest
from utils.comparisons import allclose as _allclose

import cunumeric as num

Expand All @@ -27,7 +28,7 @@ def allclose(A, B):
l2 = np.sqrt(np.sum(l2) / np.sum(A * np.conj(A)))
return l2 < 1e-6
else:
return np.allclose(A, B)
return _allclose(A, B)


def check_1d_r2c(N, dtype=np.float64):
Expand Down
35 changes: 18 additions & 17 deletions tests/integration/test_floating.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pytest
from utils.comparisons import allclose

import cunumeric as num

Expand All @@ -35,14 +36,14 @@ def test_modf(shape):
outs_num = num.modf(x_num)

for out_np, out_num in zip(outs_np, outs_num):
assert np.allclose(out_np, out_num)
assert allclose(out_np, out_num)

# Test integer input
outs_np = np.modf(x_np.astype("i"))
outs_num = num.modf(x_num.astype("i"))

for out_np, out_num in zip(outs_np, outs_num):
assert np.allclose(out_np, out_num)
assert allclose(out_np, out_num)

# Test positional outputs
out1_np = np.empty(shape, dtype="f")
Expand All @@ -54,14 +55,14 @@ def test_modf(shape):
np.modf(x_np, out1_np, out2_np)
num.modf(x_num, out1_num, out2_num)

assert np.allclose(out1_np, out1_num)
assert np.allclose(out2_np, out2_num)
assert allclose(out1_np, out1_num)
assert allclose(out2_np, out2_num)

(tmp1_np, out2_np) = np.modf(x_np, out1_np)
(tmp1_num, out2_num) = num.modf(x_num, out1_num)

assert np.allclose(out1_np, out1_num)
assert np.allclose(out2_np, out2_num)
assert allclose(out1_np, out1_num)
assert allclose(out2_np, out2_num)
assert tmp1_num is out1_num

# Test keyword outputs
Expand All @@ -74,21 +75,21 @@ def test_modf(shape):
np.modf(x_np, out=(out1_np, out2_np))
num.modf(x_num, out=(out1_num, out2_num))

assert np.allclose(out1_np, out1_num)
assert np.allclose(out2_np, out2_num)
assert allclose(out1_np, out1_num)
assert allclose(out2_np, out2_num)

(tmp2_np, out2_np) = np.modf(x_np, out=(out1_np, None))
(tmp2_num, out2_num) = num.modf(x_num, out=(out1_num, None))

assert np.allclose(out1_np, out1_num)
assert np.allclose(out2_np, out2_num)
assert allclose(out1_np, out1_num)
assert allclose(out2_np, out2_num)
assert out1_num is tmp2_num

(out1_np, tmp2_np) = np.modf(x_np, out=(None, out2_np))
(out1_num, tmp2_num) = num.modf(x_num, out=(None, out2_num))

assert np.allclose(out1_np, out1_num)
assert np.allclose(out2_np, out2_num)
assert allclose(out1_np, out1_num)
assert allclose(out2_np, out2_num)
assert out2_num is tmp2_num


Expand All @@ -101,7 +102,7 @@ def test_floating(shape):
frexp_num = num.frexp(x_num)

for out_np, out_num in zip(frexp_np, frexp_num):
assert np.allclose(out_np, out_num)
assert allclose(out_np, out_num)

out1_np = np.empty(shape, dtype="f")
out2_np = np.empty(shape, dtype="l")
Expand All @@ -112,18 +113,18 @@ def test_floating(shape):
np.frexp(x_np, out=(out1_np, out2_np))
num.frexp(x_num, out=(out1_num, out2_num))

assert np.allclose(out1_np, out1_num)
assert np.allclose(out2_np, out2_num)
assert allclose(out1_np, out1_num)
assert allclose(out2_np, out2_num)

ldexp_np = np.ldexp(*frexp_np)
ldexp_num = num.ldexp(*frexp_num)

assert np.allclose(ldexp_np, ldexp_num)
assert allclose(ldexp_np, ldexp_num)

ldexp_np = np.ldexp(out1_np, out2_np)
ldexp_num = num.ldexp(out1_num, out2_num)

assert np.allclose(ldexp_np, ldexp_num)
assert allclose(ldexp_np, ldexp_num)


@pytest.mark.parametrize("fun", ("modf", "frexp"))
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_index_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import numpy as np
import pytest
from cunumeric.eager import diagonal_reference
from test_tools.generators import mk_seq_array
from utils.generators import mk_seq_array

import cunumeric as num
from legate.core import LEGATE_MAX_DIM
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_inner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
import pytest
from cunumeric.utils import inner_modes
from test_tools.contractions import check_default
from utils.contractions import check_default

from legate.core import LEGATE_MAX_DIM

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_intra_array_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import numpy as np
import pytest
from test_tools.generators import mk_0to1_array
from utils.generators import mk_0to1_array

import cunumeric as num
from legate.core import LEGATE_MAX_DIM
Expand Down
Loading

0 comments on commit 63a8cf0

Please sign in to comment.