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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -2965,7 +2965,7 @@ def outer(x: Tensor, y: Tensor, name: str | None = None) -> Tensor:
ny = y.reshape((1, -1))

if in_dynamic_mode():
return _C_ops.matmul(nx, ny, False, False)
return _C_ops.multiply(nx, ny)

def __check_input(x, y):
var_names = {'x': x, 'y': y}
Expand All @@ -2979,7 +2979,7 @@ def __check_input(x, y):

__check_input(nx, ny)
if in_pir_mode():
return _C_ops.matmul(nx, ny, False, False)
return _C_ops.multiply(nx, ny)
else:
helper = LayerHelper('outer', **locals())
out = helper.create_variable_for_type_inference(dtype=nx.dtype)
Expand Down
24 changes: 24 additions & 0 deletions test/legacy_test/test_outer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ def test_multiply_static(self):
res = self._run_static_graph_case(x_data, y_data)
np.testing.assert_allclose(res, np.outer(x_data, y_data), rtol=1e-05)

# test static computation graph: 3-d int32 big array
x_data = np.random.randint(-80000, 80000, [5, 10, 10]).astype(np.int32)
y_data = np.random.randint(-80000, 80000, [2, 10]).astype(np.int32)
res = self._run_static_graph_case(x_data, y_data)
np.testing.assert_allclose(res, np.outer(x_data, y_data), rtol=1e-05)

# test static computation graph: 3-d int64 big array
x_data = np.random.randint(-80000, 80000, [5, 10, 10]).astype(np.int64)
y_data = np.random.randint(-80000, 80000, [2, 10]).astype(np.int64)
res = self._run_static_graph_case(x_data, y_data)
np.testing.assert_allclose(res, np.outer(x_data, y_data), rtol=1e-05)

def test_multiply_dynamic(self):
# test dynamic computation graph: 3-d array
x_data = np.random.rand(5, 10, 10).astype(np.float64)
Expand Down Expand Up @@ -138,6 +150,18 @@ def test_multiply_dynamic(self):
res = self._run_dynamic_graph_case(x_data, y_data)
np.testing.assert_allclose(res, np.outer(x_data, y_data), rtol=1e-05)

# test dynamic computation graph: 3-d int32 big array
x_data = np.random.randint(-80000, 80000, [5, 10, 10]).astype(np.int32)
y_data = np.random.randint(-80000, 80000, [2, 10]).astype(np.int32)
res = self._run_dynamic_graph_case(x_data, y_data)
np.testing.assert_allclose(res, np.outer(x_data, y_data), rtol=1e-05)

# test dynamic computation graph: 3-d int64 big array
x_data = np.random.randint(-80000, 80000, [5, 10, 10]).astype(np.int64)
y_data = np.random.randint(-80000, 80000, [2, 10]).astype(np.int64)
res = self._run_dynamic_graph_case(x_data, y_data)
np.testing.assert_allclose(res, np.outer(x_data, y_data), rtol=1e-05)


class TestMultiplyError(unittest.TestCase):

Expand Down