| 46 | |
| 47 | template <typename T> |
| 48 | T* GetMutable() { |
| 49 | if (!holder_) { |
| 50 | holder_.reset(new PlaceholderImpl<T>()); |
| 51 | } else { |
| 52 | // If holder_ is RawTensor, call holder_->Ptr() GetMutable again. Used for |
| 53 | // load_combine. |
| 54 | if (holder_->Type() == VarTypeTrait<RawTensor>::kId && |
| 55 | holder_->Type() != VarTypeTrait<T>::kId) { |
| 56 | return static_cast<RawTensor*>(holder_->Ptr())->GetMutable<T>(); |
| 57 | } |
| 58 | PADDLE_ENFORCE_EQ( |
| 59 | holder_->Type(), |
| 60 | VarTypeTrait<T>::kId, |
| 61 | common::errors::InvalidArgument( |
| 62 | "The Variable type must be %s, but the type it holds is %s.", |
| 63 | ToTypeName(VarTypeTrait<T>::kId), |
| 64 | ToTypeName(holder_->Type()))); |
| 65 | } |
| 66 | return static_cast<T*>(holder_->Ptr()); |
| 67 | } |
| 68 | |
| 69 | template <typename T> |
| 70 | bool IsType() const { |
no test coverage detected