Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions dpnp/tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,30 @@ def test_matmul_with_offsets(self, sh1, sh2):
expected = a[1] @ b[1]
assert_dtype_allclose(result, expected)

def test_rmatmul_dpnp_array(self):
a = dpnp.ones(10)
b = dpnp.ones(10)

class A(dpnp.ndarray):
def __init__(self, x):
self._array_obj = x.get_array()

def __matmul__(self, other):
return NotImplemented

a1 = A(a)

result = a1 @ b
expected = dpnp.matmul(a, b)
assert_dtype_allclose(result, expected)

def test_rmatmul_numpy_array(self):
a = dpnp.ones(10)
b = numpy.ones(10)

with pytest.raises(TypeError):
b @ a


class TestMatmulInplace:
ALL_DTYPES = get_all_dtypes(no_none=True)
Expand Down
67 changes: 67 additions & 0 deletions dpnp/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import dpctl.tensor as dpt
import numpy
import pytest

import dpnp


class TestIsSupportedArrayOrScalar:
@pytest.mark.parametrize(
"array",
[
dpnp.array([1, 2, 3]),
dpnp.array(1),
dpt.asarray([1, 2, 3]),
],
)
def test_valid_arrays(self, array):
assert dpnp.is_supported_array_or_scalar(array)

@pytest.mark.parametrize(
"value",
[
42,
True,
"1",
],
)
def test_valid_scalars(self, value):
assert dpnp.is_supported_array_or_scalar(value)

@pytest.mark.parametrize(
"array",
[
[1, 2, 3],
(1, 2, 3),
None,
numpy.array([1, 2, 3]),
],
)
def test_invalid_arrays(self, array):
assert not dpnp.is_supported_array_or_scalar(array)


class TestSynchronizeArrayData:
@pytest.mark.parametrize(
"array",
[
dpnp.array([1, 2, 3]),
dpt.asarray([1, 2, 3]),
],
)
def test_synchronize_array_data(self, array):
try:
dpnp.synchronize_array_data(array)
except Exception as e:
pytest.fail(f"synchronize_array_data failed: {e}")

@pytest.mark.parametrize(
"input",
[
[1, 2, 3],
numpy.array([1, 2, 3]),
],
)
def test_unsupported_type(self, input):
with pytest.raises(TypeError):
dpnp.synchronize_array_data(input)
Loading