27 #ifndef CDPL_MATH_LUDECOMPOSITION_HPP
28 #define CDPL_MATH_LUDECOMPOSITION_HPP
47 typedef typename E::SizeType SizeType;
48 typedef typename E::ValueType ValueType;
53 SizeType size1 = e().getSize1();
54 SizeType size2 = e().getSize2();
55 SizeType size = std::min(size1, size2);
60 SizeType singular = 0;
62 for (SizeType i = 0; i < size; i++) {
66 if (e()(i, i) != ValueType(0)) {
67 ValueType m_inv = ValueType(1) / e()(i, i);
68 range(col_i, ColumnRangeType(i + 1, size1)) *= m_inv;
70 }
else if (singular == 0)
73 range(e, MatrixRangeType(i + 1, size1), MatrixRangeType(i + 1, size2))
74 .minusAssign(
outerProd(
range(col_i, ColumnRangeType(i + 1, size1)),
75 range(row_i, RowRangeType(i + 1, size2))));
81 template <
typename E,
typename PV,
typename T>
85 typedef typename E::SizeType SizeType;
86 typedef typename E::ValueType ValueType;
91 SizeType size1 = e().getSize1();
92 SizeType size2 = e().getSize2();
93 SizeType size = std::min(size1, size2);
100 SizeType singular = 0;
102 for (SizeType i = 0; i < size; i++) {
105 SizeType norm_inf_idx = i +
normInfIndex(
range(col_i, ColumnRangeType(i, size1)));
107 if (e()(norm_inf_idx, i) != ValueType(0)) {
108 pv[i] = norm_inf_idx;
110 if (norm_inf_idx != i) {
111 row(e, norm_inf_idx).swap(row_i);
115 ValueType m_inv = ValueType(1) / e()(i, i);
116 range(col_i, ColumnRangeType(i + 1, size1)) *= m_inv;
118 }
else if (singular == 0)
121 range(e, MatrixRangeType(i + 1, size1), MatrixRangeType(i + 1, size2))
122 .minusAssign(
outerProd(
range(col_i, ColumnRangeType(i + 1, size1)),
123 range(row_i, RowRangeType(i + 1, size2))));
129 template <
typename E,
typename PV>
133 typedef typename E::SizeType SizeType;
135 for (SizeType i = 0, size = e().getSize(); i < size; i++) {
136 if (i != SizeType(pv[i]))
137 std::swap(e()(i), e()(pv[i]));
141 template <
typename E,
typename PV>
145 typedef typename E::SizeType SizeType;
147 for (SizeType i = 0, size = e().getSize1(); i < size; i++) {
148 if (i != SizeType(pv[i])) {
150 row(e, i).swap(other_row);
155 template <
typename E1,
typename E2>
165 template <
typename E1,
typename E2,
typename PV>
174 template <
typename E1,
typename E2>
184 template <
typename E1,
typename E2,
typename PV>
Functions for solving linear equations.
Definition of matrix proxy types.
Definition of vector proxy types.
Definition: MatrixProxy.hpp:196
Definition: Expression.hpp:76
Definition: MatrixProxy.hpp:49
Definition: Expression.hpp:54
Definition: VectorProxy.hpp:48
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
bool luSubstitute(const MatrixExpression< E1 > &lu, VectorExpression< E2 > &b)
Definition: LUDecomposition.hpp:157
bool solveUpper(const MatrixExpression< E1 > &e1, VectorExpression< E2 > &e2)
Definition: LinearSolve.hpp:162
VectorNormInfinityIndex< E >::ResultType normInfIndex(const VectorExpression< E > &e)
Definition: VectorExpression.hpp:546
MatrixColumn< M > column(MatrixExpression< M > &e, typename MatrixColumn< M >::SizeType j)
Definition: MatrixProxy.hpp:730
MatrixRow< M > row(MatrixExpression< M > &e, typename MatrixRow< M >::SizeType i)
Definition: MatrixProxy.hpp:716
MatrixRange< E > range(MatrixExpression< E > &e, const typename MatrixRange< E >::RangeType &r1, const typename MatrixRange< E >::RangeType &r2)
Definition: MatrixProxy.hpp:744
VectorMatrixBinaryTraits< E1, E2, ScalarMultiplication< typename E1::ValueType, typename E2::ValueType > >::ResultType outerProd(const VectorExpression< E1 > &e1, const VectorExpression< E2 > &e2)
Definition: MatrixExpression.hpp:794
bool solveUnitLower(const MatrixExpression< E1 > &e1, VectorExpression< E2 > &e2)
Definition: LinearSolve.hpp:75
void swapRows(VectorExpression< E > &e, const PV &pv)
Definition: LUDecomposition.hpp:131
E::SizeType luDecompose(MatrixExpression< E > &e)
Definition: LUDecomposition.hpp:45
The namespace of the Chemical Data Processing Library.