From 395cb561aaa61be7edd5a17a5d95e5ae02c21d51 Mon Sep 17 00:00:00 2001 From: zhupengyang Date: Fri, 9 Oct 2020 17:33:00 +0800 Subject: [PATCH] refine logsumexp error message and docs (#27713) --- .../operators/reduce_ops/logsumexp_op.cc | 28 +++++++++---------- python/paddle/tensor/math.py | 4 +-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/paddle/fluid/operators/reduce_ops/logsumexp_op.cc b/paddle/fluid/operators/reduce_ops/logsumexp_op.cc index 7cd164bfd3..9d2639c103 100644 --- a/paddle/fluid/operators/reduce_ops/logsumexp_op.cc +++ b/paddle/fluid/operators/reduce_ops/logsumexp_op.cc @@ -32,7 +32,7 @@ class LogsumexpOp : public framework::OperatorWithKernel { PADDLE_ENFORCE_LE(x_rank, 4, platform::errors::InvalidArgument( "The input tensor X's dimensions of logsumexp " - "should be less equal than 4. But received X's " + "should be less or equal than 4. But received X's " "dimensions = %d, X's shape = [%s].", x_rank, x_dims)); auto axis = ctx->Attrs().Get>("axis"); @@ -45,20 +45,18 @@ class LogsumexpOp : public framework::OperatorWithKernel { axis.size())); for (size_t i = 0; i < axis.size(); i++) { - PADDLE_ENFORCE_LT( - axis[i], x_rank, - platform::errors::InvalidArgument( - "axis[%d] should be in the " - "range [-dimension(X), dimension(X)] " - "where dimesion(X) is %d. But received axis[i] = %d.", - i, x_rank, axis[i])); - PADDLE_ENFORCE_GE( - axis[i], -x_rank, - platform::errors::InvalidArgument( - "axis[%d] should be in the " - "range [-dimension(X), dimension(X)] " - "where dimesion(X) is %d. But received axis[i] = %d.", - i, x_rank, axis[i])); + PADDLE_ENFORCE_LT(axis[i], x_rank, + platform::errors::InvalidArgument( + "axis[%d] should be in the " + "range [-D, D), where D is the dimensions of X and " + "D is %d. But received axis[%d] = %d.", + i, x_rank, i, axis[i])); + PADDLE_ENFORCE_GE(axis[i], -x_rank, + platform::errors::InvalidArgument( + "axis[%d] should be in the " + "range [-D, D), where D is the dimensions of X and " + "D is %d. But received axis[%d] = %d.", + i, x_rank, i, axis[i])); if (axis[i] < 0) { axis[i] += x_rank; } diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index 51dc771281..34d15ed0ba 100755 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -999,7 +999,7 @@ def logsumexp(x, axis=None, keepdim=False, name=None): This OP calculates the log of the sum of exponentials of ``x`` along ``axis`` . .. math:: - logsumexp(x) = \log\sum exp(x) + logsumexp(x) = \\log\\sum exp(x) Args: x (Tensor): The input Tensor with data type float32, float64. @@ -1030,8 +1030,6 @@ def logsumexp(x, axis=None, keepdim=False, name=None): import paddle - paddle.disable_static() - x = paddle.to_tensor([[-1.5, 0., 2.], [3., 1.2, -2.4]]) out1 = paddle.logsumexp(x) # [3.4691226] out2 = paddle.logsumexp(x, 1) # [2.15317821, 3.15684602] -- GitLab