Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,16 @@ def outer(x: Tensor, y: Tensor, name: str | None = None) -> Tensor:
else:
ny = y.reshape((1, -1))

if x.dtype in [
paddle.int32,
paddle.int64,
DataType.INT32,
DataType.INT64,
VarDesc.VarType.INT32,
VarDesc.VarType.INT64,
]:
return nx * ny

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

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