1#ifndef CHEMMISOL_LINEAR_H
2#define CHEMMISOL_LINEAR_H
6#include <initializer_list>
10#include "../logging.h"
25 template<
typename T, std::
size_t N>
26 using X = std::array<T, N>;
33 template<
typename T, std::
size_t N, std::
size_t P = N>
34 using M = std::array<std::array<T, P>, N>;
40 using VecX = std::vector<T>;
45 using VecM = std::vector<std::vector<T>>;
54 template<
typename T, std::
size_t N, std::
size_t P>
57 for(std::size_t i = 0; i < N; i++) {
59 for(std::size_t j = 0; j < P; j++) {
60 x1[i] += m[i][j] * x[j];
72 template<
typename T, std::
size_t N>
75 for(std::size_t i = 0; i < N; i++)
87 template<
typename T, std::
size_t N>
90 for(std::size_t i = 0; i < N; i++)
95 template<
typename T, std::
size_t N>
96 X<T, N>
operator*(
const T& a,
const X<T, N>& x) {
98 for(std::size_t i = 0; i < N; i++)
103 template<
typename T, std::
size_t N, std::
size_t P>
104 M<T, N, P>
operator*(
const T& a,
const M<T, N, P>& m) {
106 for(std::size_t i = 0; i < N; i++) {
107 for(std::size_t j = 0; j < P; j++) {
108 result[i][j] = a * m[i][j];
116 template<
typename T, std::
size_t N>
125 template<
typename T, std::
size_t N>
126 double norm(
const X<std::complex<T>, N>& x) {
129 a+=std::pow(std::norm(v), 2);
137 template<
typename T, std::
size_t N>
140 for(std::size_t i = 0; i < N; i++)
141 abs_x[i] = std::abs(x[i]);
159 template<
typename _M>
161 typename _M::value_type::value_type,
162 std::tuple_size<_M>::value,
163 std::tuple_size<typename _M::value_type>::value+1>
166 const X<
typename _M::value_type::value_type, std::tuple_size<_M>::value>& x
169 typename _M::value_type::value_type,
170 std::tuple_size<_M>::value,
171 std::tuple_size<typename _M::value_type>::value+1> a;
172 for(std::size_t i = 0; i < std::tuple_size<_M>::value; i++) {
173 for(std::size_t j = 0; j < std::tuple_size<typename _M::value_type>::value; j++) {
176 a[i][std::tuple_size<_M>::value] = x[i];
186 template<
typename T, std::
size_t N>
189 for(std::size_t i = 0; i < N-1; i++)
211 for(std::size_t i = 0; i < x.size(); i++) {
213 for(std::size_t j = 0; j < m[i].size(); j++) {
214 x1[i] += m[i][j] * x[j];
229 for(std::size_t i = 0; i < x.size(); i++)
246 for(std::size_t i = 0; i < x1.size(); i++)
269 for(std::size_t i = 0; i < x.size(); i++)
270 abs_x[i] = std::abs(x[i]);
293 for(std::size_t i = 0; i < m.size(); i++) {
294 a[i].resize(m[i].size()+1);
295 for(std::size_t j = 0; j < m[i].size(); j++) {
298 a[i][m[i].size()] = x[i];
311 for(std::size_t i = 0; i < x.size()-1; i++)
Definition chemmisol.h:31
X< T, N > operator+(const X< T, N > &x1, const X< T, N > &x2)
Definition linear.h:88
std::vector< T > VecX
Definition linear.h:40
double norm(const X< T, N > &x)
Definition linear.h:117
std::array< T, N > X
Definition linear.h:26
std::ostream & operator<<(std::ostream &o, const Phase &phase)
M< typename _M::value_type::value_type, std::tuple_size< _M >::value, std::tuple_size< typename _M::value_type >::value+1 > augment(const _M &m, const X< typename _M::value_type::value_type, std::tuple_size< _M >::value > &x)
Definition linear.h:164
std::vector< std::vector< T > > VecM
Definition linear.h:45
std::array< std::array< T, P >, N > M
Definition linear.h:34
X< T, N > abs(const X< T, N > &x)
Definition linear.h:138
X< T, N > operator-(const X< T, N > &x)
Definition linear.h:73
X< T, N > operator*(const M< T, N, P > &m, const X< T, P > &x)
Definition linear.h:55