1#ifndef MATRIX_INTERFACE_EIGEN_IMPL_H_
2#define MATRIX_INTERFACE_EIGEN_IMPL_H_
8#include <unsupported/Eigen/MatrixFunctions>
17 template <
typename Scalar>
18 using MType = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
19 template <
typename Scalar>
20 using cMType =
const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
22 template <
typename Scalar>
24 template <
typename Scalar>
29 template <
typename Scalar>
32 template <
typename Scalar>
35 template <
typename Scalar>
39 template <
typename Derived>
40 static void setZero(Eigen::MatrixBase<Derived>& M);
42 template <
typename Derived>
43 static void setZero(Eigen::MatrixBase<Derived>&& M);
45 template <
typename Derived>
46 static void setRandom(Eigen::MatrixBase<Derived>& M, std::mt19937& engine);
48 template <
typename Derived>
49 static void setRandom(Eigen::MatrixBase<Derived>&& M, std::mt19937& engine);
51 template <
typename Derived>
52 static void setIdentity(Eigen::MatrixBase<Derived>& M);
54 template <
typename Derived>
55 static void setIdentity(Eigen::MatrixBase<Derived>&& M);
57 template <
typename Derived>
58 static void setConstant(Eigen::MatrixBase<Derived>& M,
const typename Derived::Scalar& val);
60 template <
typename Derived>
61 static void setConstant(Eigen::MatrixBase<Derived>&& M,
const typename Derived::Scalar& val);
63 template <
typename Derived>
66 template <
typename Scalar>
70 template <
typename Derived>
73 template <
typename Derived>
76 template <
typename Derived>
80 template <
typename Scalar>
81 static const Scalar*
get_raw_data(
const Eigen::Matrix<Scalar, -1, -1>& M)
86 template <
typename Scalar>
93 template <
typename Derived>
94 static typename Derived::Scalar
trace(
const Eigen::MatrixBase<Derived>& M);
96 template <
typename Derived>
97 static typename Derived::RealScalar
maxNorm(
const Eigen::MatrixBase<Derived>& M);
99 template <
typename Derived>
103 template <
typename DerivedL,
typename DerivedR>
105 const Eigen::MatrixBase<DerivedR>& M2);
107 template <
typename DerivedL,
typename DerivedR>
109 const Eigen::MatrixBase<DerivedR>& M2);
111 template <
typename Scalar,
typename MatrixExpr1,
typename MatrixExpr2,
typename MatrixExpr3,
typename MatrixExprRes>
112 static void optimal_prod(
const Scalar&
scale,
const MatrixExpr1& M1,
const MatrixExpr2& M2,
const MatrixExpr3& M3, MatrixExprRes& Mres);
114 template <
typename Scalar,
typename MatrixExpr1,
typename MatrixExpr2,
typename MatrixExpr3,
typename MatrixExprRes>
115 static void optimal_prod_add(
const Scalar&
scale,
const MatrixExpr1& M1,
const MatrixExpr2& M2,
const MatrixExpr3& M3, MatrixExprRes& Mres);
117 template <
typename DerivedL,
typename DerivedR>
121 static auto add(
const Eigen::MatrixBase<DerivedL>& M1,
const Eigen::MatrixBase<DerivedR>& M2)
126 template <
typename DerivedL,
typename DerivedR>
130 static auto difference(
const Eigen::MatrixBase<DerivedL>& M1,
const Eigen::MatrixBase<DerivedR>& M2)
135 template <
typename Derived>
136 static void scale(Eigen::MatrixBase<Derived>& M,
const typename Derived::Scalar& val);
138 template <
typename Scalar,
typename Derived>
139 static auto diagUnaryFunc(
const Eigen::MatrixBase<Derived>& M,
const std::function<Scalar(Scalar)>& func)
141 return M.diagonal().unaryExpr(func).asDiagonal();
144 template <
typename Scalar,
typename Derived>
145 static auto unaryFunc(
const Eigen::MatrixBase<Derived>& M,
const std::function<Scalar(
typename Derived::Scalar)>& func)
147 return M.unaryExpr(func);
150 template <
typename Scalar,
typename Derived,
typename OtherDerived>
152 const Eigen::MatrixBase<OtherDerived>& M_right,
153 const std::function<Scalar(Scalar, Scalar)>& func)
155 return M_left.diagonal().binaryExpr(M_right.diagonal(), func).asDiagonal();
158 template <
typename Scalar,
typename Derived,
typename OtherDerived>
159 static auto binaryFunc(
const Eigen::MatrixBase<Derived>& M_left,
160 const Eigen::MatrixBase<OtherDerived>& M_right,
161 const std::function<Scalar(Scalar, Scalar)>& func)
163 return M_left.binaryExpr(M_right, func);
166 template <
typename Scalar,
typename Derived>
167 static auto msqrt(
const Eigen::MatrixBase<Derived>& M)
172 template <
typename Derived,
typename Scalar>
173 static auto mexp(
const Eigen::MatrixBase<Derived>& M, Scalar factor)
175 return (factor * M).exp();
178 template <
typename Derived>
179 static auto adjoint(
const Eigen::MatrixBase<Derived>& M)
185 template <
typename Derived>
189 return M.block(row_off, col_off,
rows,
cols);
192 template <
typename Derived>
196 return M.block(row_off, col_off,
rows,
cols);
199 template <
typename Derived>
203 return M.block(row_off, col_off,
rows,
cols);
206 template <
typename Derived>
207 static void add_to_block(Eigen::MatrixBase<Derived>& M1,
212 const Eigen::MatrixBase<Derived>& M2);
214 template <
typename Derived>
215 static void set_block(Eigen::MatrixBase<Derived>& M1,
220 const Eigen::MatrixBase<Derived>& M2);
222 template <
typename Derived>
223 static void add_to_block(Eigen::MatrixBase<Derived>&& M1,
228 const Eigen::MatrixBase<Derived>& M2);
230 template <
typename Derived>
231 static void set_block(Eigen::MatrixBase<Derived>&& M1,
236 const Eigen::MatrixBase<Derived>& M2);
238 template <
typename Derived>
241 template <
typename Derived>
244 template <
typename Derived>
245 static std::string
print(
const Eigen::DenseBase<Derived>& M);
249#ifndef XPED_COMPILED_LIB
int MIndextype
Definition: MatrixInterface_Cyclops_impl.cpp:22
CTF::Matrix< Scalar > MType
Definition: MatrixInterface_Cyclops_impl.cpp:13
CTF::Matrix< Scalar > MapMType
Definition: MatrixInterface_Cyclops_impl.hpp:45
static auto unaryFunc(const Eigen::MatrixBase< Derived > &M, const std::function< Scalar(typename Derived::Scalar)> &func)
Definition: MatrixInterface_Eigen_impl.hpp:145
static void set_block(Eigen::MatrixBase< Derived > &M1, const MIndextype &row_off, const MIndextype &col_off, const MIndextype &rows, const MIndextype &cols, const Eigen::MatrixBase< Derived > &M2)
Definition: MatrixInterface_Eigen_impl.cpp:217
static auto binaryFunc(const Eigen::MatrixBase< Derived > &M_left, const Eigen::MatrixBase< OtherDerived > &M_right, const std::function< Scalar(Scalar, Scalar)> &func)
Definition: MatrixInterface_Eigen_impl.hpp:159
static auto block(const Eigen::MatrixBase< Derived > &M, const MIndextype &row_off, const MIndextype &col_off, const MIndextype &rows, const MIndextype &cols)
Definition: MatrixInterface_Eigen_impl.hpp:187
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 > Identity(const MIndextype &rows, const MIndextype &cols, CTF::World &world)
Definition: MatrixInterface_Cyclops_impl.cpp:71
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 auto adjoint(const Eigen::MatrixBase< Derived > &M)
Definition: MatrixInterface_Eigen_impl.hpp:179
static ctf_traits< MT >::Scalar maxNorm(MT &&M)
Definition: MatrixInterface_Cyclops_impl.cpp:104
static auto block(Eigen::MatrixBase< Derived > &&M, const MIndextype &row_off, const MIndextype &col_off, const MIndextype &rows, const MIndextype &cols)
Definition: MatrixInterface_Eigen_impl.hpp:194
static auto add(const Eigen::MatrixBase< DerivedL > &M1, const Eigen::MatrixBase< DerivedR > &M2)
Definition: MatrixInterface_Eigen_impl.hpp:121
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 void resize(MType< Scalar > &M, const MIndextype &new_rows, const MIndextype &new_cols)
static MIndextype rows(const MType< Scalar > &M)
Definition: MatrixInterface_Cyclops_impl.cpp:84
static void optimal_prod(const Scalar &scale, MatrixExpr1 &&M1, MatrixExpr2 &&M2, MatrixExpr3 &&M3, MatrixExprRes &Mres)
Definition: MatrixInterface_Cyclops_impl.cpp:176
static auto difference(const Eigen::MatrixBase< DerivedL > &M1, const Eigen::MatrixBase< DerivedR > &M2)
Definition: MatrixInterface_Eigen_impl.hpp:130
static auto mexp(const Eigen::MatrixBase< Derived > &M, Scalar factor)
Definition: MatrixInterface_Eigen_impl.hpp:173
static MType< Scalar > construct(const MIndextype &rows, const MIndextype &cols, CTF::World &world)
Definition: MatrixInterface_Cyclops_impl.cpp:26
static std::pair< MType< typename ctf_traits< MT >::Scalar >, MType< typename ctf_traits< MT >::Scalar > > qr(MT &&M)
Definition: MatrixInterface_Cyclops_impl.cpp:316
Eigen::Index MIndextype
Definition: MatrixInterface_Eigen_impl.hpp:27
static auto msqrt(const Eigen::MatrixBase< Derived > &M)
Definition: MatrixInterface_Eigen_impl.hpp:167
const CTF::Matrix< Scalar > cMapMType
Definition: MatrixInterface_Cyclops_impl.hpp:47
static void optimal_prod_add(const Scalar &scale, MatrixExpr1 &&M1, MatrixExpr2 &&M2, MatrixExpr3 &&M3, MatrixExprRes &Mres)
Definition: MatrixInterface_Cyclops_impl.cpp:193
static MType< typename ctf_traits< MT1 >::Scalar > prod(MT1 &&M1, MT2 &&M2)
Definition: MatrixInterface_Cyclops_impl.cpp:167
static MType< typename ctf_traits< MT1 >::Scalar > kronecker_prod(MT1 &&M1, MT2 &&M2)
Definition: MatrixInterface_Cyclops_impl.cpp:149
static void add_to_block(MType< Scalar > &M1, const MIndextype &row_off, const MIndextype &col_off, const MIndextype &rows, const MIndextype &cols, const MType< Scalar > &M2)
Definition: MatrixInterface_Cyclops_impl.cpp:324
static void setIdentity(MType< Scalar > &M)
Definition: MatrixInterface_Cyclops_impl.cpp:59
const CTF::Matrix< Scalar > cMType
Definition: MatrixInterface_Cyclops_impl.hpp:42
int MIndextype
Definition: MatrixInterface_Cyclops_impl.hpp:49
static std::pair< MType< typename ctf_traits< MT >::Scalar >, MType< typename ctf_traits< MT >::Scalar > > eigh(MT &&M)
Definition: MatrixInterface_Cyclops_impl.cpp:308
static auto diagBinaryFunc(const Eigen::MatrixBase< Derived > &M_left, const Eigen::MatrixBase< OtherDerived > &M_right, const std::function< Scalar(Scalar, Scalar)> &func)
Definition: MatrixInterface_Eigen_impl.hpp:151
static const Scalar * get_raw_data(const Eigen::Matrix< Scalar, -1, -1 > &M)
Definition: MatrixInterface_Eigen_impl.hpp:81
static auto block(Eigen::MatrixBase< Derived > &M, const MIndextype &row_off, const MIndextype &col_off, const MIndextype &rows, const MIndextype &cols)
Definition: MatrixInterface_Eigen_impl.hpp:201
static ctf_traits< MT >::Scalar trace(MT &&M)
Definition: MatrixInterface_Cyclops_impl.cpp:97
static void setVal(MType< Scalar > &M, const MIndextype row, const MIndextype col, const Scalar &val)
static void scale(MType< Scalar > &M, const Scalar &val)
Definition: MatrixInterface_Cyclops_impl.cpp:228
static Scalar * get_raw_data(Eigen::Matrix< Scalar, -1, -1 > &M)
Definition: MatrixInterface_Eigen_impl.hpp:87
CTF::Matrix< Scalar > MType
Definition: MatrixInterface_Cyclops_impl.hpp:40
static auto diagUnaryFunc(const Eigen::MatrixBase< Derived > &M, const std::function< Scalar(Scalar)> &func)
Definition: MatrixInterface_Eigen_impl.hpp:139
static ctf_traits< MT >::Scalar maxCoeff(MT &&M, MIndextype &maxrow, MIndextype &maxcol)
Definition: MatrixInterface_Cyclops_impl.cpp:111