Merge pull request #3014 from wangkuiyi/formalize_eigen

Slight simplification of eigen.h in hope to make it more readable.
cblas_new
QI JUN 8 years ago committed by GitHub
commit 85dff17985

@ -61,25 +61,24 @@ struct EigenTensor {
} }
}; };
template <typename T, int MajorType = Eigen::RowMajor,
typename IndexType = Eigen::DenseIndex>
struct EigenMatrix : public EigenTensor<T, 2, MajorType, IndexType> {};
template <typename T, int MajorType = Eigen::RowMajor, template <typename T, int MajorType = Eigen::RowMajor,
typename IndexType = Eigen::DenseIndex> typename IndexType = Eigen::DenseIndex>
struct EigenVector : public EigenTensor<T, 1, MajorType, IndexType> { struct EigenVector : public EigenTensor<T, 1, MajorType, IndexType> {
// Flatten is to reshape a Tensor into a one dimension EigenVector // Flatten reshapes a Tensor into an EigenVector.
using Parent = EigenTensor<T, 1, MajorType, IndexType>; static typename EigenVector::Type Flatten(Tensor& tensor) {
static typename Parent::Type Flatten(Tensor& tensor) { return EigenVector::From(
return Parent::From(tensor, tensor, make_ddim({static_cast<int>(product(tensor.dims_))}));
make_ddim({static_cast<int>(product(tensor.dims_))}));
} }
static typename Parent::ConstType Flatten(const Tensor& tensor) { static typename EigenVector::ConstType Flatten(const Tensor& tensor) {
return Parent::From(tensor, return EigenVector::From(
make_ddim({static_cast<int>(product(tensor.dims_))})); tensor, make_ddim({static_cast<int>(product(tensor.dims_))}));
} }
}; };
template <typename T, int MajorType = Eigen::RowMajor,
typename IndexType = Eigen::DenseIndex>
using EigenMatrix = EigenTensor<T, 2, MajorType, IndexType>;
} // namespace framework } // namespace framework
} // namespace paddle } // namespace paddle

Loading…
Cancel
Save