10 #ifndef EIGEN_SKYLINEINPLACELU_H
11 #define EIGEN_SKYLINEINPLACELU_H
26 template<
typename MatrixType>
29 typedef typename MatrixType::Scalar
Scalar;
30 typedef typename MatrixType::Index
Index;
100 template<
typename BDerived,
typename XDerived>
102 const int transposed = 0)
const;
120 template<
typename MatrixType>
123 const size_t rows = m_lu.rows();
124 const size_t cols = m_lu.cols();
127 eigen_assert(!m_lu.IsRowMajor &&
"LU decomposition does not work with rowMajor Storage");
130 const double pivot = m_lu.coeffDiag(
row);
134 for (
typename MatrixType::InnerLowerIterator lIt(m_lu,
col); lIt; ++lIt) {
135 lIt.valueRef() /= pivot;
139 typename MatrixType::InnerLowerIterator lIt(m_lu,
col);
140 for (
Index rrow =
row + 1; rrow < m_lu.rows(); rrow++) {
141 typename MatrixType::InnerUpperIterator uItPivot(m_lu,
row);
142 typename MatrixType::InnerUpperIterator uIt(m_lu, rrow);
143 const double coef = lIt.value();
145 uItPivot += (rrow -
row - 1);
148 for (++uItPivot; uIt && uItPivot;) {
149 uIt.valueRef() -= uItPivot.value() * coef;
158 typename MatrixType::InnerLowerIterator lIt3(m_lu,
col);
159 for (
Index rrow =
row + 1; rrow < m_lu.rows(); rrow++) {
160 typename MatrixType::InnerUpperIterator uItPivot(m_lu,
row);
161 const double coef = lIt3.value();
165 m_lu.coeffRefLower(rrow,
row +
i + 1) -= uItPivot.value() * coef;
171 typename MatrixType::InnerLowerIterator lIt2(m_lu,
col);
172 for (
Index rrow =
row + 1; rrow < m_lu.rows(); rrow++) {
174 typename MatrixType::InnerUpperIterator uItPivot(m_lu,
row);
175 typename MatrixType::InnerUpperIterator uIt(m_lu, rrow);
176 const double coef = lIt2.value();
178 uItPivot += (rrow -
row - 1);
179 m_lu.coeffRefDiag(rrow) -= uItPivot.value() * coef;
185 template<
typename MatrixType>
187 const size_t rows = m_lu.rows();
188 const size_t cols = m_lu.cols();
191 eigen_assert(m_lu.IsRowMajor &&
"You're trying to apply rowMajor decomposition on a ColMajor matrix !");
194 typename MatrixType::InnerLowerIterator llIt(m_lu,
row);
198 if (m_lu.coeffExistLower(
row,
col)) {
199 const double diag = m_lu.coeffDiag(
col);
201 typename MatrixType::InnerLowerIterator lIt(m_lu,
row);
202 typename MatrixType::InnerUpperIterator uIt(m_lu,
col);
205 const Index offset = lIt.col() - uIt.row();
208 Index stop = offset > 0 ?
col - lIt.col() :
col - uIt.row();
212 Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop);
213 Map<VectorXd > colVal(uIt.valuePtr() + (offset > 0 ? offset : 0), stop);
216 Scalar newCoeff = m_lu.coeffLower(
row,
col) - rowVal.dot(colVal);
224 for (
Index k = 0; k < stop; ++k) {
225 const Scalar tmp = newCoeff;
226 newCoeff = tmp - lIt.value() * uIt.value();
232 m_lu.coeffRefLower(
row,
col) = newCoeff / diag;
238 typename MatrixType::InnerUpperIterator uuIt(m_lu,
col);
239 for (
Index rrow = uuIt.row(); rrow <
col; rrow++) {
241 typename MatrixType::InnerLowerIterator lIt(m_lu, rrow);
242 typename MatrixType::InnerUpperIterator uIt(m_lu,
col);
243 const Index offset = lIt.col() - uIt.row();
245 Index stop = offset > 0 ? rrow - lIt.col() : rrow - uIt.row();
248 Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop);
249 Map<VectorXd > colVal(uIt.valuePtr() + (offset > 0 ? offset : 0), stop);
251 Scalar newCoeff = m_lu.coeffUpper(rrow,
col) - rowVal.dot(colVal);
257 Scalar newCoeff = m_lu.coeffUpper(rrow,
col);
258 for (
Index k = 0; k < stop; ++k) {
259 const Scalar tmp = newCoeff;
260 newCoeff = tmp - lIt.value() * uIt.value();
266 m_lu.coeffRefUpper(rrow,
col) = newCoeff;
271 typename MatrixType::InnerLowerIterator lIt(m_lu,
row);
272 typename MatrixType::InnerUpperIterator uIt(m_lu,
row);
274 const Index offset = lIt.col() - uIt.row();
277 Index stop = offset > 0 ? lIt.size() : uIt.size();
279 Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop);
280 Map<VectorXd > colVal(uIt.valuePtr() + (offset > 0 ? offset : 0), stop);
281 Scalar newCoeff = m_lu.coeffDiag(
row) - rowVal.dot(colVal);
288 for (
Index k = 0; k < stop; ++k) {
289 const Scalar tmp = newCoeff;
290 newCoeff = tmp - lIt.value() * uIt.value();
295 m_lu.coeffRefDiag(
row) = newCoeff;
307 template<
typename MatrixType>
308 template<
typename BDerived,
typename XDerived>
310 const size_t rows = m_lu.rows();
311 const size_t cols = m_lu.cols();
317 typename MatrixType::InnerLowerIterator lIt(m_lu,
row);
320 while (lIt.col() <
row) {
322 newVal -=
x->coeff(
col++) * lIt.value();
326 x->coeffRef(
row) = newVal;
331 x->coeffRef(
col) =
x->coeff(
col) / m_lu.coeffDiag(
col);
335 typename MatrixType::InnerUpperIterator uIt(m_lu,
col);
340 x->coeffRef(uIt.row()) -= x_col * uIt.value();
347 x->coeffRef(0) =
x->coeff(0) / m_lu.coeffDiag(0);
Array< int, Dynamic, 1 > v
RowXpr row(Index i) const
ColXpr col(Index i) const
Matrix< float, 1, Dynamic > MatrixType
Inplace LU decomposition of a skyline matrix and associated features.
RealScalar precision() const
void setPrecision(RealScalar v)
MatrixType::Scalar Scalar
bool solve(const MatrixBase< BDerived > &b, MatrixBase< XDerived > *x, const int transposed=0) const
void setOrderingMethod(int m)
bool succeeded(void) const
SkylineInplaceLU(MatrixType &matrix, int flags=0)
int orderingMethod() const
NumTraits< typename MatrixType::Scalar >::Real RealScalar
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend