提交 045470cf 编写于 作者: Y Yi Wang

Slight simplification of eigen.h in hope to make it more readable.

上级 6129ab42
...@@ -61,25 +61,24 @@ struct EigenTensor { ...@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册