diff --git a/paddle/operators/math/matmul.h b/paddle/operators/math/matmul.h index 88341412fbc62cea9bb435326f0b31afb45e23f9..ae7f1fe9be5066a0ac0ac522849d481fc66a19be 100644 --- a/paddle/operators/math/matmul.h +++ b/paddle/operators/math/matmul.h @@ -49,7 +49,7 @@ class MatMulFunctor { "The dimensions of X and Y must be the same, and both of " "them should be %d-dimensional.", dim_b.size()); - // The front rank-2 dimensions are accumulated on the batch_count, and the + // The first rank-2 dimensions are accumulated on the batch_count, and the // last two dimensions are used for matrix multiplication. for (int j = 0; j < dim_a.size() - 2; ++j) { PADDLE_ENFORCE_EQ(dim_b[j], dim_a[j], diff --git a/paddle/operators/matmul_op.cc b/paddle/operators/matmul_op.cc index d395dfd81bb48921058ff2f08bbada057ccd73fe..3336978c8d8d94c69b986970274661a01ad2161d 100644 --- a/paddle/operators/matmul_op.cc +++ b/paddle/operators/matmul_op.cc @@ -51,7 +51,7 @@ class MatMulOp : public framework::OperatorWithKernel { "them should be %d-dimensional.", dim_x.size()); - // The front rank-2 dimensions are accumulated on the batch_count, and the + // The first rank-2 dimensions are accumulated on the batch_count, and the // last two dimensions are used for matrix multiplication. for (int j = 0; j < dim_x.size() - 2; ++j) { PADDLE_ENFORCE_EQ(dim_y[j], dim_x[j], @@ -196,7 +196,7 @@ The differences are: - When the rank of the input data is less than or equal to 3, it is similar to the `numpy.matmul` function. - When the rank of the input is greater than 3, the rank of X and - Y must be equal, and the front `rank - 2` dimensions must be equal. + Y must be equal, and the first `rank - 2` dimensions must be equal. - We add `transpose_X` and `transpose_Y` flags. Both the input `X` and `Y` can carry the LoD (Level of Details) information, diff --git a/paddle/operators/matmul_op.h b/paddle/operators/matmul_op.h index 4935db839cb4d8f0faed964c929363f7bfef697b..fe6a97465f8992281c909d4600bcfd8121d6a64a 100644 --- a/paddle/operators/matmul_op.h +++ b/paddle/operators/matmul_op.h @@ -138,7 +138,7 @@ class MatMulGradKernel : public framework::OpKernel { } int batch_count = 0; - // The front rank-2 dimensions are accumulated on the batch_count, and the + // The first rank-2 dimensions are accumulated on the batch_count, and the // last two dimensions are used for matrix multiplication. if (x_dims.size() > 3) { batch_count = accumulate(x_dims.begin(), x_dims.end() - 2, 1, diff --git a/python/paddle/v2/fluid/tests/test_matmul_op.py b/python/paddle/v2/fluid/tests/test_matmul_op.py index 7151b1f5c804920b4d67ea6429b2c20afe704126..2dba25e17d3bf72563a44f629e94949302688b39 100644 --- a/python/paddle/v2/fluid/tests/test_matmul_op.py +++ b/python/paddle/v2/fluid/tests/test_matmul_op.py @@ -127,6 +127,7 @@ for dim_X in [1, 2, 3]: }) +# Test case n-dim def generate_compatible_shapes(dim, transpose_X, transpose_Y): M = 2 N = 4 @@ -135,14 +136,14 @@ def generate_compatible_shapes(dim, transpose_X, transpose_Y): shape_Y = [2 for _ in range(dim - 2)] if transpose_X: - shape_X = shape_X + [K, M] + shape_X += [K, M] else: - shape_X = shape_X + [M, K] + shape_X += [M, K] if transpose_Y: - shape_Y = shape_Y + [N, K] + shape_Y += [N, K] else: - shape_Y = shape_Y + [K, N] + shape_Y += [K, N] return shape_X, shape_Y