Skip to content

Commit

Permalink
address reviewers' comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vtavana committed Aug 17, 2023
1 parent 1eefeca commit 5085a82
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 46 deletions.
91 changes: 49 additions & 42 deletions tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .helper import (
get_all_dtypes,
get_float_complex_dtypes,
get_float_dtypes,
has_support_aspect64,
is_cpu_device,
is_win_platform,
Expand Down Expand Up @@ -597,119 +598,125 @@ def test_gradient_y1_dx(self, array, dx):


class TestCeil:
def test_ceil(self):
@pytest.mark.parametrize("dtype", get_float_dtypes())
def test_ceil(self, dtype):
array_data = numpy.arange(10)
out = numpy.empty(10, dtype=numpy.float64)
out = numpy.empty(10, dtype)

# DPNP
dp_array = dpnp.array(array_data, dtype=dpnp.float64)
dp_out = dpnp.array(out, dtype=dpnp.float64)
dp_array = dpnp.array(array_data, dtype=dtype)
dp_out = dpnp.array(out, dtype=dtype)
result = dpnp.ceil(dp_array, out=dp_out)

# original
np_array = numpy.array(array_data, dtype=numpy.float64)
np_array = numpy.array(array_data, dtype=dtype)
expected = numpy.ceil(np_array, out=out)

assert_array_equal(expected, result)

@pytest.mark.parametrize(
"dtype",
[numpy.float32, numpy.int64, numpy.int32],
ids=["numpy.float32", "numpy.int64", "numpy.int32"],
"dtype", get_all_dtypes(no_bool=True, no_complex=True, no_none=True)
)
def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp.float64)
dpnp_dtype = dpnp.float64 if has_support_aspect64() else dpnp.float32
pytest.skip("similar data types") if dpnp_dtype == dtype else None
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(ValueError):
with pytest.raises(TypeError):
dpnp.ceil(dp_array, out=dp_out)

@pytest.mark.parametrize("dtype", get_float_dtypes())
@pytest.mark.parametrize(
"shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15, )", "(2,2)"]
)
def test_invalid_shape(self, shape):
dp_array = dpnp.arange(10, dtype=dpnp.float64)
dp_out = dpnp.empty(shape, dtype=dpnp.float64)
def test_invalid_shape(self, shape, dtype):
dp_array = dpnp.arange(10, dtype=dtype)
dp_out = dpnp.empty(shape, dtype=dtype)

with pytest.raises(ValueError):
with pytest.raises(TypeError):
dpnp.ceil(dp_array, out=dp_out)


class TestFloor:
def test_floor(self):
@pytest.mark.parametrize("dtype", get_float_dtypes())
def test_floor(self, dtype):
array_data = numpy.arange(10)
out = numpy.empty(10, dtype=numpy.float64)
out = numpy.empty(10, dtype=dtype)

# DPNP
dp_array = dpnp.array(array_data, dtype=dpnp.float64)
dp_out = dpnp.array(out, dtype=dpnp.float64)
dp_array = dpnp.array(array_data, dtype=dtype)
dp_out = dpnp.array(out, dtype=dtype)
result = dpnp.floor(dp_array, out=dp_out)

# original
np_array = numpy.array(array_data, dtype=numpy.float64)
np_array = numpy.array(array_data, dtype=dtype)
expected = numpy.floor(np_array, out=out)

assert_array_equal(expected, result)

@pytest.mark.parametrize(
"dtype",
[numpy.float32, numpy.int64, numpy.int32],
ids=["numpy.float32", "numpy.int64", "numpy.int32"],
"dtype", get_all_dtypes(no_bool=True, no_complex=True, no_none=True)
)
def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp.float64)
dpnp_dtype = dpnp.float64 if has_support_aspect64() else dpnp.float32
pytest.skip("similar data types") if dpnp_dtype == dtype else None
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(ValueError):
with pytest.raises(TypeError):
dpnp.floor(dp_array, out=dp_out)

@pytest.mark.parametrize("dtype", get_float_dtypes())
@pytest.mark.parametrize(
"shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15, )", "(2,2)"]
)
def test_invalid_shape(self, shape):
dp_array = dpnp.arange(10, dtype=dpnp.float64)
dp_out = dpnp.empty(shape, dtype=dpnp.float64)
def test_invalid_shape(self, shape, dtype):
dp_array = dpnp.arange(10, dtype=dtype)
dp_out = dpnp.empty(shape, dtype=dtype)

with pytest.raises(ValueError):
with pytest.raises(TypeError):
dpnp.floor(dp_array, out=dp_out)


class TestTrunc:
def test_trunc(self):
@pytest.mark.parametrize("dtype", get_float_dtypes())
def test_trunc(self, dtype):
array_data = numpy.arange(10)
out = numpy.empty(10, dtype=numpy.float64)
out = numpy.empty(10, dtype=dtype)

# DPNP
dp_array = dpnp.array(array_data, dtype=dpnp.float64)
dp_out = dpnp.array(out, dtype=dpnp.float64)
dp_array = dpnp.array(array_data, dtype=dtype)
dp_out = dpnp.array(out, dtype=dtype)
result = dpnp.trunc(dp_array, out=dp_out)

# original
np_array = numpy.array(array_data, dtype=numpy.float64)
np_array = numpy.array(array_data, dtype=dtype)
expected = numpy.trunc(np_array, out=out)

assert_array_equal(expected, result)

@pytest.mark.parametrize(
"dtype",
[numpy.float32, numpy.int64, numpy.int32],
ids=["numpy.float32", "numpy.int64", "numpy.int32"],
"dtype", get_all_dtypes(no_bool=True, no_complex=True, no_none=True)
)
def test_invalid_dtype(self, dtype):
dp_array = dpnp.arange(10, dtype=dpnp.float64)
dpnp_dtype = dpnp.float64 if has_support_aspect64() else dpnp.float32
pytest.skip("similar data types") if dpnp_dtype == dtype else None
dp_array = dpnp.arange(10, dtype=dpnp_dtype)
dp_out = dpnp.empty(10, dtype=dtype)

with pytest.raises(ValueError):
with pytest.raises(TypeError):
dpnp.trunc(dp_array, out=dp_out)

@pytest.mark.parametrize("dtype", get_float_dtypes())
@pytest.mark.parametrize(
"shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15, )", "(2,2)"]
)
def test_invalid_shape(self, shape):
dp_array = dpnp.arange(10, dtype=dpnp.float64)
dp_out = dpnp.empty(shape, dtype=dpnp.float64)
def test_invalid_shape(self, shape, dtype):
dp_array = dpnp.arange(10, dtype=dtype)
dp_out = dpnp.empty(shape, dtype=dtype)

with pytest.raises(ValueError):
with pytest.raises(TypeError):
dpnp.trunc(dp_array, out=dp_out)


Expand Down
8 changes: 4 additions & 4 deletions tests/test_usm_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ def test_meshgrid(usm_type_x, usm_type_y):
@pytest.mark.parametrize(
"func,data",
[
pytest.param(
"sqrt",
[1.0, 3.0, 9.0],
),
pytest.param("ceil", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
pytest.param("trunc", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
pytest.param("sqrt", [1.0, 3.0, 9.0]),
],
)
@pytest.mark.parametrize("usm_type", list_of_usm_types, ids=list_of_usm_types)
Expand Down

0 comments on commit 5085a82

Please sign in to comment.