Skip to content

Commit 1a96229

Browse files
author
Vahid Tavanashad
committed
new changes for windows
1 parent 28cbc8b commit 1a96229

File tree

4 files changed

+47
-70
lines changed

4 files changed

+47
-70
lines changed

dpnp/dpnp_iface_linearalgebra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,13 +1116,13 @@ def vdot(a, b):
11161116
if b.size != 1:
11171117
raise ValueError("The second array should be of size one.")
11181118
a_conj = numpy.conj(a)
1119-
return dpnp.multiply(a_conj, b)
1119+
return _call_multiply(a_conj, b)
11201120

11211121
if dpnp.isscalar(b):
11221122
if a.size != 1:
11231123
raise ValueError("The first array should be of size one.")
11241124
a_conj = dpnp.conj(a)
1125-
return dpnp.multiply(a_conj, b)
1125+
return _call_multiply(a_conj, b)
11261126

11271127
if a.ndim == 1 and b.ndim == 1:
11281128
return dpnp_dot(a, b, out=None, conjugate=True)

dpnp/tests/test_indexing.py

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -652,16 +652,9 @@ def test_values(self, arr_dt, idx_dt, ndim, values):
652652
ia, iind = dpnp.array(a), dpnp.array(ind)
653653

654654
for axis in range(ndim):
655-
if ndim != 1 and numpy.issubdtype(idx_dt, numpy.uint64):
656-
# For this special case, dpnp raises an error but NumPy works
657-
# TODO: remove the workaround when dpctl-1936 is fixed
658-
assert_raises(
659-
ValueError, dpnp.put_along_axis, ia, iind, values, axis
660-
)
661-
else:
662-
numpy.put_along_axis(a, ind, values, axis)
663-
dpnp.put_along_axis(ia, iind, values, axis)
664-
assert_array_equal(ia, a)
655+
numpy.put_along_axis(a, ind, values, axis)
656+
dpnp.put_along_axis(ia, iind, values, axis)
657+
assert_array_equal(ia, a)
665658

666659
@pytest.mark.parametrize("xp", [numpy, dpnp])
667660
@pytest.mark.parametrize("dt", [bool, numpy.float32])
@@ -678,10 +671,6 @@ def test_broadcast(self, arr_dt, idx_dt):
678671
ia, iind = dpnp.array(a), dpnp.array(ind)
679672

680673
if numpy.issubdtype(idx_dt, numpy.uint64):
681-
# For this special case, dpnp raises an error but NumPy works
682-
# TODO: remove the workaround when dpctl-1936 is fixed
683-
assert_raises(ValueError, dpnp.put_along_axis, ia, iind, 20, axis=1)
684-
else:
685674
numpy.put_along_axis(a, ind, 20, axis=1)
686675
dpnp.put_along_axis(ia, iind, 20, axis=1)
687676
assert_array_equal(ia, a)
@@ -732,10 +721,11 @@ def test_1d(self, a_dt, ind_dt, indices, mode):
732721
expected = numpy.take(a, ind, mode=mode)
733722
assert_array_equal(result, expected)
734723
elif numpy.issubdtype(ind_dt, numpy.uint64):
735-
# For this special case, although casting `ind_dt`` to numpy.intp
736-
# is not safe, NumPy and dpnp do not raise an error
724+
# For this special case, although casting `ind_dt` to numpy.intp
725+
# is not safe, dpnp do not raise an error
726+
# NumPy only raises an error on Windows
737727
result = dpnp.take(ia, iind, mode=mode)
738-
expected = numpy.take(a, ind, mode=mode)
728+
expected = numpy.take(a, ind.astype(numpy.int64), mode=mode)
739729
assert_array_equal(result, expected)
740730
else:
741731
assert_raises(TypeError, ia.take, iind, mode=mode)
@@ -758,9 +748,15 @@ def test_2d(self, a_dt, ind_dt, indices, mode, axis):
758748
ind = numpy.array(indices, dtype=ind_dt)
759749
ia, iind = dpnp.array(a), dpnp.array(ind)
760750

761-
result = ia.take(iind, axis=axis, mode=mode)
762-
expected = a.take(ind, axis=axis, mode=mode)
763-
assert_array_equal(result, expected)
751+
if numpy.issubdtype(ind_dt, numpy.uint64):
752+
# For this special case, NumPy raises an error on Windows
753+
result = ia.take(iind, axis=axis, mode=mode)
754+
expected = a.take(ind.astype(numpy.int64), axis=axis, mode=mode)
755+
assert_array_equal(result, expected)
756+
else:
757+
result = ia.take(iind, axis=axis, mode=mode)
758+
expected = a.take(ind, axis=axis, mode=mode)
759+
assert_array_equal(result, expected)
764760

765761
@pytest.mark.parametrize("a_dt", get_all_dtypes(no_none=True))
766762
@pytest.mark.parametrize("mode", ["clip", "wrap"])
@@ -852,14 +848,9 @@ def test_multi_dimensions(self, arr_dt, idx_dt, ndim):
852848
ia, iind = dpnp.array(a), dpnp.array(ind)
853849

854850
for axis in range(ndim):
855-
if ndim != 1 and numpy.issubdtype(idx_dt, numpy.uint64):
856-
# For this special case, dpnp raises an error but NumPy works
857-
# TODO: remove the workaround when dpctl-1936 is fixed
858-
assert_raises(ValueError, dpnp.take_along_axis, ia, iind, axis)
859-
else:
860-
result = dpnp.take_along_axis(ia, iind, axis)
861-
expected = numpy.take_along_axis(a, ind, axis)
862-
assert_array_equal(expected, result)
851+
result = dpnp.take_along_axis(ia, iind, axis)
852+
expected = numpy.take_along_axis(a, ind, axis)
853+
assert_array_equal(expected, result)
863854

864855
@pytest.mark.parametrize("xp", [numpy, dpnp])
865856
def test_not_enough_indices(self, xp):
@@ -892,14 +883,9 @@ def test_empty(self, a_dt, idx_dt):
892883
ind = numpy.ones((3, 0, 5), dtype=idx_dt)
893884
ia, iind = dpnp.array(a), dpnp.array(ind)
894885

895-
if numpy.issubdtype(idx_dt, numpy.uint64):
896-
# For this special case, dpnp raises an error but NumPy works
897-
# TODO: remove the workaround when dpctl-1936 is fixed
898-
assert_raises(ValueError, dpnp.take_along_axis, ia, iind, axis=1)
899-
else:
900-
result = dpnp.take_along_axis(ia, iind, axis=1)
901-
expected = numpy.take_along_axis(a, ind, axis=1)
902-
assert_array_equal(expected, result)
886+
result = dpnp.take_along_axis(ia, iind, axis=1)
887+
expected = numpy.take_along_axis(a, ind, axis=1)
888+
assert_array_equal(expected, result)
903889

904890
@pytest.mark.parametrize("a_dt", get_all_dtypes(no_none=True))
905891
@pytest.mark.parametrize("idx_dt", get_integer_dtypes())
@@ -908,14 +894,9 @@ def test_broadcast(self, a_dt, idx_dt):
908894
ind = numpy.ones((1, 2, 5), dtype=idx_dt)
909895
ia, iind = dpnp.array(a), dpnp.array(ind)
910896

911-
if numpy.issubdtype(idx_dt, numpy.uint64):
912-
# For this special case, dpnp raises an error but NumPy works
913-
# TODO: remove the workaround when dpctl-1936 is fixed
914-
assert_raises(ValueError, dpnp.take_along_axis, ia, iind, axis=1)
915-
else:
916-
result = dpnp.take_along_axis(ia, iind, axis=1)
917-
expected = numpy.take_along_axis(a, ind, axis=1)
918-
assert_array_equal(expected, result)
897+
result = dpnp.take_along_axis(ia, iind, axis=1)
898+
expected = numpy.take_along_axis(a, ind, axis=1)
899+
assert_array_equal(expected, result)
919900

920901
def test_mode_wrap(self):
921902
a = numpy.array([-2, -1, 0, 1, 2])

dpnp/tests/test_mathematical.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,13 @@ def test_basic(self, mant_dt, exp_dt):
14291429
if dpnp.issubdtype(exp_dt, dpnp.uint64):
14301430
assert_raises(ValueError, dpnp.ldexp, imant, iexp)
14311431
assert_raises(TypeError, numpy.ldexp, mant, exp)
1432+
elif dpnp.issubdtype(exp_dt, dpnp.uint32):
1433+
# For this special case, NumPy raises an error on Windows
1434+
# because it doesn't have a loop for the input types
1435+
# dpnp works fine
1436+
result = dpnp.ldexp(imant, iexp)
1437+
expected = numpy.ldexp(mant, exp.astype(numpy.int32))
1438+
assert_almost_equal(result, expected)
14321439
else:
14331440
result = dpnp.ldexp(imant, iexp)
14341441
expected = numpy.ldexp(mant, exp)
@@ -3409,7 +3416,7 @@ def test_invalid_out(self, out):
34093416
class TestPower:
34103417
@pytest.mark.parametrize("val_type", get_all_dtypes(no_none=True))
34113418
@pytest.mark.parametrize("data_type", get_all_dtypes())
3412-
@pytest.mark.parametrize("val", [1.5, 1, 5], ids=["1.5", "1", "5"])
3419+
@pytest.mark.parametrize("val", [1.5, 1, 3], ids=["1.5", "1", "3"])
34133420
@pytest.mark.parametrize(
34143421
"array",
34153422
[

dpnp/tests/test_product.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@
1616
from .third_party.cupy import testing
1717

1818

19-
def _assert_selective_dtype_allclose(result, expected, dtype):
20-
# For numpy.dot, numpy.vdot, numpy.kron, numpy.inner, and numpy.tensordot,
21-
# when inputs are an scalar (which has the default dtype of platform) and
22-
# an array, the scalar dtype precision determines the output dtype
23-
# precision. In dpnp, we rely on dpnp.multiply for scalar-array product
24-
# and array (not scalar) determines output dtype precision of dpnp.multiply
25-
if dtype in [numpy.int32, numpy.float32, numpy.complex64]:
26-
assert_dtype_allclose(result, expected, check_only_type_kind=True)
27-
else:
28-
assert_dtype_allclose(result, expected)
29-
30-
3119
class TestCross:
3220
def setup_method(self):
3321
numpy.random.seed(42)
@@ -222,11 +210,11 @@ def test_scalar(self, dtype):
222210

223211
result = dpnp.dot(a, ib)
224212
expected = numpy.dot(a, b)
225-
_assert_selective_dtype_allclose(result, expected, dtype)
213+
assert_dtype_allclose(result, expected)
226214

227215
result = dpnp.dot(ib, a)
228216
expected = numpy.dot(b, a)
229-
_assert_selective_dtype_allclose(result, expected, dtype)
217+
assert_dtype_allclose(result, expected)
230218

231219
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
232220
@pytest.mark.parametrize(
@@ -297,7 +285,7 @@ def test_out_scalar(self, dtype):
297285
expected = numpy.dot(a, b, out=out)
298286

299287
assert result is dp_out
300-
_assert_selective_dtype_allclose(result, expected, dtype)
288+
assert_dtype_allclose(result, expected)
301289

302290
@pytest.mark.parametrize("dtype", get_all_dtypes())
303291
@pytest.mark.parametrize(
@@ -448,11 +436,11 @@ def test_scalar(self, dtype):
448436

449437
result = dpnp.inner(a, ib)
450438
expected = numpy.inner(a, b)
451-
_assert_selective_dtype_allclose(result, expected, dtype)
439+
assert_dtype_allclose(result, expected)
452440

453441
result = dpnp.inner(ib, a)
454442
expected = numpy.inner(b, a)
455-
_assert_selective_dtype_allclose(result, expected, dtype)
443+
assert_dtype_allclose(result, expected)
456444

457445
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
458446
@pytest.mark.parametrize(
@@ -516,11 +504,12 @@ def test_scalar(self, dtype):
516504

517505
result = dpnp.kron(a, ib)
518506
expected = numpy.kron(a, b)
519-
_assert_selective_dtype_allclose(result, expected, dtype)
507+
assert_dtype_allclose(result, expected)
520508

521509
result = dpnp.kron(ib, a)
522510
expected = numpy.kron(b, a)
523-
_assert_selective_dtype_allclose(result, expected, dtype)
511+
# NumPy returns incorrect dtype on Windows, so add check_type=False
512+
assert_dtype_allclose(result, expected, check_type=False)
524513

525514
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
526515
@pytest.mark.parametrize(
@@ -768,11 +757,11 @@ def test_scalar(self, dtype):
768757

769758
result = dpnp.tensordot(a, ib, axes=0)
770759
expected = numpy.tensordot(a, b, axes=0)
771-
_assert_selective_dtype_allclose(result, expected, dtype)
760+
assert_dtype_allclose(result, expected)
772761

773762
result = dpnp.tensordot(ib, a, axes=0)
774763
expected = numpy.tensordot(b, a, axes=0)
775-
_assert_selective_dtype_allclose(result, expected, dtype)
764+
assert_dtype_allclose(result, expected)
776765

777766
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
778767
@pytest.mark.parametrize("axes", [0, 1, 2])
@@ -902,11 +891,11 @@ def test_scalar(self, dtype):
902891

903892
result = dpnp.vdot(ia, b)
904893
expected = numpy.vdot(a, b)
905-
_assert_selective_dtype_allclose(result, expected, dtype)
894+
assert_dtype_allclose(result, expected)
906895

907896
result = dpnp.vdot(b, ia)
908897
expected = numpy.vdot(b, a)
909-
_assert_selective_dtype_allclose(result, expected, dtype)
898+
assert_dtype_allclose(result, expected)
910899

911900
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
912901
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)