Eigen::internal::ldlt_inplace< Lower > Struct Reference

#include <LDLT.h>

Static Public Member Functions

template<typename MatrixType , typename TranspositionType , typename Workspace >
static bool unblocked (MatrixType &mat, TranspositionType &transpositions, Workspace &temp, SignMatrix &sign)
 
template<typename MatrixType , typename WDerived >
static bool updateInPlace (MatrixType &mat, MatrixBase< WDerived > &w, const typename MatrixType::RealScalar &sigma=1)
 
template<typename MatrixType , typename TranspositionType , typename Workspace , typename WType >
static bool update (MatrixType &mat, const TranspositionType &transpositions, Workspace &tmp, const WType &w, const typename MatrixType::RealScalar &sigma=1)
 

Member Function Documentation

◆ unblocked()

template<typename MatrixType , typename TranspositionType , typename Workspace >
static bool Eigen::internal::ldlt_inplace< Lower >::unblocked ( MatrixType mat,
TranspositionType &  transpositions,
Workspace &  temp,
SignMatrix sign 
)
inlinestatic
280  {
281  using std::abs;
282  typedef typename MatrixType::Scalar Scalar;
283  typedef typename MatrixType::RealScalar RealScalar;
284  typedef typename TranspositionType::StorageIndex IndexType;
285  eigen_assert(mat.rows() == mat.cols());
286  const Index size = mat.rows();
287  bool found_zero_pivot = false;
288  bool ret = true;
289 
290  if (size <= 1) {
291  transpositions.setIdentity();
292  if (size == 0)
293  sign = ZeroSign;
294  else if (numext::real(mat.coeff(0, 0)) > static_cast<RealScalar>(0))
296  else if (numext::real(mat.coeff(0, 0)) < static_cast<RealScalar>(0))
298  else
299  sign = ZeroSign;
300  return true;
301  }
302 
303  for (Index k = 0; k < size; ++k) {
304  // Find largest diagonal element
305  Index index_of_biggest_in_corner;
306  mat.diagonal().tail(size - k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner);
307  index_of_biggest_in_corner += k;
308 
309  transpositions.coeffRef(k) = IndexType(index_of_biggest_in_corner);
310  if (k != index_of_biggest_in_corner) {
311  // apply the transposition while taking care to consider only
312  // the lower triangular part
313  Index s = size - index_of_biggest_in_corner - 1; // trailing size after the biggest element
314  mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k));
315  mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s));
316  std::swap(mat.coeffRef(k, k), mat.coeffRef(index_of_biggest_in_corner, index_of_biggest_in_corner));
317  for (Index i = k + 1; i < index_of_biggest_in_corner; ++i) {
318  Scalar tmp = mat.coeffRef(i, k);
319  mat.coeffRef(i, k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner, i));
320  mat.coeffRef(index_of_biggest_in_corner, i) = numext::conj(tmp);
321  }
323  mat.coeffRef(index_of_biggest_in_corner, k) = numext::conj(mat.coeff(index_of_biggest_in_corner, k));
324  }
325 
326  // partition the matrix:
327  // A00 | - | -
328  // lu = A10 | A11 | -
329  // A20 | A21 | A22
330  Index rs = size - k - 1;
331  Block<MatrixType, Dynamic, 1> A21(mat, k + 1, k, rs, 1);
332  Block<MatrixType, 1, Dynamic> A10(mat, k, 0, 1, k);
333  Block<MatrixType, Dynamic, Dynamic> A20(mat, k + 1, 0, rs, k);
334 
335  if (k > 0) {
336  temp.head(k) = mat.diagonal().real().head(k).asDiagonal() * A10.adjoint();
337  mat.coeffRef(k, k) -= (A10 * temp.head(k)).value();
338  if (rs > 0) A21.noalias() -= A20 * temp.head(k);
339  }
340 
341  // In some previous versions of Eigen (e.g., 3.2.1), the scaling was omitted if the pivot
342  // was smaller than the cutoff value. However, since LDLT is not rank-revealing
343  // we should only make sure that we do not introduce INF or NaN values.
344  // Remark that LAPACK also uses 0 as the cutoff value.
345  RealScalar realAkk = numext::real(mat.coeffRef(k, k));
346  bool pivot_is_valid = (abs(realAkk) > RealScalar(0));
347 
348  if (k == 0 && !pivot_is_valid) {
349  // The entire diagonal is zero, there is nothing more to do
350  // except filling the transpositions, and checking whether the matrix is zero.
351  sign = ZeroSign;
352  for (Index j = 0; j < size; ++j) {
353  transpositions.coeffRef(j) = IndexType(j);
354  ret = ret && (mat.col(j).tail(size - j - 1).array() == Scalar(0)).all();
355  }
356  return ret;
357  }
358 
359  if ((rs > 0) && pivot_is_valid)
360  A21 /= realAkk;
361  else if (rs > 0)
362  ret = ret && (A21.array() == Scalar(0)).all();
363 
364  if (found_zero_pivot && pivot_is_valid)
365  ret = false; // factorization failed
366  else if (!pivot_is_valid)
367  found_zero_pivot = true;
368 
369  if (sign == PositiveSemiDef) {
370  if (realAkk < static_cast<RealScalar>(0)) sign = Indefinite;
371  } else if (sign == NegativeSemiDef) {
372  if (realAkk > static_cast<RealScalar>(0)) sign = Indefinite;
373  } else if (sign == ZeroSign) {
374  if (realAkk > static_cast<RealScalar>(0))
376  else if (realAkk < static_cast<RealScalar>(0))
378  }
379  }
380 
381  return ret;
382  }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition: Macros.h:910
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
Scalar coeff(Index row, Index col) const
Definition: SparseMatrix.h:211
const ConstDiagonalReturnType diagonal() const
Definition: SparseMatrix.h:757
void swap(SparseMatrix &other)
Definition: SparseMatrix.h:829
Index cols() const
Definition: SparseMatrix.h:161
Scalar & coeffRef(Index row, Index col)
Definition: SparseMatrix.h:275
Index rows() const
Definition: SparseMatrix.h:159
float real
Definition: datatypes.h:10
RealScalar s
Definition: level1_cplx_impl.h:130
Eigen::DenseIndex ret
Definition: level1_cplx_impl.h:43
EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:117
char char char int int * k
Definition: level2_impl.h:374
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
@ PositiveSemiDef
Definition: LDLT.h:34
@ ZeroSign
Definition: LDLT.h:34
@ NegativeSemiDef
Definition: LDLT.h:34
@ Indefinite
Definition: LDLT.h:34
EIGEN_DEVICE_FUNC bool all()
Definition: Macros.h:1276
squared absolute value
Definition: GlobalFunctions.h:87
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
T sign(T x)
Definition: cxx11_tensor_builtins_sycl.cpp:172
@ IsComplex
Definition: NumTraits.h:176
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References abs(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::coeff(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::coeffRef(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::cols(), conj(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::diagonal(), eigen_assert, i, j, k, Eigen::internal::NegativeSemiDef, Eigen::internal::PositiveSemiDef, ret, Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::rows(), s, SYCL::sign(), Eigen::EigenBase< Derived >::size(), swap(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::swap(), tmp, Eigen::value, and Eigen::internal::ZeroSign.

◆ update()

template<typename MatrixType , typename TranspositionType , typename Workspace , typename WType >
static bool Eigen::internal::ldlt_inplace< Lower >::update ( MatrixType mat,
const TranspositionType &  transpositions,
Workspace &  tmp,
const WType &  w,
const typename MatrixType::RealScalar sigma = 1 
)
inlinestatic
427  {
428  // Apply the permutation to the input w
429  tmp = transpositions * w;
430 
432  }
RowVector3d w
Definition: Matrix_resize_int.cpp:3
int sigma
Definition: calibrate.py:179
static bool updateInPlace(MatrixType &mat, MatrixBase< WDerived > &w, const typename MatrixType::RealScalar &sigma=1)
Definition: LDLT.h:392

References calibrate::sigma, tmp, and w.

Referenced by smc.smc::recursiveBayesian().

◆ updateInPlace()

template<typename MatrixType , typename WDerived >
static bool Eigen::internal::ldlt_inplace< Lower >::updateInPlace ( MatrixType mat,
MatrixBase< WDerived > &  w,
const typename MatrixType::RealScalar sigma = 1 
)
inlinestatic
393  {
394  using numext::isfinite;
395  typedef typename MatrixType::Scalar Scalar;
396  typedef typename MatrixType::RealScalar RealScalar;
397 
398  const Index size = mat.rows();
399  eigen_assert(mat.cols() == size && w.size() == size);
400 
401  RealScalar alpha = 1;
402 
403  // Apply the update
404  for (Index j = 0; j < size; j++) {
405  // Check for termination due to an original decomposition of low-rank
406  if (!(isfinite)(alpha)) break;
407 
408  // Update the diagonal terms
410  Scalar wj = w.coeff(j);
411  RealScalar swj2 = sigma * numext::abs2(wj);
412  RealScalar gamma = dj * alpha + swj2;
413 
414  mat.coeffRef(j, j) += swj2 / alpha;
415  alpha += swj2 / dj;
416 
417  // Update the terms of L
418  Index rs = size - j - 1;
419  w.tail(rs) -= wj * mat.col(j).tail(rs);
420  if (!numext::is_exactly_zero(gamma)) mat.col(j).tail(rs) += (sigma * numext::conj(wj) / gamma) * w.tail(rs);
421  }
422  return true;
423  }
RealScalar alpha
Definition: level1_cplx_impl.h:151
#define isfinite(X)
Definition: main.h:111
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isfinite(const Eigen::bfloat16 &h)
Definition: BFloat16.h:752
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool is_exactly_zero(const X &x)
Definition: Meta.h:592
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: MathFunctions.h:1102
Mdouble gamma(Mdouble gamma_in)
This is the gamma function returns the true value for the half integer value.
Definition: ExtendedMath.cc:116

References Eigen::numext::abs2(), alpha, Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::coeff(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::coeffRef(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::cols(), conj(), eigen_assert, mathsFunc::gamma(), Eigen::numext::is_exactly_zero(), Eigen::numext::isfinite(), isfinite, j, Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::rows(), calibrate::sigma, Eigen::EigenBase< Derived >::size(), and w.


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