Skip to content

Commit adc32ad

Browse files
committed
improve coverage
1 parent 927d898 commit adc32ad

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

dpnp/dpnp_utils/dpnp_utils_einsum.py

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,6 @@ def _compute_size_by_dict(indices, idx_dict):
109109
return ret
110110

111111

112-
def _compute_size(start, shape):
113-
"""
114-
Compute the total size of a multi-dimensional array starting from a given index.
115-
116-
Parameters
117-
----------
118-
start : int
119-
The starting index from which to compute the size.
120-
shape : tuple
121-
The shape of the multi-dimensional array.
122-
123-
Returns
124-
-------
125-
out : int
126-
The total size of the array.
127-
128-
"""
129-
ret = 1
130-
for i in range(start, len(shape)):
131-
ret *= shape[i]
132-
return ret
133-
134-
135112
def _einsum_diagonals(input_subscripts, operands):
136113
"""
137114
Adopted from _einsum_diagonals in cupy/core/_einsum.py
@@ -818,11 +795,11 @@ def _parse_int_subscript(list_subscript):
818795
"For this input type lists must contain "
819796
"either int or Ellipsis"
820797
) from e
821-
if isinstance(s, int):
822-
if not 0 <= s < len(_einsum_symbols):
823-
raise ValueError(
824-
f"subscript is not within the valid range [0, {len(_einsum_symbols)})."
825-
)
798+
799+
if not 0 <= s < len(_einsum_symbols):
800+
raise ValueError(
801+
f"subscript is not within the valid range [0, {len(_einsum_symbols)})."
802+
)
826803
str_subscript += _einsum_symbols[s]
827804
return str_subscript
828805

dpnp/dpnp_utils/dpnp_utils_statistics.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
import dpnp
28-
from dpnp.dpnp_utils import get_usm_allocations
28+
from dpnp.dpnp_utils import get_usm_allocations, map_dtype_to_device
2929

3030
__all__ = ["dpnp_cov"]
3131

@@ -73,12 +73,7 @@ def _get_2dmin_array(x, dtype):
7373
dtypes.append(y.dtype)
7474
dtype = dpnp.result_type(*dtypes)
7575
# TODO: remove when dpctl.result_type() is returned dtype based on fp64
76-
fp64 = queue.sycl_device.has_aspect_fp64
77-
if not fp64:
78-
if dtype == dpnp.float64:
79-
dtype = dpnp.float32
80-
elif dtype == dpnp.complex128:
81-
dtype = dpnp.complex64
76+
dtype = map_dtype_to_device(dtype, queue.sycl_device)
8277

8378
X = _get_2dmin_array(m, dtype)
8479
if y is not None:

tests/test_linalg.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,13 @@ def test_einsum_error1(self):
719719
# different size for same label 5 != 4
720720
assert_raises(ValueError, inp.einsum, "ii", a)
721721

722+
a = inp.arange(25).reshape(5, 5)
723+
# subscript is not within the valid range [0, 52)
724+
assert_raises(ValueError, inp.einsum, a, [53, 53])
725+
726+
# output subscript includes repeated labels
727+
assert_raises(ValueError, inp.einsum, "ii>jj", a)
728+
722729
@pytest.mark.parametrize("do_opt", [True, False])
723730
@pytest.mark.parametrize("xp", [numpy, inp])
724731
def test_einsum_error2(self, do_opt, xp):
@@ -1740,6 +1747,17 @@ def test_output_order(self):
17401747
tmp = inp.einsum("...ft,mf->...mt", d, c, order="a", optimize=opt)
17411748
assert tmp.flags.c_contiguous
17421749

1750+
def test_einsum_path(self):
1751+
# Test einsum path for covergae
1752+
a = numpy.random.rand(1, 2, 3, 4)
1753+
b = numpy.random.rand(4, 3, 2, 1)
1754+
a_dp = inp.array(a)
1755+
b_dp = inp.array(b)
1756+
expected = numpy.einsum_path("ijkl,dcba->dcba", a, b)
1757+
result = inp.einsum_path("ijkl,dcba->dcba", a_dp, b_dp)
1758+
assert expected[0] == result[0]
1759+
assert expected[1] == result[1]
1760+
17431761

17441762
class TestInv:
17451763
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)