提交 ac28fad6 编写于 作者: Y Yi Wang

Add type assertion in Variable::Get

上级 58efbf41
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include <typeindex> #include <typeindex>
#include <typeinfo> #include <typeinfo>
#include "paddle/platform/assert.h"
namespace paddle { namespace paddle {
namespace framework { namespace framework {
...@@ -23,6 +25,9 @@ class Variable { ...@@ -23,6 +25,9 @@ class Variable {
public: public:
template <typename T> template <typename T>
const T& Get() const { const T& Get() const {
PADDLE_ASSERT(holder_ != nullptr);
PADDLE_ASSERT(std::type_index(typeid(T)) ==
std::type_index(holder_->Type()));
return *static_cast<const T*>(holder_->Ptr()); return *static_cast<const T*>(holder_->Ptr());
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册