Skip to content

Commit ea16c17

Browse files
committed
fix issues
1 parent 2619205 commit ea16c17

File tree

5 files changed

+36
-41
lines changed

5 files changed

+36
-41
lines changed

dpnp/tests/test_indexing.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
get_all_dtypes,
2323
get_integer_dtypes,
2424
has_support_aspect64,
25+
is_win_platform,
26+
numpy_version,
2527
)
2628
from .third_party.cupy import testing
2729

@@ -700,10 +702,12 @@ def test_1d(self, a_dt, ind_dt, indices, mode):
700702
assert_array_equal(result, expected)
701703
elif numpy.issubdtype(ind_dt, numpy.uint64):
702704
# For this special case, although casting `ind_dt` to numpy.intp
703-
# is not safe, dpnp do not raise an error
704-
# NumPy only raises an error on Windows
705+
# is not safe, both NumPy and dpnp work properly
706+
# NumPy < "2.2.0" raises an error on Windows
707+
if numpy_version() < "2.2.0" and is_win_platform():
708+
ind = ind.astype(numpy.int64)
705709
result = dpnp.take(ia, iind, mode=mode)
706-
expected = numpy.take(a, ind.astype(numpy.int64), mode=mode)
710+
expected = numpy.take(a, ind, mode=mode)
707711
assert_array_equal(result, expected)
708712
else:
709713
assert_raises(TypeError, ia.take, iind, mode=mode)

dpnp/tests/test_mathematical.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def test_angle(self, dtype, deg):
6767
result = dpnp.angle(dp_a, deg=deg)
6868

6969
# For dtype=int8, uint8, NumPy returns float16, but dpnp returns float32
70-
assert_dtype_allclose(result, expected, check_only_type_kind=True)
70+
dt_int8 = dtype in [dpnp.int8, dpnp.uint8]
71+
assert_dtype_allclose(result, expected, check_only_type_kind=dt_int8)
7172

7273
@pytest.mark.parametrize("dtype", get_complex_dtypes())
7374
def test_angle_complex(self, dtype, deg):
@@ -1352,8 +1353,7 @@ def test_1d(self, dt):
13521353
expected = numpy.i0(a)
13531354
# NumPy promotes result of integer inputs to float64, but dpnp
13541355
# follows Type Promotion Rules
1355-
skip_dtype = [numpy.int8, numpy.int16, numpy.uint8, numpy.uint16]
1356-
flag = True if dt in skip_dtype else False
1356+
flag = dt in [numpy.int8, numpy.int16, numpy.uint8, numpy.uint16]
13571357
assert_dtype_allclose(result, expected, check_only_type_kind=flag)
13581358

13591359
@pytest.mark.parametrize("dt", get_float_dtypes())
@@ -2034,7 +2034,8 @@ def test_basic(self, dt):
20342034
expected = numpy.sinc(a)
20352035
# numpy promotes result for integer inputs to float64 dtype, but dpnp
20362036
# follows Type Promotion Rules similar to other trigonometric functions
2037-
assert_dtype_allclose(result, expected, check_only_type_kind=True)
2037+
flag = dt in [numpy.int8, numpy.int16, numpy.uint8, numpy.uint16]
2038+
assert_dtype_allclose(result, expected, check_only_type_kind=flag)
20382039

20392040
def test_bool(self):
20402041
a = numpy.array([True, False, True])
@@ -2054,7 +2055,8 @@ def test_zero(self, dt):
20542055
expected = numpy.sinc(a)
20552056
# numpy promotes result for integer inputs to float64 dtype, but dpnp
20562057
# follows Type Promotion Rules similar to other trigonometric functions
2057-
assert_dtype_allclose(result, expected, check_only_type_kind=True)
2058+
flag = dt in [numpy.int8, numpy.int16, numpy.uint8, numpy.uint16]
2059+
assert_dtype_allclose(result, expected, check_only_type_kind=flag)
20582060

20592061
# TODO: add a proper NumPy version once resolved
20602062
@testing.with_requires("numpy>=2.0.0")
@@ -2499,7 +2501,7 @@ def test_divide_scalar(shape, dtype):
24992501
)
25002502
def test_negative(data, dtype):
25012503
np_a = numpy.array(data, dtype=dtype)
2502-
dpnp_a = dpnp.array(data, dtype=dtype)
2504+
dpnp_a = dpnp.array(np_a)
25032505

25042506
result = dpnp.negative(dpnp_a)
25052507
expected = numpy.negative(np_a)
@@ -2529,12 +2531,10 @@ def test_negative_boolean():
25292531
[[[1.0, -1.0], [0.1, -0.1]], [-2, -1, 0, 1, 2]],
25302532
ids=["[[1., -1.], [0.1, -0.1]]", "[-2, -1, 0, 1, 2]"],
25312533
)
2532-
@pytest.mark.parametrize(
2533-
"dtype", get_all_dtypes(no_bool=True, no_unsigned=True)
2534-
)
2534+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
25352535
def test_positive(data, dtype):
2536-
np_a = numpy.array(data, dtype=dtype)
2537-
dpnp_a = dpnp.array(data, dtype=dtype)
2536+
np_a = get_abs_array(data, dtype=dtype)
2537+
dpnp_a = dpnp.array(np_a)
25382538

25392539
result = dpnp.positive(dpnp_a)
25402540
expected = numpy.positive(np_a)

dpnp/tests/test_product.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
generate_random_numpy_array,
1313
get_all_dtypes,
1414
get_complex_dtypes,
15+
is_win_platform,
16+
numpy_version,
1517
)
1618
from .third_party.cupy import testing
1719

@@ -508,8 +510,9 @@ def test_scalar(self, dtype):
508510

509511
result = dpnp.kron(ib, a)
510512
expected = numpy.kron(b, a)
511-
# NumPy returns incorrect dtype on Windows, add check_type=False
512-
assert_dtype_allclose(result, expected, check_type=False)
513+
# NumPy returns incorrect dtype on Windows
514+
flag = not is_win_platform() if numpy_version() < "2.0.0" else True
515+
assert_dtype_allclose(result, expected, check_type=flag)
513516

514517
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
515518
@pytest.mark.parametrize(

dpnp/tests/test_strides.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,8 @@ def test_logsumexp(dtype):
163163
expected = numpy.logaddexp.reduce(a)
164164
# for int8, uint8, NumPy returns float16 but dpnp returns float64
165165
# for int16, uint16, NumPy returns float32 but dpnp returns float64
166-
if dtype in [dpnp.int8, dpnp.uint8, dpnp.int16, dpnp.uint16]:
167-
check_only_type_kind = True
168-
else:
169-
check_only_type_kind = False
170-
assert_dtype_allclose(
171-
result, expected, check_only_type_kind=check_only_type_kind
172-
)
166+
flag = dtype in [dpnp.int8, dpnp.uint8, dpnp.int16, dpnp.uint16]
167+
assert_dtype_allclose(result, expected, check_only_type_kind=flag)
173168

174169

175170
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
@@ -181,13 +176,8 @@ def test_cumlogsumexp(dtype):
181176
expected = numpy.logaddexp.accumulate(a)
182177
# for int8, uint8, NumPy returns float16 but dpnp returns float64
183178
# for int16, uint16, NumPy returns float32 but dpnp returns float64
184-
if dtype in [dpnp.int8, dpnp.uint8, dpnp.int16, dpnp.uint16]:
185-
check_only_type_kind = True
186-
else:
187-
check_only_type_kind = False
188-
assert_dtype_allclose(
189-
result, expected, check_only_type_kind=check_only_type_kind
190-
)
179+
flag = dtype in [dpnp.int8, dpnp.uint8, dpnp.int16, dpnp.uint16]
180+
assert_dtype_allclose(result, expected, check_only_type_kind=flag)
191181

192182

193183
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
@@ -199,13 +189,8 @@ def test_reduce_hypot(dtype):
199189
expected = numpy.hypot.reduce(a)
200190
# for int8, uint8, NumPy returns float16 but dpnp returns float64
201191
# for int16, uint16, NumPy returns float32 but dpnp returns float64
202-
if dtype in [dpnp.int8, dpnp.uint8, dpnp.int16, dpnp.uint16]:
203-
check_only_type_kind = True
204-
else:
205-
check_only_type_kind = False
206-
assert_dtype_allclose(
207-
result, expected, check_only_type_kind=check_only_type_kind
208-
)
192+
flag = dtype in [dpnp.int8, dpnp.uint8, dpnp.int16, dpnp.uint16]
193+
assert_dtype_allclose(result, expected, check_only_type_kind=flag)
209194

210195

211196
@pytest.mark.parametrize(

dpnp/tests/test_sum.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ def test_sum(shape, dtype_in, dtype_out, transpose, keepdims, order):
5151
axes.append(tuple(axes_range))
5252

5353
for axis in axes:
54-
if numpy.issubdtype(dtype_out, numpy.bool_):
54+
if (
55+
numpy.issubdtype(dtype_out, numpy.bool_)
56+
and numpy.issubdtype(dtype_in, numpy.signedinteger)
57+
and not a_np.sum(axis=axis).all()
58+
):
5559
# If summation is zero and dtype=numpy.bool is passed to numpy.sum
5660
# NumPy returns True which is not correct
57-
numpy_res = a_np.sum(axis=axis, keepdims=keepdims).astype(
58-
numpy.bool_
59-
)
61+
numpy_res = a_np.sum(axis=axis, keepdims=keepdims)
62+
numpy_res = numpy_res.astype(numpy.bool_)
6063
else:
6164
numpy_res = a_np.sum(axis=axis, dtype=dtype_out, keepdims=keepdims)
6265
dpnp_res = a.sum(axis=axis, dtype=dtype_out, keepdims=keepdims)

0 commit comments

Comments
 (0)