27 #ifndef CDPL_MATH_LINEARSOLVE_HPP
28 #define CDPL_MATH_LINEARSOLVE_HPP
40 class VectorExpression;
42 class MatrixExpression;
44 template <
typename E1,
typename E2>
51 if (e1().getSize1() != e1().getSize2())
54 if (SizeType(e1().getSize2()) != SizeType(e2().getSize()))
57 SizeType size = e2().getSize();
59 for (SizeType n = 0; n < size; n++) {
60 if (e1()(n, n) ==
typename E1::ValueType(0))
63 ValueType t = e2()(n) /= e1()(n, n);
65 if (t != ValueType(0))
66 for (SizeType
m = n + 1;
m < size;
m++)
67 e2()(
m) -= e1()(
m, n) * t;
73 template <
typename E1,
typename E2>
80 if (e1().getSize1() != e1().getSize2())
83 if (SizeType(e1().getSize2()) != SizeType(e2().getSize()))
86 SizeType size = e2().getSize();
88 for (SizeType n = 0; n < size; n++) {
89 ValueType t = e2()(n);
91 if (t != ValueType(0))
92 for (SizeType
m = n + 1;
m < size;
m++)
93 e2()(
m) -= e1()(
m, n) * t;
99 template <
typename E1,
typename E2>
106 if (e1().getSize1() != e1().getSize2())
109 if (SizeType(e1().getSize2()) != SizeType(e2().getSize1()))
112 SizeType size1 = e2().getSize1();
113 SizeType size2 = e2().getSize2();
115 for (SizeType n = 0; n < size1; n++) {
116 if (e1()(n, n) ==
typename E1::ValueType(0))
119 for (SizeType l = 0; l < size2; l++) {
120 ValueType t = e2()(n, l) /= e1()(n, n);
122 if (t != ValueType(0))
123 for (SizeType
m = n + 1;
m < size1;
m++)
124 e2()(
m, l) -= e1()(
m, n) * t;
131 template <
typename E1,
typename E2>
138 if (e1().getSize1() != e1().getSize2())
141 if (SizeType(e1().getSize2()) != SizeType(e2().getSize1()))
144 SizeType size1 = e2().getSize1();
145 SizeType size2 = e2().getSize2();
147 for (SizeType n = 0; n < size1; n++) {
148 for (SizeType l = 0; l < size2; l++) {
149 ValueType t = e2()(n, l);
151 if (t != ValueType(0))
152 for (SizeType
m = n + 1;
m < size1;
m++)
153 e2()(
m, l) -= e1()(
m, n) * t;
160 template <
typename E1,
typename E2>
168 if (e1().getSize1() != e1().getSize2())
171 if (SizeType(e1().getSize2()) != SizeType(e2().getSize()))
174 SizeType size = e2().getSize();
176 for (DifferenceType n = size - 1; n >= 0; n--) {
177 if (e1()(n, n) ==
typename E1::ValueType(0))
180 ValueType t = e2()(n) /= e1()(n, n);
182 if (t != ValueType(0))
183 for (DifferenceType
m = n - 1;
m >= 0;
m--)
184 e2()(
m) -= e1()(
m, n) * t;
190 template <
typename E1,
typename E2>
198 if (e1().getSize1() != e1().getSize2())
201 if (SizeType(e1().getSize2()) != SizeType(e2().getSize()))
204 SizeType size = e2().getSize();
206 for (DifferenceType n = size - 1; n >= 0; n--) {
207 ValueType t = e2()(n);
209 if (t != ValueType(0))
210 for (DifferenceType
m = n - 1;
m >= 0;
m--)
211 e2()(
m) -= e1()(
m, n) * t;
217 template <
typename E1,
typename E2>
225 if (e1().getSize1() != e1().getSize2())
228 if (SizeType(e1().getSize2()) != SizeType(e2().getSize1()))
231 SizeType size1 = e2().getSize1();
232 SizeType size2 = e2().getSize2();
234 for (DifferenceType n = size1 - 1; n >= 0; n--) {
235 if (e1()(n, n) ==
typename E1::ValueType(0))
238 for (DifferenceType l = size2 - 1; l >= 0; l--) {
239 ValueType t = e2()(n, l) /= e1()(n, n);
241 if (t != ValueType(0))
242 for (DifferenceType
m = n - 1;
m >= 0;
m--)
243 e2()(
m, l) -= e1()(
m, n) * t;
250 template <
typename E1,
typename E2>
258 if (e1().getSize1() != e1().getSize2())
261 if (SizeType(e1().getSize2()) != SizeType(e2().getSize1()))
264 SizeType size1 = e2().getSize1();
265 SizeType size2 = e2().getSize2();
267 for (DifferenceType n = size1 - 1; n >= 0; n--) {
268 for (DifferenceType l = size2 - 1; l >= 0; l--) {
269 ValueType t = e2()(n, l);
271 if (t != ValueType(0))
272 for (DifferenceType
m = n - 1;
m >= 0;
m--)
273 e2()(
m, l) -= e1()(
m, n) * t;
Definition: Expression.hpp:76
Definition: Expression.hpp:54
constexpr unsigned int m
Specifies that the stereocenter has m configuration.
Definition: CIPDescriptor.hpp:116
bool solveUpper(const MatrixExpression< E1 > &e1, VectorExpression< E2 > &e2)
Definition: LinearSolve.hpp:162
bool solveUnitUpper(const MatrixExpression< E1 > &e1, VectorExpression< E2 > &e2)
Definition: LinearSolve.hpp:192
bool solveUnitLower(const MatrixExpression< E1 > &e1, VectorExpression< E2 > &e2)
Definition: LinearSolve.hpp:75
bool solveLower(const MatrixExpression< E1 > &e1, VectorExpression< E2 > &e2)
Definition: LinearSolve.hpp:46
The namespace of the Chemical Data Processing Library.
std::common_type< T1, T2 >::type Type
Definition: CommonType.hpp:43