33 #ifndef __H__LGMATH__MATRIX_VECTOR_FUNCTIONS_COMMON_IMPL__
34 #define __H__LGMATH__MATRIX_VECTOR_FUNCTIONS_COMMON_IMPL__
46 template <
typename vector_t_out,
typename matrix_t,
typename vector_t_in>
49 MatVecMult(vector_t_out& vOut,
const matrix_t& m,
const vector_t_in& v)
51 assert(vector_t_out::Size == matrix_t::RowSize);
52 assert(vector_t_in::Size == matrix_t::ColSize);
54 typedef typename matrix_t::size_type size_type;
55 for(size_type i = 0; i < vOut.size(); ++i)
58 for(size_type j = 0; j < v.size(); ++j)
60 vOut[i] += m(i,j) * v[j];
67 template <
typename vector_t_out,
typename matrix_t,
typename vector_t_in>
72 assert(vector_t_out::Size == matrix_t::RowSize);
73 assert(vector_t_in::Size == matrix_t::ColSize);
75 typedef typename matrix_t::size_type size_type;
76 for(size_type i = 0; i < vOut.size(); ++i)
78 for(size_type j = 0; j < v.size(); ++j)
80 vOut[i] += m(i,j) * v[j];
87 template <
typename vector_t_out,
typename matrix_t,
typename vector_t_in>
92 assert(vector_t_out::Size == matrix_t::RowSize);
93 assert(vector_t_in::Size == matrix_t::ColSize);
95 typedef typename matrix_t::size_type size_type;
96 for(size_type i = 0; i < vOut.size(); ++i)
98 for(size_type j = 0; j < v.size(); ++j)
100 vOut[i] +=
s * m(i,j) * v[j];
108 template <
typename vector_t_out,
typename matrix_t,
typename vector_t_in>
113 assert(vector_t_out::Size == matrix_t::ColSize);
114 assert(vector_t_in::Size == matrix_t::RowSize);
116 typedef typename matrix_t::size_type size_type;
117 for(size_type i = 0; i < vOut.size(); ++i)
120 for(size_type j = 0; j < v.size(); ++j)
122 vOut[i] += m(j,i) * v[j];
129 template <
typename vector_t_out,
typename matrix_t,
typename vector_t_in>
134 assert(vector_t_out::Size == matrix_t::ColSize);
135 assert(vector_t_in::Size == matrix_t::RowSize);
137 typedef typename matrix_t::size_type size_type;
138 for(size_type i = 0; i < vOut.size(); ++i)
140 for(size_type j = 0; j < v.size(); ++j)
142 vOut[i] += m(j,i) * v[j];
155 template <
typename matrix_t,
typename vector_t>
160 typedef typename matrix_t::size_type size_type;
163 assert (vector_t::Size == matrix_t::RowSize);
164 assert (matrix_t::RowSize >= matrix_t::ColSize);
169 for (size_type i = 0; i < matrix_t::RowSize - 1; i++)
170 for (size_type k = matrix_t::RowSize - 1; k > i; k--)
172 d = A (i, i); x = A (k, i);
175 if (std::abs (d) > std::abs (x))
178 c = 1.0 / std::sqrt (1 +
s *
s);
184 s = 1.0 / std::sqrt (1 + c * c);
190 for (size_type j = i; j < matrix_t::ColSize; j++)
192 x = A (i, j); y = A (k, j);
193 A (i, j) = c * x +
s * y;
194 A (k, j) = c * y -
s * x;
198 x = v [i]; y = v [k];
199 v [i] = c * x +
s * y;
200 v [k] = c * y -
s * x;
220 template <
typename matrix_t,
typename vector_t>
225 typedef typename matrix_t::size_type size_type;
231 size_type i = matrix_t::ColSize;
235 for (size_type j = i + 1; j < matrix_t::ColSize; j++)
236 v [i] -= A (i, j) * v [j];
237 if (std::abs (A (i, i)) <
SMALL * std::abs (v [i]))
238 UG_THROW (
"InvMatVecMult_byGivens: Inverting singular matrix by the Givens rotations");
248 template <
typename matrix_t,
typename vector_t>
253 typedef typename matrix_t::size_type size_type;
262 for (size_type i = 0; i < matrix_t::ColSize; i++) coeff [i] = v [i];
a mathematical Vector with N entries.
Definition: math_vector.h:97
#define UG_THROW(msg)
Definition: error.h:57
void TransposedMatVecMultAdd(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
Transposed Matrix - Vector Muliplication.
Definition: math_matrix_vector_functions_common_impl.hpp:132
void MatVecMultAppend(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
Matrix - Vector Multiplication adding to a second vector.
Definition: math_matrix_vector_functions_common_impl.hpp:70
void InvMatVecMult_byGivens(matrix_t &A, vector_t &v)
Multiplication by the inverse using the Givens rotations.
Definition: math_matrix_vector_functions_common_impl.hpp:223
void GivensMatVecMult(matrix_t &A, vector_t &v)
Multiplication by the Givens rotation of the QR-Decomposition.
Definition: math_matrix_vector_functions_common_impl.hpp:158
void TransposedMatVecMult(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
Transposed Matrix - Vector Muliplication.
Definition: math_matrix_vector_functions_common_impl.hpp:111
void OrthogProjectVec(vector_t &v, const matrix_t &A)
Orthogonal projection.
Definition: math_matrix_vector_functions_common_impl.hpp:251
void MatVecScaleMultAppend(vector_t_out &vOut, typename vector_t_out::value_type s, const matrix_t &m, const vector_t_in &v)
Matrix - Vector Multiplication added scaled to a second vector.
Definition: math_matrix_vector_functions_common_impl.hpp:90
void MatVecMult(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
Matrix - Vector Multiplication.
Definition: math_matrix_vector_functions_common_impl.hpp:49
const number SMALL
Definition: math_constants.h:41
T value_type
Definition: sparsematrix_interface.h:2