Xped
Loading...
Searching...
No Matches
MatrixInterface_Cyclops_impl.hpp
Go to the documentation of this file.
1#ifndef MATRIX_INTERFACE_CYCLOPS_IMPL_H_
2#define MATRIX_INTERFACE_CYCLOPS_IMPL_H_
3
4#include "ctf.hpp"
5
6namespace Xped {
7
8template <typename T>
10{};
11
12template <typename Scalar_>
13struct ctf_traits<CTF::Tensor<Scalar_>>
14{
15 using Scalar = Scalar_;
16};
17
18template <typename Scalar_>
19struct ctf_traits<CTF::Matrix<Scalar_>>
20{
21 using Scalar = Scalar_;
22};
23
24template <typename Scalar_>
25struct ctf_traits<CTF::Tensor<Scalar_>&>
26{
27 using Scalar = Scalar_;
28};
29
30template <typename Scalar_>
31struct ctf_traits<CTF::Matrix<Scalar_>&>
32{
33 using Scalar = Scalar_;
34};
35
37{
38 // typedefs
39 template <typename Scalar>
40 using MType = CTF::Matrix<Scalar>;
41 template <typename Scalar>
42 using cMType = const CTF::Matrix<Scalar>;
43
44 template <typename Scalar>
45 using MapMType = CTF::Matrix<Scalar>;
46 template <typename Scalar>
47 using cMapMType = const CTF::Matrix<Scalar>;
48
49 typedef int MIndextype;
50
51 // constructors
52 template <typename Scalar>
53 static MType<Scalar> construct(const MIndextype& rows, const MIndextype& cols, CTF::World& world);
54
55 template <typename Scalar>
56 static MType<Scalar> construct_with_zero(const MIndextype& rows, const MIndextype& cols, CTF::World& world);
57
58 template <typename Scalar>
59 static void resize(MType<Scalar>& M, const MIndextype& new_rows, const MIndextype& new_cols);
60
61 // initialization
62 template <typename Scalar>
63 static void setZero(MType<Scalar>& M);
64
65 template <typename Scalar>
66 static void setRandom(MType<Scalar>& M);
67
68 template <typename Scalar>
69 static void setIdentity(MType<Scalar>& M);
70
71 template <typename Scalar>
72 static void setConstant(MType<Scalar>& M, const Scalar& val);
73
74 template <typename Scalar>
75 static void setVal(MType<Scalar>& M, const MIndextype row, const MIndextype col, const Scalar& val);
76
77 template <typename Scalar>
78 static MType<Scalar> Identity(const MIndextype& rows, const MIndextype& cols, CTF::World& world);
79
80 // shape
81 template <typename Scalar>
82 static MIndextype rows(const MType<Scalar>& M);
83
84 template <typename Scalar>
85 static MIndextype cols(const MType<Scalar>& M);
86
87 // reduction
88 template <typename MT>
89 static typename ctf_traits<MT>::Scalar trace(MT&& M);
90
91 template <typename MT>
92 static typename ctf_traits<MT>::Scalar maxNorm(MT&& M);
93
94 template <typename MT>
95 static typename ctf_traits<MT>::Scalar maxCoeff(MT&& M, MIndextype& maxrow, MIndextype& maxcol);
96
97 template <typename Scalar>
98 static Scalar getVal(const MType<Scalar>& M, const MIndextype& row, const MIndextype& col);
99
100 template <typename MT1, typename MT2>
101 static MType<typename ctf_traits<MT1>::Scalar> kronecker_prod(MT1&& M1, MT2&& M2);
102
103 template <typename MT1, typename MT2>
104 static MType<typename ctf_traits<MT1>::Scalar> prod(MT1&& M1, MT2&& M2);
105
106 template <typename Scalar, typename MatrixExpr1, typename MatrixExpr2, typename MatrixExpr3, typename MatrixExprRes>
107 static void optimal_prod(const Scalar& scale, MatrixExpr1&& M1, MatrixExpr2&& M2, MatrixExpr3&& M3, MatrixExprRes& Mres);
108
109 template <typename Scalar, typename MatrixExpr1, typename MatrixExpr2, typename MatrixExpr3, typename MatrixExprRes>
110 static void optimal_prod_add(const Scalar& scale, MatrixExpr1&& M1, MatrixExpr2&& M2, MatrixExpr3&& M3, MatrixExprRes& Mres);
111
112 template <typename MT>
114
115 template <typename MT>
117
118 template <typename MT1, typename MT2>
119 static MType<typename ctf_traits<MT1>::Scalar> add(MT1&& M1, MT2&& M2);
120
121 template <typename MT1, typename MT2>
122 static MType<typename ctf_traits<MT1>::Scalar> difference(MT1&& M1, MT2&& M2);
123
124 template <typename Scalar>
125 static void scale(MType<Scalar>& M, const Scalar& val);
126
127 template <typename Scalar, typename MT>
128 static MType<Scalar> unaryFunc(MT&& M, const std::function<Scalar(Scalar)>& func);
129
130 template <typename Scalar, typename MT>
131 static MType<Scalar> diagUnaryFunc(MT&& M, const std::function<Scalar(Scalar)>& func);
132
133 template <typename Scalar, typename MTL, typename MTR>
134 static MType<Scalar> diagBinaryFunc(MTL&& M_left, MTR&& M_right, const std::function<Scalar(Scalar, Scalar)>& func);
135
136 template <typename Scalar, typename MTL, typename MTR>
137 static MType<Scalar> binaryFunc(MTL&& M_left, MTR&& M_right, const std::function<Scalar(Scalar, Scalar)>& func);
138
139 template <typename MT>
141
142 // template <typename Scalar>
143 // static auto adjoint(CTF::Tensor<Scalar>& M)
144 // {
145 // MType<Scalar> N(M.lens[1], M.lens[0]);
146 // N["ij"] = M["ji"];
147 // return N;
148 // }
149
150 template <typename Scalar>
151 static MType<Scalar>
152 block(const MType<Scalar>& M, const MIndextype& row_off, const MIndextype& col_off, const MIndextype& rows, const MIndextype& cols);
153
154 template <typename MT>
155 static std::pair<MType<typename ctf_traits<MT>::Scalar>, MType<typename ctf_traits<MT>::Scalar>> eigh(MT&& M);
156
157 template <typename MT>
158 static std::pair<MType<typename ctf_traits<MT>::Scalar>, MType<typename ctf_traits<MT>::Scalar>> qr(MT&& M);
159
160 template <typename Scalar>
161 static void add_to_block(MType<Scalar>& M1,
162 const MIndextype& row_off,
163 const MIndextype& col_off,
164 const MIndextype& rows,
165 const MIndextype& cols,
166 const MType<Scalar>& M2);
167
168 template <typename MT>
169 static void print(MT&& M);
170};
171
172} // namespace Xped
173
174#ifndef XPED_COMPILED_LIB
176#endif
177
178#endif
Definition: Tensor.hpp:40
Definition: bench.cpp:62
Definition: MatrixInterface_Cyclops_impl.hpp:37
CTF::Matrix< Scalar > MapMType
Definition: MatrixInterface_Cyclops_impl.hpp:45
static MType< Scalar > binaryFunc(MTL &&M_left, MTR &&M_right, const std::function< Scalar(Scalar, Scalar)> &func)
static MType< Scalar > block(const MType< Scalar > &M, const MIndextype &row_off, const MIndextype &col_off, const MIndextype &rows, const MIndextype &cols)
Definition: MatrixInterface_Cyclops_impl.cpp:287
static void setZero(MType< Scalar > &M)
Definition: MatrixInterface_Cyclops_impl.cpp:47
static MType< typename ctf_traits< MT >::Scalar > mexp(MT &&M)
static void setConstant(MType< Scalar > &M, const Scalar &val)
Definition: MatrixInterface_Cyclops_impl.cpp:65
static MType< typename ctf_traits< MT >::Scalar > msqrt(MT &&M)
static MType< Scalar > diagUnaryFunc(MT &&M, const std::function< Scalar(Scalar)> &func)
Definition: MatrixInterface_Cyclops_impl.cpp:243
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 void resize(MType< Scalar > &M, const MIndextype &new_rows, const MIndextype &new_cols)
Definition: MatrixInterface_Cyclops_impl.cpp:40
static ctf_traits< MT >::Scalar maxNorm(MT &&M)
Definition: MatrixInterface_Cyclops_impl.cpp:104
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 void optimal_prod(const Scalar &scale, MatrixExpr1 &&M1, MatrixExpr2 &&M2, MatrixExpr3 &&M3, MatrixExprRes &Mres)
Definition: MatrixInterface_Cyclops_impl.cpp:176
static MType< Scalar > unaryFunc(MT &&M, const std::function< Scalar(Scalar)> &func)
Definition: MatrixInterface_Cyclops_impl.cpp:234
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
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 MType< Scalar > diagBinaryFunc(MTL &&M_left, MTR &&M_right, const std::function< Scalar(Scalar, Scalar)> &func)
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 ctf_traits< MT >::Scalar trace(MT &&M)
Definition: MatrixInterface_Cyclops_impl.cpp:97
static MType< typename ctf_traits< MT1 >::Scalar > add(MT1 &&M1, MT2 &&M2)
Definition: MatrixInterface_Cyclops_impl.cpp:210
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 MType< typename ctf_traits< MT >::Scalar > adjoint(MT &&M)
Definition: MatrixInterface_Cyclops_impl.cpp:270
CTF::Matrix< Scalar > MType
Definition: MatrixInterface_Cyclops_impl.hpp:40
static ctf_traits< MT >::Scalar maxCoeff(MT &&M, MIndextype &maxrow, MIndextype &maxcol)
Definition: MatrixInterface_Cyclops_impl.cpp:111
Scalar_ Scalar
Definition: MatrixInterface_Cyclops_impl.hpp:21
Scalar_ Scalar
Definition: MatrixInterface_Cyclops_impl.hpp:33
Scalar_ Scalar
Definition: MatrixInterface_Cyclops_impl.hpp:15
Scalar_ Scalar
Definition: MatrixInterface_Cyclops_impl.hpp:27
Definition: MatrixInterface_Cyclops_impl.hpp:10