Eigen::SkylineInplaceLU< MatrixType > Class Template Reference

Inplace LU decomposition of a skyline matrix and associated features. More...

Public Member Functions

void compute ()
 
void computeRowMajor ()
 
int flags () const
 
int orderingMethod () const
 
RealScalar precision () const
 
void setFlags (int f)
 
void setOrderingMethod (int m)
 
void setPrecision (RealScalar v)
 
 SkylineInplaceLU (MatrixType &matrix, int flags=0)
 
template<typename BDerived , typename XDerived >
bool solve (const MatrixBase< BDerived > &b, MatrixBase< XDerived > *x, const int transposed=0) const
 
bool succeeded (void) const
 

Protected Types

typedef MatrixType::Index Index
 
typedef NumTraits< typename MatrixType::Scalar >::Real RealScalar
 
typedef MatrixType::Scalar Scalar
 

Protected Attributes

int m_flags
 
MatrixTypem_lu
 
RealScalar m_precision
 
int m_status
 
bool m_succeeded
 

Detailed Description

template<typename MatrixType>
class Eigen::SkylineInplaceLU< MatrixType >

Inplace LU decomposition of a skyline matrix and associated features.

Parameters
MatrixTypethe type of the matrix of which we are computing the LU factorization

Definition at line 27 of file SkylineInplaceLU.h.

Member Typedef Documentation

◆ Index

template<typename MatrixType >
typedef MatrixType::Index Eigen::SkylineInplaceLU< MatrixType >::Index
protected

Definition at line 30 of file SkylineInplaceLU.h.

◆ RealScalar

template<typename MatrixType >
typedef NumTraits<typename MatrixType::Scalar>::Real Eigen::SkylineInplaceLU< MatrixType >::RealScalar
protected

Definition at line 32 of file SkylineInplaceLU.h.

◆ Scalar

template<typename MatrixType >
typedef MatrixType::Scalar Eigen::SkylineInplaceLU< MatrixType >::Scalar
protected

Definition at line 29 of file SkylineInplaceLU.h.

Constructor & Destructor Documentation

◆ SkylineInplaceLU()

template<typename MatrixType >
Eigen::SkylineInplaceLU< MatrixType >::SkylineInplaceLU ( MatrixType matrix,
int  flags = 0 
)
inline

Creates a LU object and compute the respective factorization of matrix using flags flags.

Definition at line 38 of file SkylineInplaceLU.h.

39  : /*m_matrix(matrix.rows(), matrix.cols()),*/ m_flags(flags), m_status(0), m_lu(matrix) {
40  m_precision = RealScalar(0.1) * Eigen::dummy_precision<RealScalar > ();
41  m_lu.IsRowMajor ? computeRowMajor() : compute();
42  }
NumTraits< typename MatrixType::Scalar >::Real RealScalar

Member Function Documentation

◆ compute()

template<typename MatrixType >
void Eigen::SkylineInplaceLU< MatrixType >::compute

Computes/re-computes the LU factorization

Computes / recomputes the in place LU decomposition of the SkylineInplaceLU. using the default algorithm.

Definition at line 122 of file SkylineInplaceLU.h.

122  {
123  const size_t rows = m_lu.rows();
124  const size_t cols = m_lu.cols();
125 
126  eigen_assert(rows == cols && "We do not (yet) support rectangular LU.");
127  eigen_assert(!m_lu.IsRowMajor && "LU decomposition does not work with rowMajor Storage");
128 
129  for (Index row = 0; row < rows; row++) {
130  const double pivot = m_lu.coeffDiag(row);
131 
132  //Lower matrix Columns update
133  const Index& col = row;
134  for (typename MatrixType::InnerLowerIterator lIt(m_lu, col); lIt; ++lIt) {
135  lIt.valueRef() /= pivot;
136  }
137 
138  //Upper matrix update -> contiguous memory access
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();
144 
145  uItPivot += (rrow - row - 1);
146 
147  //update upper part -> contiguous memory access
148  for (++uItPivot; uIt && uItPivot;) {
149  uIt.valueRef() -= uItPivot.value() * coef;
150 
151  ++uIt;
152  ++uItPivot;
153  }
154  ++lIt;
155  }
156 
157  //Upper matrix update -> non contiguous memory access
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();
162 
163  //update lower part -> non contiguous memory access
164  for (Index i = 0; i < rrow - row - 1; i++) {
165  m_lu.coeffRefLower(rrow, row + i + 1) -= uItPivot.value() * coef;
166  ++uItPivot;
167  }
168  ++lIt3;
169  }
170  //update diag -> contiguous
171  typename MatrixType::InnerLowerIterator lIt2(m_lu, col);
172  for (Index rrow = row + 1; rrow < m_lu.rows(); rrow++) {
173 
174  typename MatrixType::InnerUpperIterator uItPivot(m_lu, row);
175  typename MatrixType::InnerUpperIterator uIt(m_lu, rrow);
176  const double coef = lIt2.value();
177 
178  uItPivot += (rrow - row - 1);
179  m_lu.coeffRefDiag(rrow) -= uItPivot.value() * coef;
180  ++lIt2;
181  }
182  }
183 }
int i
RowXpr row(Index i) const
ColXpr col(Index i) const
#define eigen_assert(x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
Derived::Index cols
Derived::Index rows

◆ computeRowMajor()

template<typename MatrixType >
void Eigen::SkylineInplaceLU< MatrixType >::computeRowMajor

Definition at line 186 of file SkylineInplaceLU.h.

186  {
187  const size_t rows = m_lu.rows();
188  const size_t cols = m_lu.cols();
189 
190  eigen_assert(rows == cols && "We do not (yet) support rectangular LU.");
191  eigen_assert(m_lu.IsRowMajor && "You're trying to apply rowMajor decomposition on a ColMajor matrix !");
192 
193  for (Index row = 0; row < rows; row++) {
194  typename MatrixType::InnerLowerIterator llIt(m_lu, row);
195 
196 
197  for (Index col = llIt.col(); col < row; col++) {
198  if (m_lu.coeffExistLower(row, col)) {
199  const double diag = m_lu.coeffDiag(col);
200 
201  typename MatrixType::InnerLowerIterator lIt(m_lu, row);
202  typename MatrixType::InnerUpperIterator uIt(m_lu, col);
203 
204 
205  const Index offset = lIt.col() - uIt.row();
206 
207 
208  Index stop = offset > 0 ? col - lIt.col() : col - uIt.row();
209 
210  //#define VECTORIZE
211 #ifdef VECTORIZE
212  Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop);
213  Map<VectorXd > colVal(uIt.valuePtr() + (offset > 0 ? offset : 0), stop);
214 
215 
216  Scalar newCoeff = m_lu.coeffLower(row, col) - rowVal.dot(colVal);
217 #else
218  if (offset > 0) //Skip zero value of lIt
219  uIt += offset;
220  else //Skip zero values of uIt
221  lIt += -offset;
222  Scalar newCoeff = m_lu.coeffLower(row, col);
223 
224  for (Index k = 0; k < stop; ++k) {
225  const Scalar tmp = newCoeff;
226  newCoeff = tmp - lIt.value() * uIt.value();
227  ++lIt;
228  ++uIt;
229  }
230 #endif
231 
232  m_lu.coeffRefLower(row, col) = newCoeff / diag;
233  }
234  }
235 
236  //Upper matrix update
237  const Index col = row;
238  typename MatrixType::InnerUpperIterator uuIt(m_lu, col);
239  for (Index rrow = uuIt.row(); rrow < col; rrow++) {
240 
241  typename MatrixType::InnerLowerIterator lIt(m_lu, rrow);
242  typename MatrixType::InnerUpperIterator uIt(m_lu, col);
243  const Index offset = lIt.col() - uIt.row();
244 
245  Index stop = offset > 0 ? rrow - lIt.col() : rrow - uIt.row();
246 
247 #ifdef VECTORIZE
248  Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop);
249  Map<VectorXd > colVal(uIt.valuePtr() + (offset > 0 ? offset : 0), stop);
250 
251  Scalar newCoeff = m_lu.coeffUpper(rrow, col) - rowVal.dot(colVal);
252 #else
253  if (offset > 0) //Skip zero value of lIt
254  uIt += offset;
255  else //Skip zero values of uIt
256  lIt += -offset;
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();
261 
262  ++lIt;
263  ++uIt;
264  }
265 #endif
266  m_lu.coeffRefUpper(rrow, col) = newCoeff;
267  }
268 
269 
270  //Diag matrix update
271  typename MatrixType::InnerLowerIterator lIt(m_lu, row);
272  typename MatrixType::InnerUpperIterator uIt(m_lu, row);
273 
274  const Index offset = lIt.col() - uIt.row();
275 
276 
277  Index stop = offset > 0 ? lIt.size() : uIt.size();
278 #ifdef VECTORIZE
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);
282 #else
283  if (offset > 0) //Skip zero value of lIt
284  uIt += offset;
285  else //Skip zero values of uIt
286  lIt += -offset;
287  Scalar newCoeff = m_lu.coeffDiag(row);
288  for (Index k = 0; k < stop; ++k) {
289  const Scalar tmp = newCoeff;
290  newCoeff = tmp - lIt.value() * uIt.value();
291  ++lIt;
292  ++uIt;
293  }
294 #endif
295  m_lu.coeffRefDiag(row) = newCoeff;
296  }
297 }
MatrixType::Scalar Scalar

◆ flags()

template<typename MatrixType >
int Eigen::SkylineInplaceLU< MatrixType >::flags ( ) const
inline
Returns
the current flags

Definition at line 78 of file SkylineInplaceLU.h.

78  {
79  return m_flags;
80  }

◆ orderingMethod()

template<typename MatrixType >
int Eigen::SkylineInplaceLU< MatrixType >::orderingMethod ( ) const
inline

Definition at line 86 of file SkylineInplaceLU.h.

86  {
87  return m_flags;
88  }

◆ precision()

template<typename MatrixType >
RealScalar Eigen::SkylineInplaceLU< MatrixType >::precision ( ) const
inline
Returns
the current precision.
See also
setPrecision()

Definition at line 61 of file SkylineInplaceLU.h.

61  {
62  return m_precision;
63  }

◆ setFlags()

template<typename MatrixType >
void Eigen::SkylineInplaceLU< MatrixType >::setFlags ( int  f)
inline

Sets the flags. Possible values are:

  • CompleteFactorization
  • IncompleteFactorization
  • MemoryEfficient
  • one of the ordering methods
  • etc...
See also
flags()

Definition at line 73 of file SkylineInplaceLU.h.

73  {
74  m_flags = f;
75  }

◆ setOrderingMethod()

template<typename MatrixType >
void Eigen::SkylineInplaceLU< MatrixType >::setOrderingMethod ( int  m)
inline

Definition at line 82 of file SkylineInplaceLU.h.

82  {
83  m_flags = m;
84  }
Matrix3f m

◆ setPrecision()

template<typename MatrixType >
void Eigen::SkylineInplaceLU< MatrixType >::setPrecision ( RealScalar  v)
inline

Sets the relative threshold value used to prune zero coefficients during the decomposition.

Setting a value greater than zero speeds up computation, and yields to an incomplete factorization with fewer non zero coefficients. Such approximate factors are especially useful to initialize an iterative solver.

Note that the exact meaning of this parameter might depends on the actual backend. Moreover, not all backends support this feature.

See also
precision()

Definition at line 54 of file SkylineInplaceLU.h.

54  {
55  m_precision = v;
56  }
Array< int, Dynamic, 1 > v

◆ solve()

template<typename MatrixType >
template<typename BDerived , typename XDerived >
bool Eigen::SkylineInplaceLU< MatrixType >::solve ( const MatrixBase< BDerived > &  b,
MatrixBase< XDerived > *  x,
const int  transposed = 0 
) const
Returns
the lower triangular matrix L
the upper triangular matrix U

Computes *x = U^-1 L^-1 b

If transpose is set to SvTranspose or SvAdjoint, the solution of the transposed/adjoint system is computed instead.

Not all backends implement the solution of the transposed or adjoint system.

Definition at line 309 of file SkylineInplaceLU.h.

309  {
310  const size_t rows = m_lu.rows();
311  const size_t cols = m_lu.cols();
312 
313 
314  for (Index row = 0; row < rows; row++) {
315  x->coeffRef(row) = b.coeff(row);
316  Scalar newVal = x->coeff(row);
317  typename MatrixType::InnerLowerIterator lIt(m_lu, row);
318 
319  Index col = lIt.col();
320  while (lIt.col() < row) {
321 
322  newVal -= x->coeff(col++) * lIt.value();
323  ++lIt;
324  }
325 
326  x->coeffRef(row) = newVal;
327  }
328 
329 
330  for (Index col = rows - 1; col > 0; col--) {
331  x->coeffRef(col) = x->coeff(col) / m_lu.coeffDiag(col);
332 
333  const Scalar x_col = x->coeff(col);
334 
335  typename MatrixType::InnerUpperIterator uIt(m_lu, col);
336  uIt += uIt.size()-1;
337 
338 
339  while (uIt) {
340  x->coeffRef(uIt.row()) -= x_col * uIt.value();
341  //TODO : introduce --operator
342  uIt += -1;
343  }
344 
345 
346  }
347  x->coeffRef(0) = x->coeff(0) / m_lu.coeffDiag(0);
348 
349  return true;
350 }

◆ succeeded()

template<typename MatrixType >
bool Eigen::SkylineInplaceLU< MatrixType >::succeeded ( void  ) const
inline
Returns
true if the factorization succeeded

Definition at line 105 of file SkylineInplaceLU.h.

105  {
106  return m_succeeded;
107  }

Member Data Documentation

◆ m_flags

template<typename MatrixType >
int Eigen::SkylineInplaceLU< MatrixType >::m_flags
protected

Definition at line 111 of file SkylineInplaceLU.h.

◆ m_lu

template<typename MatrixType >
MatrixType& Eigen::SkylineInplaceLU< MatrixType >::m_lu
protected

Definition at line 114 of file SkylineInplaceLU.h.

◆ m_precision

template<typename MatrixType >
RealScalar Eigen::SkylineInplaceLU< MatrixType >::m_precision
protected

Definition at line 110 of file SkylineInplaceLU.h.

◆ m_status

template<typename MatrixType >
int Eigen::SkylineInplaceLU< MatrixType >::m_status
mutableprotected

Definition at line 112 of file SkylineInplaceLU.h.

◆ m_succeeded

template<typename MatrixType >
bool Eigen::SkylineInplaceLU< MatrixType >::m_succeeded
protected

Definition at line 113 of file SkylineInplaceLU.h.


The documentation for this class was generated from the following file: