Skip to content

Commit 3b5f426

Browse files
authored
Merge branch 'master' into update-tests-part-2
2 parents 0b78437 + 11487c5 commit 3b5f426

File tree

7 files changed

+81
-38
lines changed

7 files changed

+81
-38
lines changed

dpnp/dpnp_iface_manipulation.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,11 +2170,12 @@ def insert(arr, obj, values, axis=None):
21702170
----------
21712171
arr : array_like
21722172
Input array.
2173-
obj : {slice, int, array-like of ints}
2173+
obj : {slice, int, array-like of ints or bools}
21742174
Object that defines the index or indices before which `values` is
21752175
inserted. It supports multiple insertions when `obj` is a single
21762176
scalar or a sequence with one element (similar to calling insert
21772177
multiple times).
2178+
Boolean indices are treated as a mask of elements to insert.
21782179
values : array_like
21792180
Values to insert into `arr`. If the type of `values` is different
21802181
from that of `arr`, `values` is converted to the type of `arr`.
@@ -2266,20 +2267,12 @@ def insert(arr, obj, values, axis=None):
22662267
obj, sycl_queue=params.exec_q, usm_type=params.usm_type
22672268
)
22682269
if indices.dtype == dpnp.bool:
2269-
warnings.warn(
2270-
"In the future insert will treat boolean arrays and array-likes"
2271-
" as a boolean index instead of casting it to integers",
2272-
FutureWarning,
2273-
stacklevel=2,
2274-
)
2275-
indices = indices.astype(dpnp.intp)
2276-
# TODO: Code after warning period:
2277-
# if indices.ndim != 1:
2278-
# raise ValueError(
2279-
# "boolean array argument `obj` to insert must be "
2280-
# "one-dimensional"
2281-
# )
2282-
# indices = dpnp.nonzero(indices)[0]
2270+
if indices.ndim != 1:
2271+
raise ValueError(
2272+
"boolean array argument obj to insert "
2273+
"must be one dimensional"
2274+
)
2275+
indices = dpnp.flatnonzero(indices)
22832276
elif indices.ndim > 1:
22842277
raise ValueError(
22852278
"index array argument `obj` to insert must be one-dimensional "

dpnp/dpnp_utils/dpnp_utils_statistics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _get_2dmin_array(x, dtype):
153153
elif x.ndim == 1:
154154
x = x[dpnp.newaxis, :]
155155

156-
if not rowvar and x.shape[0] != 1:
156+
if not rowvar and x.ndim != 1:
157157
x = x.T
158158

159159
if x.dtype != dtype:

dpnp/tests/test_manipulation.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
import numpy
55
import pytest
66
from dpctl.tensor._numpy_helper import AxisError
7-
from numpy.testing import assert_array_equal, assert_equal, assert_raises
7+
from numpy.testing import (
8+
assert_array_equal,
9+
assert_equal,
10+
assert_raises,
11+
)
812

913
import dpnp
1014

@@ -573,16 +577,34 @@ def test_ndarray_obj_values(self, obj, values):
573577
result = dpnp.insert(ia, obj, values)
574578
assert_equal(result, expected)
575579

576-
@pytest.mark.filterwarnings("ignore::FutureWarning")
580+
@testing.with_requires("numpy>=2.2")
577581
@pytest.mark.parametrize(
578582
"obj",
579-
[True, [False], numpy.array([True] * 4), [True, False, True, False]],
583+
[[False], numpy.array([True] * 4), [True, False, True, False]],
580584
)
581585
def test_boolean_obj(self, obj):
586+
if not isinstance(obj, numpy.ndarray):
587+
# numpy.insert raises exception
588+
# TODO: remove once NumPy resolves that
589+
obj = numpy.array(obj)
590+
582591
a = numpy.array([1, 2, 3])
583592
ia = dpnp.array(a)
584593
assert_equal(dpnp.insert(ia, obj, 9), numpy.insert(a, obj, 9))
585594

595+
@testing.with_requires("numpy>=2.2")
596+
@pytest.mark.parametrize("xp", [dpnp, numpy])
597+
@pytest.mark.parametrize(
598+
"obj_data",
599+
[True, [[True, False], [True, False]]],
600+
ids=["0d", "2d"],
601+
)
602+
def test_boolean_obj_error(self, xp, obj_data):
603+
a = xp.array([1, 2, 3])
604+
obj = xp.array(obj_data)
605+
with pytest.raises(ValueError):
606+
xp.insert(a, obj, 9)
607+
586608
def test_1D_array(self):
587609
a = numpy.array([1, 2, 3])
588610
ia = dpnp.array(a)
@@ -1394,6 +1416,9 @@ def test_overflow(self, a):
13941416
expected = numpy.trim_zeros(a)
13951417
assert_array_equal(result, expected)
13961418

1419+
# TODO: modify once SAT-7616
1420+
# numpy 2.2 validates trim rules
1421+
@testing.with_requires("numpy<2.2")
13971422
def test_trim_no_rule(self):
13981423
a = numpy.array([0, 0, 1, 0, 2, 3, 4, 0])
13991424
ia = dpnp.array(a)

dpnp/tests/test_statistics.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
get_float_complex_dtypes,
1818
has_support_aspect64,
1919
)
20+
from .third_party.cupy.testing import with_requires
2021

2122

2223
class TestAverage:
@@ -654,23 +655,38 @@ def test_correlate_another_sycl_queue(self):
654655
dpnp.correlate(a, v)
655656

656657

657-
@pytest.mark.parametrize(
658-
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
659-
)
660-
def test_cov_rowvar(dtype):
661-
a = dpnp.array([[0, 2], [1, 1], [2, 0]], dtype=dtype)
662-
b = numpy.array([[0, 2], [1, 1], [2, 0]], dtype=dtype)
663-
assert_allclose(dpnp.cov(a.T), dpnp.cov(a, rowvar=False))
664-
assert_allclose(numpy.cov(b, rowvar=False), dpnp.cov(a, rowvar=False))
658+
class TestCov:
659+
@pytest.mark.parametrize(
660+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
661+
)
662+
def test_false_rowvar_dtype(self, dtype):
663+
a = numpy.array([[0, 2], [1, 1], [2, 0]], dtype=dtype)
664+
ia = dpnp.array(a)
665665

666+
assert_allclose(dpnp.cov(ia.T), dpnp.cov(ia, rowvar=False))
667+
assert_allclose(dpnp.cov(ia, rowvar=False), numpy.cov(a, rowvar=False))
666668

667-
@pytest.mark.parametrize(
668-
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
669-
)
670-
def test_cov_1D_rowvar(dtype):
671-
a = dpnp.array([[0, 1, 2]], dtype=dtype)
672-
b = numpy.array([[0, 1, 2]], dtype=dtype)
673-
assert_allclose(numpy.cov(b, rowvar=False), dpnp.cov(a, rowvar=False))
669+
# numpy 2.2 properly transposes 2d array when rowvar=False
670+
@with_requires("numpy>=2.2")
671+
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
672+
def test_false_rowvar_1x3(self):
673+
a = numpy.array([[0, 1, 2]])
674+
ia = dpnp.array(a)
675+
676+
expected = numpy.cov(a, rowvar=False)
677+
result = dpnp.cov(ia, rowvar=False)
678+
assert_allclose(expected, result)
679+
680+
# numpy 2.2 properly transposes 2d array when rowvar=False
681+
@with_requires("numpy>=2.2")
682+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
683+
def test_true_rowvar(self):
684+
a = numpy.ones((3, 1))
685+
ia = dpnp.array(a)
686+
687+
expected = numpy.cov(a, ddof=0, rowvar=True)
688+
result = dpnp.cov(ia, ddof=0, rowvar=True)
689+
assert_allclose(expected, result)
674690

675691

676692
@pytest.mark.parametrize("axis", [None, 0, 1])

dpnp/tests/test_umath.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def get_id(val):
7373

7474

7575
# implement missing umaths and to remove the list
76-
# SAT-7323 bitwise_count
7776
new_umaths_numpy_20 = [
78-
"bitwise_count",
77+
"bitwise_count", # SAT-7323
78+
"matvec", # SAT-7615
79+
"vecmat", # SAT-7615
7980
]
8081

8182

dpnp/tests/third_party/cupy/manipulation_tests/test_add_remove.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,17 @@ def test_trim_back_zeros(self, xp, dtype):
387387
a = xp.array([1, 0, 2, 3, 0, 5, 0, 0, 0], dtype=dtype)
388388
return xp.trim_zeros(a, trim=self.trim)
389389

390+
# TODO: remove once SAT-7616
391+
@testing.with_requires("numpy<2.2")
390392
@testing.for_all_dtypes()
391393
def test_trim_zero_dim(self, dtype):
392394
for xp in (numpy, cupy):
393395
a = testing.shaped_arange((), xp, dtype)
394396
with pytest.raises(TypeError):
395397
xp.trim_zeros(a, trim=self.trim)
396398

399+
# TODO: remove once SAT-7616
400+
@testing.with_requires("numpy<2.2")
397401
@testing.for_all_dtypes()
398402
def test_trim_ndim(self, dtype):
399403
for xp in (numpy, cupy):

dpnp/tests/third_party/cupy/statistics_tests/test_correlation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
import dpnp as cupy
7-
from dpnp.tests.helper import has_support_aspect64
7+
from dpnp.tests.helper import has_support_aspect64, numpy_version
88
from dpnp.tests.third_party.cupy import testing
99

1010

@@ -127,10 +127,14 @@ def check_raises(
127127
)
128128

129129
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
130+
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
130131
def test_cov(self):
131132
self.check((2, 3))
132133
self.check((2,), (2,))
133-
self.check((1, 3), (1, 3), rowvar=False)
134+
if numpy_version() >= "2.2.0":
135+
# TODO: enable once numpy 2.2 resolves ValueError
136+
# self.check((1, 3), (1, 3), rowvar=False)
137+
self.check((1, 3), (1, 1), rowvar=False) # TODO: remove
134138
self.check((2, 3), (2, 3), rowvar=False)
135139
self.check((2, 3), bias=True)
136140
self.check((2, 3), ddof=2)

0 commit comments

Comments
 (0)