Skip to content

Commit 2f5e79b

Browse files
committed
address comments
1 parent 986791d commit 2f5e79b

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

dpnp/dpnp_iface_trigonometric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ def hypot(
860860
Parameters `where`, `dtype` and `subok` are supported with their default values.
861861
Keyword argument `kwargs` is currently unsupported.
862862
Otherwise the function will be executed sequentially on CPU.
863-
Input array data types are limited by supported DPNP :ref:`Data types`.
863+
Input array data types are limited by supported real-valued data types.
864864
865865
Examples
866866
--------

tests/test_mathematical.py

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ def test_floor_divide(self, dtype, lhs, rhs):
187187
"floor_divide", dtype, lhs, rhs, check_type=False
188188
)
189189

190-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
191190
@pytest.mark.parametrize(
192191
"dtype", get_all_dtypes(no_bool=True, no_complex=True)
193192
)
@@ -910,6 +909,90 @@ def test_invalid_out(self, out):
910909
assert_raises(TypeError, numpy.add, a.asnumpy(), 2, out)
911910

912911

912+
class TestHypot:
913+
@pytest.mark.parametrize("dtype", get_float_dtypes())
914+
def test_hypot(self, dtype):
915+
array1_data = numpy.arange(10)
916+
array2_data = numpy.arange(5, 15)
917+
out = numpy.empty(10, dtype=dtype)
918+
919+
# DPNP
920+
dp_array1 = dpnp.array(array1_data, dtype=dtype)
921+
dp_array2 = dpnp.array(array2_data, dtype=dtype)
922+
dp_out = dpnp.array(out, dtype=dtype)
923+
result = dpnp.hypot(dp_array1, dp_array2, out=dp_out)
924+
925+
# original
926+
np_array1 = numpy.array(array1_data, dtype=dtype)
927+
np_array2 = numpy.array(array2_data, dtype=dtype)
928+
expected = numpy.hypot(np_array1, np_array2, out=out)
929+
930+
assert_allclose(expected, result)
931+
assert_allclose(out, dp_out)
932+
933+
@pytest.mark.parametrize("dtype", get_float_dtypes())
934+
def test_out_dtypes(self, dtype):
935+
size = 10
936+
937+
np_array1 = numpy.arange(size, 2 * size, dtype=dtype)
938+
np_array2 = numpy.arange(size, dtype=dtype)
939+
np_out = numpy.empty(size, dtype=numpy.float32)
940+
expected = numpy.hypot(np_array1, np_array2, out=np_out)
941+
942+
dp_array1 = dpnp.arange(size, 2 * size, dtype=dtype)
943+
dp_array2 = dpnp.arange(size, dtype=dtype)
944+
945+
dp_out = dpnp.empty(size, dtype=dpnp.float32)
946+
if dtype != dpnp.float32:
947+
# dtype of out mismatches types of input arrays
948+
with pytest.raises(TypeError):
949+
dpnp.hypot(dp_array1, dp_array2, out=dp_out)
950+
951+
# allocate new out with expected type
952+
dp_out = dpnp.empty(size, dtype=dtype)
953+
954+
result = dpnp.hypot(dp_array1, dp_array2, out=dp_out)
955+
956+
tol = numpy.finfo(numpy.float32).resolution
957+
assert_allclose(expected, result, rtol=tol, atol=tol)
958+
959+
@pytest.mark.parametrize("dtype", get_float_dtypes())
960+
def test_out_overlap(self, dtype):
961+
size = 15
962+
# DPNP
963+
dp_a = dpnp.arange(2 * size, dtype=dtype)
964+
dpnp.hypot(dp_a[size::], dp_a[::2], out=dp_a[:size:])
965+
966+
# original
967+
np_a = numpy.arange(2 * size, dtype=dtype)
968+
numpy.hypot(np_a[size::], np_a[::2], out=np_a[:size:])
969+
970+
tol = numpy.finfo(numpy.float32).resolution
971+
assert_allclose(np_a, dp_a, rtol=tol, atol=tol)
972+
973+
@pytest.mark.parametrize(
974+
"shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15, )", "(2,2)"]
975+
)
976+
def test_invalid_shape(self, shape):
977+
dp_array1 = dpnp.arange(10)
978+
dp_array2 = dpnp.arange(5, 15)
979+
dp_out = dpnp.empty(shape)
980+
981+
with pytest.raises(ValueError):
982+
dpnp.hypot(dp_array1, dp_array2, out=dp_out)
983+
984+
@pytest.mark.parametrize(
985+
"out",
986+
[4, (), [], (3, 7), [2, 4]],
987+
ids=["4", "()", "[]", "(3, 7)", "[2, 4]"],
988+
)
989+
def test_invalid_out(self, out):
990+
a = dpnp.arange(10)
991+
992+
assert_raises(TypeError, dpnp.hypot, a, 2, out)
993+
assert_raises(TypeError, numpy.hypot, a.asnumpy(), 2, out)
994+
995+
913996
class TestMultiply:
914997
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
915998
def test_multiply(self, dtype):

0 commit comments

Comments
 (0)