Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ def __call__(
return out
return dpnp_array._create_from_usm_ndarray(res_usm)

def outer(self, x1, x2):
_x1 = x1[(Ellipsis,) + (None,) * x2.ndim]
_x2 = x2[(None,) * x1.ndim + (Ellipsis,)]
return self.__call__(_x1, _x2)


class DPNPAngle(DPNPUnaryFunc):
"""Class that implements dpnp.angle unary element-wise functions."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_flipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_arange_4d(self, axis, dtype):
)
def test_lr_equivalent(self, dtype):
dp_a = dpnp.arange(4, dtype=dtype)
dp_a = dp_a[:, dpnp.newaxis] + dp_a[dpnp.newaxis, :]
dp_a = dpnp.add.outer(dp_a, dp_a)
assert_equal(dpnp.flip(dp_a, 1), dpnp.fliplr(dp_a))

np_a = numpy.arange(4, dtype=dtype)
Expand All @@ -72,7 +72,7 @@ def test_lr_equivalent(self, dtype):
)
def test_ud_equivalent(self, dtype):
dp_a = dpnp.arange(4, dtype=dtype)
dp_a = dp_a[:, dpnp.newaxis] + dp_a[dpnp.newaxis, :]
dp_a = dpnp.add.outer(dp_a, dp_a)
assert_equal(dpnp.flip(dp_a, 0), dpnp.flipud(dp_a))

np_a = numpy.arange(4, dtype=dtype)
Expand Down
34 changes: 34 additions & 0 deletions tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -3142,3 +3142,37 @@ def test_bitwise_1array_input():
result = dpnp.add(1, x, dtype="f4")
expected = numpy.add(1, x_np, dtype="f4")
assert_dtype_allclose(result, expected)


@pytest.mark.parametrize(
"x_shape",
[
(),
(2),
(3, 4),
(3, 4, 5),
],
)
@pytest.mark.parametrize(
"y_shape",
[
(),
(2),
(3, 4),
(3, 4, 5),
],
)
def test_elemenwise_outer(x_shape, y_shape):
x_np = numpy.random.random(x_shape)
y_np = numpy.random.random(y_shape)
expected = numpy.multiply.outer(x_np, y_np)

x = dpnp.asarray(x_np)
y = dpnp.asarray(y_np)
result = dpnp.multiply.outer(x, y)

assert_dtype_allclose(result, expected)

if x_shape != () and y_shape != ():
result_outer = dpnp.outer(x, y)
assert dpnp.allclose(result.flatten(), result_outer.flatten())