Skip to content

Commit

Permalink
comprehensive pytest update
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv committed Apr 22, 2022
1 parent 7677936 commit bbda5a9
Show file tree
Hide file tree
Showing 68 changed files with 1,138 additions and 895 deletions.
6 changes: 5 additions & 1 deletion tests/integration/test_2d_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cunumeric as num


def test():
def test_sum():
anp = np.array([[1, 2, 3], [4, 5, 6]])
a = num.array(anp)
r = a.sum(0)
Expand All @@ -28,10 +28,14 @@ def test():
r = a.sum(1)
assert np.array_equal(r, [6, 15])


def test_random():
bnp = np.random.random((2, 3))
b = num.array(bnp)
assert np.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))
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 @@ -18,9 +18,10 @@

import cunumeric as num

np.random.seed(42)

def test():
np.random.seed(42)

def test_sum():
b = np.random.random((10, 12, 13))
a = num.array(b)
assert np.allclose(a, b)
Expand Down
55 changes: 29 additions & 26 deletions tests/integration/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cunumeric as num


def run_test(arr, values, test_args):
def _run_test(arr, values, test_args):
for axis in test_args:
b = np.append(arr, values, axis)
c = num.append(arr, values, axis)
Expand Down Expand Up @@ -51,31 +51,34 @@ def run_test(arr, values, test_args):
)


def test():
dim = 10
print("test append")
# test append w/ 1D, 2D and 3D arrays
input_arr = [
(0,),
(0, 10),
(1,),
(1, 1),
(1, 1, 1),
(1, dim),
(dim, dim),
(dim, dim, dim),
]
for input_size in input_arr:
a = np.random.randint(low=0, high=100, size=(input_size))

test_args = list(range(a.ndim))
test_args.append(None)
# test the exception for 1D array on append
run_test(a, a, test_args)
if a.ndim > 1:
# 1D array
b = np.random.randint(low=0, high=100, size=(dim,))
run_test(a, b, [None])
DIM = 10

# test append w/ 1D, 2D and 3D arrays
SIZES = [
(0,),
(0, 10),
(1,),
(1, 1),
(1, 1, 1),
(1, DIM),
(DIM, DIM),
(DIM, DIM, DIM),
]


@pytest.mark.parametrize("size", SIZES, ids=str)
def test_append(size):
a = np.random.randint(low=0, high=100, size=size)

test_args = list(range(a.ndim)) + [None]

# test the exception for 1D array on append
_run_test(a, a, test_args)

if a.ndim > 1:
# 1D array
b = np.random.randint(low=0, high=100, size=(DIM,))
_run_test(a, b, [None])


if __name__ == "__main__":
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/test_argmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@

import cunumeric as num

anp = np.random.randn(4, 5)

def test():
anp = np.random.randn(4, 5)

def test_argmin():
a = num.array(anp)

assert np.array_equal(num.argmin(a, axis=0), np.argmin(anp, axis=0))
assert np.array_equal(num.argmin(a, axis=1), np.argmin(anp, axis=1))


def test_argmax():
a = num.array(anp)

assert np.array_equal(num.argmax(a, axis=0), np.argmax(anp, axis=0))
assert np.array_equal(num.argmax(a, axis=1), np.argmax(anp, axis=1))

Expand Down
66 changes: 44 additions & 22 deletions tests/integration/test_array_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cunumeric as num


def test():
def test_array():
x = num.array([1, 2, 3])
y = np.array([1, 2, 3])
z = num.array(y)
Expand All @@ -31,76 +31,98 @@ def test():
assert num.array_equal(x, y)
assert x.dtype == y.dtype


def test_empty():
xe = num.empty((2, 3))
ye = np.empty((2, 3))
assert xe.shape == ye.shape
assert xe.dtype == ye.dtype


def test_zeros():
xz = num.zeros((2, 3))
yz = np.zeros((2, 3))
assert np.array_equal(xz, yz)
assert xz.dtype == yz.dtype


def test_ones():
xo = num.ones((2, 3))
yo = np.ones((2, 3))
assert np.array_equal(xo, yo)
assert xo.dtype == yo.dtype


def test_full():
xf = num.full((2, 3), 3)
yf = np.full((2, 3), 3)
assert np.array_equal(xf, yf)
assert xf.dtype == yf.dtype


def test_empty_like():
x = num.array([1, 2, 3])
y = num.array(x)
xel = num.empty_like(x)
yel = np.empty_like(y)
assert xel.shape == yel.shape
assert xel.dtype == yel.dtype


def test_zeros_like():
x = num.array([1, 2, 3])
y = num.array(x)
xzl = num.zeros_like(x)
yzl = np.zeros_like(y)
assert np.array_equal(xzl, yzl)
assert xzl.dtype == yzl.dtype


def test_ones_like():
x = num.array([1, 2, 3])
y = num.array(x)
xol = num.ones_like(x)
yol = np.ones_like(y)
assert np.array_equal(xol, yol)
assert xol.dtype == yol.dtype


def test_full_like():
x = num.array([1, 2, 3])
y = num.array(x)
xfl = num.full_like(x, 3)
yfl = np.full_like(y, 3)
assert np.array_equal(xfl, yfl)
assert xfl.dtype == yfl.dtype

x = num.arange(1)
y = np.arange(1)
assert np.array_equal(x, y)
assert x.dtype == y.dtype
# xfls = num.full_like(x, '3', dtype=np.str_)
# yfls = np.full_like(y, '3', dtype=np.str_)
# assert(num.array_equal(xfls, yfls))
# assert(xfls.dtype == yfls.dtype)

x = num.arange(10)
y = np.arange(10)
assert np.array_equal(x, y)
assert x.dtype == y.dtype

x = num.arange(10, dtype=np.int32)
y = np.arange(10, dtype=np.int32)
assert np.array_equal(x, y)
assert x.dtype == y.dtype
ARANGE_ARGS = [
(1,),
(10,),
(2.0, 10.0),
(2, 30, 3),
]

x = num.arange(2.0, 10.0)
y = np.arange(2.0, 10.0)

@pytest.mark.parametrize("args", ARANGE_ARGS, ids=str)
def test_arange(args):
x = num.arange(*args)
y = np.arange(*args)
assert np.array_equal(x, y)
assert x.dtype == y.dtype

x = num.arange(2, 30, 3)
y = np.arange(2, 30, 3)

def test_arange_with_dtype():
x = num.arange(10, dtype=np.int32)
y = np.arange(10, dtype=np.int32)
assert np.array_equal(x, y)
assert x.dtype == y.dtype

# xfls = num.full_like(x, '3', dtype=np.str_)
# yfls = np.full_like(y, '3', dtype=np.str_)
# assert(num.array_equal(xfls, yfls))
# assert(xfls.dtype == yfls.dtype)


if __name__ == "__main__":
import sys
Expand Down
Loading

0 comments on commit bbda5a9

Please sign in to comment.