Skip to content

Commit cdaafab

Browse files
committed
fix a few issues
1 parent 041d9e6 commit cdaafab

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

dpnp/tests/test_mathematical.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import dpnp
2121
from dpnp.dpnp_array import dpnp_array
22+
from dpnp.dpnp_utils import map_dtype_to_device
2223

2324
from .helper import (
2425
assert_dtype_allclose,
@@ -2860,7 +2861,7 @@ def test_divide(self, dtype):
28602861
dp_array1 = dpnp.array(np_array1)
28612862
dp_array2 = dpnp.array(np_array2)
28622863
if numpy.issubdtype(dtype, numpy.integer):
2863-
out_dtype = dpnp.float64
2864+
out_dtype = map_dtype_to_device(dpnp.float64, dp_array1.sycl_device)
28642865
else:
28652866
out_dtype = _get_output_data_type(dtype)
28662867
dp_out = dpnp.empty(expected.shape, dtype=out_dtype)

dpnp/tests/test_product.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ def test_out_scalar(self, dtype):
289289
b = generate_random_numpy_array(10, dtype)
290290
ib = dpnp.array(b)
291291

292-
scalar_dtype = map_dtype_to_device(type(a), ib.sycl_device)
293-
result_dtype = dpnp.result_type(scalar_dtype, ib)
294-
out = numpy.empty(10, dtype=result_dtype)
295-
dp_out = dpnp.array(out)
292+
np_res_dtype = numpy.result_type(type(a), b)
293+
out = numpy.empty(10, dtype=np_res_dtype)
294+
dp_res_dtype = map_dtype_to_device(np_res_dtype, ib.sycl_device)
295+
dp_out = dpnp.array(out, dtype=dp_res_dtype)
296296
result = dpnp.dot(a, ib, out=dp_out)
297297
expected = numpy.dot(a, b, out=out)
298298

@@ -382,7 +382,7 @@ def test_out_error_scalar(self, ia):
382382
out = numpy.empty((10,), dtype=numpy.complex64)
383383
# For scalar dpnp raises TypeError, and for empty array raises ValueError
384384
# NumPy raises ValueError for both cases
385-
assert_raises(ValueError, dpnp.dot, ia, ib, out=dp_out)
385+
assert_raises((TypeError, ValueError), dpnp.dot, ia, ib, out=dp_out)
386386
assert_raises(ValueError, numpy.dot, a, b, out=out)
387387

388388
# output shape is incorrect

dpnp/tests/test_sum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def test_sum(shape, dtype_in, dtype_out, transpose, keepdims, order):
5252
axes.append(tuple(axes_range))
5353

5454
for axis in axes:
55-
if numpy.issubdtype(dtype_out, numpy.bool):
55+
if numpy.issubdtype(dtype_out, numpy.bool_):
5656
# If summation is zero and dtype=numpy.bool is passed to numpy.sum
5757
# NumPy returns True which is not correct
5858
numpy_res = a_np.sum(axis=axis, keepdims=keepdims).astype(
59-
numpy.bool
59+
numpy.bool_
6060
)
6161
else:
6262
numpy_res = a_np.sum(axis=axis, dtype=dtype_out, keepdims=keepdims)

dpnp/tests/third_party/cupy/core_tests/test_elementwise.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,19 @@ class TestElementwiseType(unittest.TestCase):
9494
@testing.for_int_dtypes(no_bool=True)
9595
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
9696
def test_large_int_upper_1(self, xp, dtype):
97-
a = xp.array([0], dtype=numpy.int8)
97+
a = xp.array([0], dtype=xp.int8)
9898
b = xp.iinfo(dtype).max
9999
return a + b
100100

101101
@testing.for_int_dtypes(no_bool=True)
102102
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
103103
def test_large_int_upper_2(self, xp, dtype):
104-
if (
105-
numpy.issubdtype(dtype, numpy.unsignedinteger)
106-
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
107-
):
104+
flag = dtype in [numpy.int16, numpy.int32, numpy.int64, numpy.longlong]
105+
flag = numpy.issubdtype(dtype, numpy.unsignedinteger) or flag
106+
if flag and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0":
108107
pytest.skip("numpy promotes dtype differently")
109108

110-
a = xp.array([1], dtype=numpy.int8)
109+
a = xp.array([1], dtype=xp.int8)
111110
b = xp.iinfo(dtype).max - 1
112111
return a + b
113112

@@ -150,14 +149,26 @@ def test_large_int_upper_4(self, xp, dtype):
150149
@testing.for_int_dtypes(no_bool=True)
151150
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
152151
def test_large_int_lower_1(self, xp, dtype):
153-
a = xp.array([0], dtype=numpy.int8)
152+
if (
153+
dtype in [numpy.int16, numpy.int32, numpy.int64, numpy.longlong]
154+
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
155+
):
156+
pytest.skip("numpy promotes dtype differently")
157+
158+
a = xp.array([0], dtype=xp.int8)
154159
b = xp.iinfo(dtype).min
155160
return a + b
156161

157162
@testing.for_int_dtypes(no_bool=True)
158163
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
159164
def test_large_int_lower_2(self, xp, dtype):
160-
a = xp.array([-1], dtype=numpy.int8)
165+
if (
166+
dtype in [numpy.int16, numpy.int32, numpy.int64, numpy.longlong]
167+
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
168+
):
169+
pytest.skip("numpy promotes dtype differently")
170+
171+
a = xp.array([-1], dtype=xp.int8)
161172
b = xp.iinfo(dtype).min + 1
162173
return a + b
163174

0 commit comments

Comments
 (0)