From 782ddc5f59631319a201d04cf88b142ab87e7e14 Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Sun, 21 Jan 2018 10:03:56 +0800 Subject: [PATCH] follow comments --- paddle/operators/math/matmul.h | 2 +- paddle/operators/matmul_op.cc | 4 ++-- paddle/operators/matmul_op.h | 2 +- python/paddle/v2/fluid/tests/test_matmul_op.py | 9 +++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/paddle/operators/math/matmul.h b/paddle/operators/math/matmul.h index 88341412fbc..ae7f1fe9be5 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 d395dfd81bb..3336978c8d8 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 4935db839cb..fe6a97465f8 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 7151b1f5c80..2dba25e17d3 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 -- GitLab