27 #ifndef CDPL_MATH_LUDECOMPOSITION_HPP
28 #define CDPL_MATH_LUDECOMPOSITION_HPP
53 typedef typename E::SizeType SizeType;
54 typedef typename E::ValueType ValueType;
59 SizeType size1 = e().getSize1();
60 SizeType size2 = e().getSize2();
61 SizeType size = std::min(size1, size2);
66 SizeType singular = 0;
68 for (SizeType i = 0; i < size; i++) {
72 if (e()(i, i) != ValueType(0)) {
73 ValueType m_inv = ValueType(1) / e()(i, i);
74 range(col_i, ColumnRangeType(i + 1, size1)) *= m_inv;
76 }
else if (singular == 0)
79 range(e, MatrixRangeType(i + 1, size1), MatrixRangeType(i + 1, size2))
80 .minusAssign(
outerProd(
range(col_i, ColumnRangeType(i + 1, size1)),
81 range(row_i, RowRangeType(i + 1, size2))));
97 template <
typename E,
typename PV,
typename T>
101 typedef typename E::SizeType SizeType;
102 typedef typename E::ValueType ValueType;
107 SizeType size1 = e().getSize1();
108 SizeType size2 = e().getSize2();
109 SizeType size = std::min(size1, size2);
116 SizeType singular = 0;
118 for (SizeType i = 0; i < size; i++) {
121 SizeType norm_inf_idx = i +
normInfIndex(
range(col_i, ColumnRangeType(i, size1)));
123 if (e()(norm_inf_idx, i) != ValueType(0)) {
124 pv[i] = norm_inf_idx;
126 if (norm_inf_idx != i) {
127 row(e, norm_inf_idx).swap(row_i);
131 ValueType m_inv = ValueType(1) / e()(i, i);
132 range(col_i, ColumnRangeType(i + 1, size1)) *= m_inv;
134 }
else if (singular == 0)
137 range(e, MatrixRangeType(i + 1, size1), MatrixRangeType(i + 1, size2))
138 .minusAssign(
outerProd(
range(col_i, ColumnRangeType(i + 1, size1)),
139 range(row_i, RowRangeType(i + 1, size2))));
152 template <
typename E,
typename PV>
156 typedef typename E::SizeType SizeType;
158 for (SizeType i = 0, size = e().getSize(); i < size; i++) {
159 if (i != SizeType(pv[i]))
160 std::swap(e()(i), e()(pv[i]));
171 template <
typename E,
typename PV>
175 typedef typename E::SizeType SizeType;
177 for (SizeType i = 0, size = e().getSize1(); i < size; i++) {
178 if (i != SizeType(pv[i])) {
180 row(e, i).swap(other_row);
193 template <
typename E1,
typename E2>
213 template <
typename E1,
typename E2,
typename PV>
230 template <
typename E1,
typename E2>
250 template <
typename E1,
typename E2,
typename PV>
Functions for solving linear equations.
Definition of matrix proxy types.
Definition of vector proxy types.
Vector-expression proxy that views a single column of an underlying matrix.
Definition: MatrixProxy.hpp:320
CRTP base class for all matrix expression types.
Definition: Expression.hpp:104
Vector-expression proxy that views a single row of an underlying matrix.
Definition: MatrixProxy.hpp:53
CRTP base class for all vector expression types.
Definition: Expression.hpp:66
Vector-expression proxy that views a contiguous half-open subrange of an underlying vector.
Definition: VectorProxy.hpp:52
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
bool luSubstitute(const MatrixExpression< E1 > &lu, VectorExpression< E2 > &b)
Solves for b in place, given the LU decomposition lu (without pivoting).
Definition: LUDecomposition.hpp:195
bool solveUpper(const MatrixExpression< E1 > &e1, VectorExpression< E2 > &e2)
Solves in place by back-substitution, where e1 is an upper-triangular matrix.
Definition: LinearSolve.hpp:202
VectorNormInfinityIndex< E >::ResultType normInfIndex(const VectorExpression< E > &e)
Returns the (first) index at which the vector expression e attains its L∞ norm.
Definition: VectorExpression.hpp:966
MatrixColumn< M > column(MatrixExpression< M > &e, typename MatrixColumn< M >::SizeType j)
Returns a mutable column proxy for column j of the matrix expression e.
Definition: MatrixProxy.hpp:1259
MatrixRow< M > row(MatrixExpression< M > &e, typename MatrixRow< M >::SizeType i)
Returns a mutable row proxy for row i of the matrix expression e.
Definition: MatrixProxy.hpp:1231
MatrixRange< E > range(MatrixExpression< E > &e, const typename MatrixRange< E >::RangeType &r1, const typename MatrixRange< E >::RangeType &r2)
Returns a mutable matrix range proxy viewing rows in r1 and columns in r2 of e.
Definition: MatrixProxy.hpp:1288
VectorMatrixBinaryTraits< E1, E2, ScalarMultiplication< typename E1::ValueType, typename E2::ValueType > >::ResultType outerProd(const VectorExpression< E1 > &e1, const VectorExpression< E2 > &e2)
Returns the outer product of the vector expressions e1 and e2 as a matrix expression .
Definition: MatrixExpression.hpp:1409
bool solveUnitLower(const MatrixExpression< E1 > &e1, VectorExpression< E2 > &e2)
Solves in place by forward-substitution, where e1 is a unit lower-triangular matrix (1 on the diagon...
Definition: LinearSolve.hpp:91
void swapRows(VectorExpression< E > &e, const PV &pv)
Applies the permutation vector pv to the vector expression e by swapping element i with element pv[i]...
Definition: LUDecomposition.hpp:154
E::SizeType luDecompose(MatrixExpression< E > &e)
Computes an in-place LU decomposition of the matrix e without partial pivoting.
Definition: LUDecomposition.hpp:51
The namespace of the Chemical Data Processing Library.