From 5139e6c740f9829234de3cc4ed5a3fcd56e2331c Mon Sep 17 00:00:00 2001 From: Yang Yu Date: Fri, 29 Dec 2017 12:57:57 +0800 Subject: [PATCH] Follow comments --- paddle/framework/executor.cc | 6 +++--- paddle/framework/tensor_util.h | 4 ++-- paddle/framework/tensor_util_test.cc | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/paddle/framework/executor.cc b/paddle/framework/executor.cc index de4d3395eb..bf1f0471cc 100644 --- a/paddle/framework/executor.cc +++ b/paddle/framework/executor.cc @@ -59,11 +59,11 @@ static void CreateTensor(Variable* var, proto::VarDesc::VarType var_type) { static void CheckTensorNANOrInf(const std::string& name, const framework::Tensor& tensor) { - if (tensor.type().hash_code() != typeid(float).hash_code() && - tensor.type().hash_code() != typeid(double).hash_code()) { + if (tensor.memory_size() == 0) { return; } - if (tensor.memory_size() == 0) { + if (tensor.type().hash_code() != typeid(float).hash_code() && + tensor.type().hash_code() != typeid(double).hash_code()) { return; } PADDLE_ENFORCE(!framework::HasInf(tensor), "Tensor %s has Inf", name); diff --git a/paddle/framework/tensor_util.h b/paddle/framework/tensor_util.h index a86fab2925..6a21f8db1e 100644 --- a/paddle/framework/tensor_util.h +++ b/paddle/framework/tensor_util.h @@ -210,10 +210,10 @@ inline void CopyToVector(const Tensor& src, std::vector* dst) { } // Returns true if a tensor contains NAN, i.e., Not A Number. -extern bool HasNAN(const framework::Tensor& tensor); +bool HasNAN(const framework::Tensor& tensor); // Returns true if a tensor contains Inf, i.e., Infinity. -extern bool HasInf(const framework::Tensor& tensor); +bool HasInf(const framework::Tensor& tensor); inline void SerializeToStream(std::ostream& os, const Tensor& tensor, const platform::DeviceContext& dev_ctx) { diff --git a/paddle/framework/tensor_util_test.cc b/paddle/framework/tensor_util_test.cc index f00ce79548..0dc5166fca 100644 --- a/paddle/framework/tensor_util_test.cc +++ b/paddle/framework/tensor_util_test.cc @@ -231,7 +231,7 @@ TEST(CopyToVector, Tensor) { #endif } -TEST(IsNAN, CPU) { +TEST(HasNAN, CPU) { using namespace paddle::framework; using namespace paddle::platform; Tensor src; @@ -243,7 +243,7 @@ TEST(IsNAN, CPU) { ASSERT_TRUE(HasNAN(src)); } -TEST(IsInf, CPU) { +TEST(HasInf, CPU) { using namespace paddle::framework; using namespace paddle::platform; Tensor src; -- GitLab