1#ifndef PLAIN_INTERFACE_EIGEN_IMPL_H_
2#define PLAIN_INTERFACE_EIGEN_IMPL_H_
6#include <unsupported/Eigen/CXX11/Tensor>
10struct PlainInterface :
public MatrixInterface,
public TensorInterface,
public VectorInterface
39 template <std::
size_t Rank,
typename Derived,
typename Scalar>
51 template <std::
size_t Rank,
typename Derived,
typename Scalar>
63 template <std::
size_t Rank,
typename Derived,
typename Scalar>
74 template <std::
size_t Rank,
typename Derived,
typename Scalar>
86 template <std::
size_t Rank,
typename Derived>
92 const std::array<Indextype, Rank>& dims)
95 nda::dim<-9, -9, 1> first_dim;
96 first_dim.set_extent(dims[0]);
97 std::array<nda::dim<-9, -9, -9>, Rank - 1> shape_data;
98 for(std::size_t i = 1; i < Rank; i++) {
99 shape_data[i - 1].set_extent(dims[i]);
100 shape_data[i - 1].set_stride(std::accumulate(dims.begin(), dims.begin() + i, 1ul, std::multiplies<typename Derived::Scalar>()));
104 nda::dense_shape<Rank> block_shape(dims_tuple);
109 return construct<typename Derived::Scalar, Rank>(tensorview);
112 template <
typename Derived>
115 V = M.diagonal().head(n_elems);
118 template <
typename Derived>
120 svd(
const Eigen::MatrixBase<Derived>& M)
122#ifdef XPED_DONT_USE_BDCSVD
123 Eigen::JacobiSVD<MType<typename Derived::Scalar>> Jack;
125 Eigen::BDCSVD<MType<typename Derived::Scalar>> Jack;
128 Jack.compute(M, Eigen::ComputeThinU | Eigen::ComputeThinV);
129 return std::make_tuple(Jack.matrixU(), Jack.singularValues(), Jack.matrixV().adjoint());
132 template <
typename Scalar>
135 return V.matrix().asDiagonal();
CTF::Matrix< Scalar > MType
Definition: MatrixInterface_Cyclops_impl.cpp:13
CTF::Vector< Scalar > VType
Definition: PlainInterface_Cyclops_impl.cpp:33
static void setZero(MType< Scalar > &M)
Definition: MatrixInterface_Cyclops_impl.cpp:47
static void setConstant(MType< Scalar > &M, const Scalar &val)
Definition: MatrixInterface_Cyclops_impl.cpp:65
static MType< Scalar > construct_with_zero(const MIndextype &rows, const MIndextype &cols, CTF::World &world)
Definition: MatrixInterface_Cyclops_impl.cpp:32
static void print(MT &&M)
Definition: MatrixInterface_Cyclops_impl.cpp:343
static Scalar getVal(const MType< Scalar > &M, const MIndextype &row, const MIndextype &col)
Definition: MatrixInterface_Cyclops_impl.cpp:136
static void setRandom(MType< Scalar > &M)
Definition: MatrixInterface_Cyclops_impl.cpp:53
static MIndextype cols(const MType< Scalar > &M)
Definition: MatrixInterface_Cyclops_impl.cpp:90
static MType< typename ctf_traits< MT1 >::Scalar > difference(MT1 &&M1, MT2 &&M2)
Definition: MatrixInterface_Cyclops_impl.cpp:219
static MIndextype rows(const MType< Scalar > &M)
Definition: MatrixInterface_Cyclops_impl.cpp:84
static MType< Scalar > construct(const MIndextype &rows, const MIndextype &cols, CTF::World &world)
Definition: MatrixInterface_Cyclops_impl.cpp:26
static MType< typename ctf_traits< MT1 >::Scalar > add(MT1 &&M1, MT2 &&M2)
Definition: MatrixInterface_Cyclops_impl.cpp:210
static void scale(MType< Scalar > &M, const Scalar &val)
Definition: MatrixInterface_Cyclops_impl.cpp:228
CTF::Matrix< Scalar > MType
Definition: MatrixInterface_Cyclops_impl.hpp:40
static void set_block_from_tensor(Eigen::MatrixBase< Derived > &M, const Indextype &row, const Indextype &col, const Indextype &rows, const Indextype &cols, const Scalar &scale, const TType< Scalar, Rank > &T)
Definition: PlainInterface_Eigen_Array_impl.hpp:40
int Indextype
Definition: PlainInterface_Cyclops_impl.hpp:11
static std::tuple< MType< typename Derived::Scalar >, VType< typename Derived::Scalar >, MType< typename Derived::Scalar > > svd(const Eigen::MatrixBase< Derived > &M)
Definition: PlainInterface_Eigen_Array_impl.hpp:120
static void set_block_from_tensor(Eigen::MatrixBase< Derived > &&M, const Indextype &row, const Indextype &col, const Indextype &rows, const Indextype &cols, const Scalar &scale, const TType< Scalar, Rank > &T)
Definition: PlainInterface_Eigen_Array_impl.hpp:64
static void diagonal_head_matrix_to_vector(VType< typename Derived::Scalar > &V, const Eigen::MatrixBase< Derived > &M, const Indextype &n_elems)
Definition: PlainInterface_Eigen_Array_impl.hpp:113
static void add_to_block_from_tensor(Eigen::MatrixBase< Derived > &M, const Indextype &row, const Indextype &col, const Indextype &rows, const Indextype &cols, const Scalar &scale, const TType< Scalar, Rank > &T)
Definition: PlainInterface_Eigen_Array_impl.hpp:52
static void add_to_block_from_tensor(Eigen::MatrixBase< Derived > &&M, const Indextype &row, const Indextype &col, const Indextype &rows, const Indextype &cols, const Scalar &scale, const TType< Scalar, Rank > &T)
Definition: PlainInterface_Eigen_Array_impl.hpp:75
static void scale(MType< Scalar > &M, const Scalar &val)
Definition: MatrixInterface_Cyclops_impl.cpp:228
static MType< Scalar > vec_to_diagmat(const VType< Scalar > &V)
Definition: PlainInterface_Eigen_Array_impl.hpp:133
static TType< typename Derived::Scalar, Rank > tensor_from_matrix_block(const Eigen::MatrixBase< Derived > &M, const Indextype &row, const Indextype &col, const Indextype &rows, const Indextype &cols, const std::array< Indextype, Rank > &dims)
Definition: PlainInterface_Eigen_Array_impl.hpp:87
nda::dense_array< Scalar, Rank > TType
Definition: TensorInterface_Array_impl.hpp:44
static nda::internal::tuple_of_n< element_t, N > as_tuple(std::array< element_t, N > const &arr, std::index_sequence< Is... >)
Definition: TensorInterface_Array_impl.hpp:31
static void setZero(TType< Scalar, Rank > &T)
Definition: TensorInterface_Array_impl.hpp:95
static void setConstant(TType< Scalar, Rank > &T, const Scalar &val)
Definition: TensorInterface_Array_impl.hpp:107
static std::string print(const TType< Scalar, Rank > &T)
Definition: TensorInterface_Array_impl.hpp:389
static Scalar getVal(const TType< Scalar, Rank > &T, const std::array< Indextype, Rank > &index)
Definition: TensorInterface_Array_impl.hpp:119
static TType< Scalar, Rank > construct(const std::array< Indextype, Rank > &dims, mpi::XpedWorld &world=mpi::getUniverse())
Definition: TensorInterface_Array_impl.hpp:58
static void setRandom(TType< Scalar, Rank > &T)
Definition: TensorInterface_Array_impl.hpp:101
nda::const_dense_array_ref< Scalar, Rank > cMapTType
Definition: TensorInterface_Array_impl.hpp:51
static void setZero(VType< Scalar > &V)
Definition: VectorInterface_Cyclops_impl.cpp:34
static VType< Scalar > construct(const VIndextype &elems, CTF::World &world)
Definition: VectorInterface_Cyclops_impl.cpp:15
static VType< Scalar > construct_with_zero(const VIndextype &elems, CTF::World &world)
Definition: VectorInterface_Cyclops_impl.cpp:21
static void setRandom(VType< Scalar > &V)
Definition: VectorInterface_Cyclops_impl.cpp:40
static std::string print(const VType< Scalar > &V)
Definition: VectorInterface_Cyclops_impl.cpp:92
static void setConstant(VType< Scalar > &V, const Scalar &val)
Definition: VectorInterface_Cyclops_impl.cpp:46
static VType< Scalar > scale(VT1 &&V, const Scalar &val)
Definition: VectorInterface_Cyclops_impl.cpp:75
CTF::Vector< Scalar > VType
Definition: VectorInterface_Cyclops_impl.hpp:12