You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In functions const T* Tensor::data() const and T* Tensor::data(), the inner type holder_ holds must be the same as T. It is implemented by comparing hash codes in the current version, i.e., holder_->type().hash_code() == typeid(T).hash_code().
However, C++ does not guarantee the hash codes of different types must be different. It is recommended to change it to be holder_->type() == std::type_index(typeid(T)).
Inside the first for loop of function void FileReader::ReadNext(std::vector<LoDTensor> *out), std::vector<LodTensor>::at is called to access the data in the read-out result out. Therefore, std::vector<LodTensor>::at would check the size bound of out during each loop and thus it is inefficient.
A better choice is to add PADDLE_ENFORCE_EQ to compare out->size() to dims_.size() before the loop, rather than check the bounds in each loop.
The text was updated successfully, but these errors were encountered:
Bug in paddle/fluid/framework/tensor_impl.h
In functions
const T* Tensor::data() const
andT* Tensor::data()
, the inner typeholder_
holds must be the same asT
. It is implemented by comparing hash codes in the current version, i.e.,holder_->type().hash_code() == typeid(T).hash_code()
.However, C++ does not guarantee the hash codes of different types must be different. It is recommended to change it to be
holder_->type() == std::type_index(typeid(T))
.Inefficient code in paddle/fluid/framework/reader.cc
Inside the first
for
loop of functionvoid FileReader::ReadNext(std::vector<LoDTensor> *out)
,std::vector<LodTensor>::at
is called to access the data in the read-out resultout
. Therefore,std::vector<LodTensor>::at
would check the size bound ofout
during each loop and thus it is inefficient.A better choice is to add
PADDLE_ENFORCE_EQ
to compareout->size()
todims_.size()
before the loop, rather than check the bounds in each loop.The text was updated successfully, but these errors were encountered: