Eigen  5.0.1-dev+master
 
Loading...
Searching...
No Matches
BunchKaufman.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2026 Rasmus Munk Larsen <rmlarsen@gmail.com>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_BUNCHKAUFMAN_H
12#define EIGEN_BUNCHKAUFMAN_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20template <typename MatrixType_, int UpLo_>
21struct traits<BunchKaufman<MatrixType_, UpLo_> > : traits<MatrixType_> {
22 using XprKind = MatrixXpr;
23 using StorageKind = SolverStorage;
24 using StorageIndex = int;
25 enum { Flags = 0 };
26};
27
28template <typename MatrixType, int UpLo>
29struct BunchKaufman_Traits;
30
31// Panel width for the blocked factorization (defined below); forward-declared so the size
32// constructor can pre-allocate the panel workspace.
33template <typename Scalar>
34inline Index bunch_kaufman_blocksize();
35
36// prod_k x_k = mantissa 2^exponent with frexp() keeping the mantissa in [1/2, 1), for the real scalars whose
37// scaled_product multiplies directly (half, bfloat16, custom types): only the result has to be representable.
38template <typename RealScalar>
39class bunch_kaufman_balanced_product {
40 public:
41 void multiply(const RealScalar& factor) {
42 RealScalar factorExponent, renorm;
43 const RealScalar factorMantissa = pfrexp<RealScalar>(factor, factorExponent);
44 // |factorMantissa| and |m_mantissa| are in [1/2, 1) unless zero, so the product stays normal and its rounding is
45 // the only error this step adds.
46 m_mantissa = pfrexp<RealScalar>(m_mantissa * factorMantissa, renorm);
47 m_exponent += Index(factorExponent) + Index(renorm);
48 }
49
50 RealScalar value() const {
51 // ldexp() saturates to zero or infinity but takes an int exponent; past this magnitude it has already
52 // saturated, so clamping first cannot change the result.
53 const Index limit = Index(NumTraits<RealScalar>::max_exponent()) - Index(NumTraits<RealScalar>::min_exponent()) +
54 Index(NumTraits<RealScalar>::digits());
55 return numext::ldexp(m_mantissa, int(numext::mini(numext::maxi(m_exponent, -limit), limit)));
56 }
57 RealScalar abs() const { return numext::abs(value()); }
58 RealScalar logAbs() const { return numext::log(abs()); }
59
60 private:
61 RealScalar m_mantissa = RealScalar(1);
62 Index m_exponent = 0;
63};
64} // namespace internal
65
104template <typename MatrixType_, int UpLo_>
105class BunchKaufman : public SolverBase<BunchKaufman<MatrixType_, UpLo_> > {
106 public:
107 using MatrixType = MatrixType_;
108 using Base = SolverBase<BunchKaufman>;
109 friend class SolverBase<BunchKaufman>;
110
111 EIGEN_GENERIC_PUBLIC_INTERFACE(BunchKaufman)
112 enum {
113 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
114 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
115 UpLo = UpLo_
116 };
117
119 // Panel workspace for the blocked algorithm (only allocated for large dynamic-sized problems).
120 using WorkspaceType = Matrix<Scalar, Dynamic, Dynamic>;
123
124 using Traits = internal::BunchKaufman_Traits<MatrixType, UpLo>;
125
132 : m_matrix(),
133 m_l1_norm(0),
134 m_transpositions(),
135 m_subdiag(),
136 m_n_pos(0),
137 m_n_neg(0),
138 m_n_zero(0),
139 m_isInitialized(false),
140 m_info(InvalidInput) {}
141
148 explicit BunchKaufman(Index size)
149 : m_matrix(size, size),
150 m_l1_norm(0),
151 m_transpositions(size),
152 m_subdiag(size),
153 // Pre-allocate the panel workspace to the exact shape compute() needs, so that a subsequent
154 // compute() on a problem of this size performs no heap allocation (the blocked factorization
155 // resizes it to n x (nb+1); resizing to the same shape is a no-op).
156 m_workspace(size, internal::bunch_kaufman_blocksize<Scalar>() + 1),
157 m_n_pos(0),
158 m_n_neg(0),
159 m_n_zero(0),
160 m_isInitialized(false),
161 m_info(InvalidInput) {}
162
169 template <typename InputType>
170 explicit BunchKaufman(const EigenBase<InputType>& matrix)
171 : m_matrix(matrix.rows(), matrix.cols()),
172 m_l1_norm(0),
173 m_transpositions(matrix.rows()),
174 m_subdiag(matrix.rows()),
175 m_n_pos(0),
176 m_n_neg(0),
177 m_n_zero(0),
178 m_isInitialized(false),
179 m_info(InvalidInput) {
180 compute(matrix.derived());
181 }
182
190 template <typename InputType>
192 : m_matrix(matrix.derived()),
193 m_l1_norm(0),
194 m_transpositions(matrix.rows()),
195 m_subdiag(matrix.rows()),
196 m_n_pos(0),
197 m_n_neg(0),
198 m_n_zero(0),
199 m_isInitialized(false),
200 m_info(InvalidInput) {
201 computeInPlace();
202 }
203
205 inline typename Traits::MatrixU matrixU() const {
206 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
207 return Traits::getU(m_matrix);
208 }
209
211 inline typename Traits::MatrixL matrixL() const {
212 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
213 return Traits::getL(m_matrix);
214 }
215
218 inline const TranspositionType& transpositionsP() const {
219 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
220 return m_transpositions;
221 }
222
229 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
230 return m_matrix.diagonal();
231 }
232
238 inline const TmpVectorType& subDiagonal() const {
239 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
240 return m_subdiag;
241 }
242
251 Index numPositive() const {
252 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
253 return m_n_pos;
254 }
255
257 Index numNegative() const {
258 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
259 return m_n_neg;
260 }
261
269 Index numZero() const {
270 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
271 return m_n_zero;
272 }
273
277 bool isPositive() const { return numNegative() == 0 && numPositive() + numZero() == rows(); }
278
282 bool isNegative() const { return numPositive() == 0 && numNegative() + numZero() == rows(); }
283
284#ifdef EIGEN_PARSED_BY_DOXYGEN
293 template <typename Rhs>
295#endif
296
297 template <typename Derived>
298 bool solveInPlace(MatrixBase<Derived>& bAndX) const;
299
300 template <typename InputType>
301 BunchKaufman& compute(const EigenBase<InputType>& matrix);
302
306 RealScalar rcond() const {
307 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
308 return internal::rcond_estimate_helper(m_l1_norm, *this);
309 }
310
317 inline const MatrixType& matrixLDLT() const {
318 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
319 return m_matrix;
320 }
321
322 MatrixType reconstructedMatrix() const;
323
326 * It has only linear complexity (that is, O(n) where n is the dimension of the square matrix)
327 * as the decomposition has already been computed.
328 *
329 * \warning a determinant can be very big or small, so for matrices
330 * of large enough dimension, there is a risk of overflow/underflow.
331 * One way to work around that is to use logAbsDeterminant() and signDeterminant() instead.
332 * Also, do not rely on the determinant being exactly zero for testing
333 * singularity or rank-deficiency.
334 *
335 * \sa absDeterminant(), logAbsDeterminant(), signDeterminant(), MatrixBase::determinant()
336 */
337 Scalar determinant() const;
338
352
367
368 /** \returns the sign of the determinant of the matrix of which *this is the Bunch-Kaufman decomposition,
369 * that is, \c 1, \c -1, or \c 0 if the matrix is singular or has a non-finite pivot.
370 *
371 * The sign is read off the inertia rather than computed from a product, so it is exact and cannot
372 * overflow: \f$ \mathrm{sign}(\det A) = (-1)^{n_-} \f$, with \f$ n_- \f$ the number of negative
373 * eigenvalues, which congruence leaves invariant (Sylvester's law of inertia).
374 *
375 * \sa determinant(), absDeterminant(), logAbsDeterminant(), MatrixBase::determinant()
376 */
377 Scalar signDeterminant() const;
378
385 const BunchKaufman& adjoint() const { return *this; }
386
387 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return m_matrix.rows(); }
388 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_matrix.cols(); }
389
399 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
400 return m_info;
401 }
402
403#ifndef EIGEN_PARSED_BY_DOXYGEN
404 template <typename RhsType, typename DstType>
405 void _solve_impl(const RhsType& rhs, DstType& dst) const;
406
407 template <bool Conjugate, typename RhsType, typename DstType>
408 void _solve_impl_transposed(const RhsType& rhs, DstType& dst) const;
409#endif
410
411 protected:
412 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
413
414
415 template <typename Derived>
416 void applyD(MatrixBase<Derived>& x) const;
417
420 template <bool Conjugate, typename Derived>
421 void solveInPlaceD(MatrixBase<Derived>& x) const;
422
423 BunchKaufman& computeInPlace();
424
426 void computeInertia();
427
430 static RealScalar scaledBlockDeterminant(const RealScalar& d11, const RealScalar& d22, const RealScalar& d21);
431
436 using DeterminantProduct =
437 std::conditional_t<internal::has_scaled_product<RealScalar>::value, internal::scaled_product<RealScalar>,
438 internal::bunch_kaufman_balanced_product<RealScalar>>;
439 DeterminantProduct determinantD() const;
440
441 MatrixType m_matrix;
442 RealScalar m_l1_norm;
443 TranspositionType m_transpositions;
444 TmpVectorType m_subdiag;
445 WorkspaceType m_workspace;
446 Index m_n_pos;
447 Index m_n_neg;
448 Index m_n_zero;
449 bool m_isInitialized;
450 ComputationInfo m_info;
451};
452
453namespace internal {
454
458template <typename RealScalar>
459EIGEN_DEVICE_FUNC inline RealScalar bunch_kaufman_alpha() {
460 return (RealScalar(1) + numext::sqrt(RealScalar(17))) / RealScalar(8);
461}
462
465template <typename Scalar>
466inline Index bunch_kaufman_blocksize() {
467#ifdef EIGEN_BUNCHKAUFMAN_BLOCKSIZE
468 return Index(EIGEN_BUNCHKAUFMAN_BLOCKSIZE);
469#else
470 return 64;
471#endif
472}
473
477template <bool IsComplex>
478struct bunch_kaufman_magnitude {
479 template <typename VectorType>
480 static auto run(const VectorType& v) -> decltype(v.cwiseAbs()) {
481 return v.cwiseAbs();
482 }
483};
484template <>
485struct bunch_kaufman_magnitude<true> {
486 template <typename VectorType>
487 static auto run(const VectorType& v) -> decltype(v.real().cwiseAbs() + v.imag().cwiseAbs()) {
488 return v.real().cwiseAbs() + v.imag().cwiseAbs();
489 }
490};
491
495template <bool LastOnTies = false, typename VectorType>
496typename NumTraits<typename VectorType::Scalar>::Real bunch_kaufman_max(const VectorType& v, Index* index = nullptr) {
497 using Magnitude = bunch_kaufman_magnitude<NumTraits<typename VectorType::Scalar>::IsComplex>;
498 if (index == nullptr) return Magnitude::run(v).maxCoeff();
499 EIGEN_IF_CONSTEXPR (LastOnTies) {
500 const typename NumTraits<typename VectorType::Scalar>::Real m = Magnitude::run(v.reverse()).maxCoeff(index);
501 *index = v.size() - 1 - *index;
502 return m;
503 }
504 return Magnitude::run(v).maxCoeff(index);
505}
506
507template <int UpLo>
508struct bunch_kaufman;
509
510template <>
511struct bunch_kaufman<Lower> {
512 // Unblocked (level-2 BLAS) Bunch-Kaufman factorization of the lower triangle of `mat`, in place.
513 // Columns [k0, n) are factorized. On output:
514 // - the strictly-lower triangle holds the unit lower factor L (with explicit zeros at the
515 // sub-diagonal positions of 2x2 blocks),
516 // - the diagonal holds the main diagonal of D,
517 // - subdiag(k) holds D(k+1,k) for each 2x2 block starting at column k (and 0 elsewhere),
518 // - transpositions encodes the symmetric permutation P (applied in increasing index order).
519 // Returns 0 on success, or the (1-based) index of the first exactly-zero pivot encountered.
520 // LastOnTies takes the last of equal pivot candidates rather than the first; see bunch_kaufman_max.
521 template <bool LastOnTies = false, typename MatrixType, typename TranspositionType, typename SubDiagType>
522 static Index unblocked(MatrixType& mat, TranspositionType& transpositions, SubDiagType& subdiag, Index k0 = 0) {
523 using Scalar = typename MatrixType::Scalar;
524 using RealScalar = typename MatrixType::RealScalar;
525 using StorageIndex = typename TranspositionType::StorageIndex;
526 const Index n = mat.rows();
527 const RealScalar alpha = bunch_kaufman_alpha<RealScalar>();
528 Index info = 0;
529
530 Index k = k0;
531 while (k < n) {
532 Index kstep = 1;
533 Index kp = k;
534 const RealScalar absakk = numext::abs(numext::real(mat.coeff(k, k)));
535
536 // colmax = max_{i>k} |mat(i,k)|, attained at row imax.
537 Index imax = k;
538 RealScalar colmax(0);
539 if (k + 1 < n) {
540 Index rel = 0;
541 colmax = bunch_kaufman_max<LastOnTies>(mat.col(k).tail(n - k - 1), &rel);
542 imax = k + 1 + rel;
543 }
544
545 if (numext::is_exactly_zero((numext::maxi)(absakk, colmax)) || (numext::isnan)(absakk)) {
546 // The whole remaining column is zero: 1x1 zero pivot, matrix is singular.
547 kp = k;
548 if (info == 0) info = k + 1;
549 mat.coeffRef(k, k) = Scalar(numext::real(mat.coeff(k, k)));
550 } else if (absakk >= alpha * colmax) {
551 // 1x1 pivot at k, no interchange.
552 kp = k;
553 } else {
554 // rowmax = largest off-diagonal magnitude in row/column imax.
555 RealScalar rowmax = bunch_kaufman_max(mat.row(imax).segment(k, imax - k));
556 if (imax + 1 < n) {
557 RealScalar rowmax2 = bunch_kaufman_max(mat.col(imax).tail(n - imax - 1));
558 rowmax = (numext::maxi)(rowmax, rowmax2);
559 }
560 if (absakk >= alpha * colmax * (colmax / rowmax)) {
561 // 1x1 pivot at k.
562 kp = k;
563 } else if (numext::abs(numext::real(mat.coeff(imax, imax))) >= alpha * rowmax) {
564 // 1x1 pivot at imax: interchange rows/columns k and imax.
565 kp = imax;
566 } else {
567 // 2x2 pivot at (k, imax): interchange rows/columns k+1 and imax.
568 kp = imax;
569 kstep = 2;
570 }
571 }
572
573 const Index kk = k + kstep - 1; // column of the pivot block to interchange with kp
574 if (kp != kk) selfadjoint_swap_lower(mat, kk, kp);
575
576 if (kstep == 1) {
577 transpositions.coeffRef(k) = StorageIndex(kp);
578 subdiag.coeffRef(k) = Scalar(0);
579
580 const RealScalar dkk = numext::real(mat.coeff(k, k));
581 mat.coeffRef(k, k) = Scalar(dkk);
582 const Index rs = n - k - 1;
583 if (rs > 0) {
584 if (!numext::is_exactly_zero(dkk)) {
585 // A22 <- A22 - (1/dkk) w w^*, with w = mat(k+1:n, k); then L column = w / dkk.
586 auto w = mat.col(k).tail(rs);
587 mat.block(k + 1, k + 1, rs, rs).template selfadjointView<Lower>().rankUpdate(w, RealScalar(-1) / dkk);
588 w /= dkk;
589 } else if (info == 0) {
590 info = k + 1;
591 }
592 }
593 k += 1;
594 } else {
595 transpositions.coeffRef(k) = StorageIndex(k);
596 transpositions.coeffRef(k + 1) = StorageIndex(kp);
597
598 const RealScalar d11 = numext::real(mat.coeff(k, k));
599 const RealScalar d22 = numext::real(mat.coeff(k + 1, k + 1));
600 const Scalar d21 = mat.coeff(k + 1, k);
601 mat.coeffRef(k, k) = Scalar(d11);
602 mat.coeffRef(k + 1, k + 1) = Scalar(d22);
603 // Scaled 2x2 inverse (LAPACK xSYTF2/xHETF2 strategy). NEVER form det = d11*d22 - |d21|^2 or
604 // abs2(d21) directly: those over/underflow for well-conditioned but extreme-scaled blocks
605 // (e.g. [[0,s],[s,0]], s=1e200, where det = -s^2 overflows/underflows). Instead divide
606 // through by the off-diagonal d21, so the scaled determinant
607 // denom = real(ak*akm1) - 1 = det / |d21|^2 (with ak = d22/d21, akm1 = d11/conj(d21))
608 // stays O(1). Divide by d21 itself, never by a hoisted reciprocal: 1/d21 overflows once |d21|
609 // is subnormal, where these quotients are still finite (issue #3142).
610 const Scalar cjd = numext::conj(d21);
611 const Scalar ak = numext::divide(d22, d21);
612 const Scalar akm1 = numext::divide(d11, cjd);
613 const RealScalar denom = numext::real(ak * akm1) - RealScalar(1);
614 // The pivot criterion gives |d11 d22| <= alpha^2 |d21|^2 with alpha < 1, so in exact arithmetic
615 // -1 - alpha^2 < denom < alpha^2 - 1. Outside that range ak overflowed -- the criterion bounds
616 // |d22| only against the largest entry of its own row -- or a NaN entry was pulled into the
617 // block. Either way the block's inverse is not representable: report it rather than silently
618 // propagate it.
619 if (info == 0 && !(denom < RealScalar(0) && denom > RealScalar(-2))) info = k + 1;
620
621 const Index rs = n - k - 2;
622 if (rs > 0) {
623 // Fused factor-column computation and trailing update, in a single pass over the lower
624 // triangle of A22 (the xSYTF2/xHETF2 strategy). For each trailing column j, first form the
625 // two unit lower factor entries of row j (the rows of U D^{-1}, in the scaled form above),
626 // l0_j = t*((ak*u0_j - u1_j)/conj(d21)), l1_j = t*((akm1*u1_j - u0_j)/d21),
627 // dividing before scaling by t: the quotient is denom*l_j, within a factor 1 + alpha^2 of the
628 // result, whereas t*(ak*u0_j - u1_j) can overflow (|t| < 1/(1 - alpha^2)) where l_j is finite.
629 // Then update column j against the ORIGINAL pivot columns u = [u0 u1] (they carry the D
630 // scale, U = L*D, so no 1/det factor appears):
631 // A22(i,j) -= u0_i*conj(l0_j) + u1_i*conj(l1_j), i >= j.
632 // Rows < j of the pivot columns already hold L, rows >= j still hold U -- exactly the
633 // entries each column update needs, so no workspace is required. Compared with composing
634 // self-adjoint rank-1/rank-2 updates (syr + syr + syr2) this halves the flops and touches
635 // the trailing triangle once instead of three times.
636 const RealScalar t = RealScalar(1) / denom;
637 auto c0 = mat.col(k).tail(rs);
638 auto c1 = mat.col(k + 1).tail(rs);
639 for (Index j = 0; j < rs; ++j) {
640 const Scalar u0 = c0.coeff(j);
641 const Scalar u1 = c1.coeff(j);
642 const Scalar l0 = t * numext::divide(ak * u0 - u1, cjd);
643 const Scalar l1 = t * numext::divide(akm1 * u1 - u0, d21);
644 const Index len = rs - j;
645 mat.col(k + 2 + j).tail(len) -= numext::conj(l0) * c0.tail(len) + numext::conj(l1) * c1.tail(len);
646 c0.coeffRef(j) = l0;
647 c1.coeffRef(j) = l1;
648 // Keep the updated diagonal exactly real (the correction is Hermitian; roundoff would
649 // otherwise leave a tiny imaginary part).
650 EIGEN_IF_CONSTEXPR (NumTraits<Scalar>::IsComplex) {
651 mat.coeffRef(k + 2 + j, k + 2 + j) = Scalar(numext::real(mat.coeff(k + 2 + j, k + 2 + j)));
652 }
653 }
654 }
655 // Move the 2x2 off-diagonal of D out of the L storage.
656 subdiag.coeffRef(k) = d21;
657 subdiag.coeffRef(k + 1) = Scalar(0);
658 mat.coeffRef(k + 1, k) = Scalar(0);
659 k += 2;
660 }
661 }
662 return info;
663 }
664
665 // Partial factorization of a panel of at most `nb` columns of the lower triangle of `mat`, starting
666 // at column k0, using the Bunch-Kaufman method (level-2 within the panel). Follows the panel/workspace
667 // structure of LAPACK's xLASYF. The trailing sub-matrix mat(k0+kb:n, k0+kb:n) is left untouched; the
668 // workspace `W` (n x nb) returns, in its first kb columns, the product L21*D restricted to the panel
669 // columns, so that the caller can apply the deferred trailing update A22 <- A22 - L21 * (L21*D)^* with
670 // a single level-3 (triangular) matrix product. Returns the number kb (<= nb) of columns factorized.
671 template <bool LastOnTies = false, typename MatrixType, typename WorkspaceType, typename TranspositionType,
672 typename SubDiagType>
673 static Index partial_factor(MatrixType& mat, Index k0, Index nb, WorkspaceType& W, TranspositionType& transpositions,
674 SubDiagType& subdiag, Index& info) {
675 using Scalar = typename MatrixType::Scalar;
676 using RealScalar = typename MatrixType::RealScalar;
677 using StorageIndex = typename TranspositionType::StorageIndex;
678 const Index n = mat.rows();
679 const RealScalar alpha = bunch_kaufman_alpha<RealScalar>();
680 constexpr bool is_complex = NumTraits<Scalar>::IsComplex;
681
682 Index j = 0;
683 while (j < nb) {
684 const Index jc = k0 + j;
685 const Index h = n - jc;
686
687 // W(jc:n, j) <- updated column jc = (column jc of A) minus the contributions of the panel columns
688 // [k0, jc) already factorized (those are stored as L in mat, and L*D in W).
689 W.col(j).segment(jc, h) = mat.col(jc).segment(jc, h);
690 EIGEN_IF_CONSTEXPR (is_complex) W.coeffRef(jc, j) = Scalar(numext::real(W.coeff(jc, j)));
691 if (j > 0) {
692 W.col(j).segment(jc, h).noalias() -= mat.block(jc, k0, h, j) * W.row(jc).head(j).adjoint();
693 EIGEN_IF_CONSTEXPR (is_complex) W.coeffRef(jc, j) = Scalar(numext::real(W.coeff(jc, j)));
694 }
695
696 Index kstep = 1;
697 Index kp = jc;
698 const RealScalar absakk = numext::abs(numext::real(W.coeff(jc, j)));
699 Index imax = jc;
700 RealScalar colmax(0);
701 if (jc + 1 < n) {
702 Index rel = 0;
703 colmax = bunch_kaufman_max<LastOnTies>(W.col(j).segment(jc + 1, n - jc - 1), &rel);
704 imax = jc + 1 + rel;
705 }
706
707 if (numext::is_exactly_zero((numext::maxi)(absakk, colmax)) || (numext::isnan)(absakk)) {
708 kp = jc;
709 if (info == 0) info = jc + 1;
710 } else if (absakk >= alpha * colmax) {
711 kp = jc;
712 } else {
713 // W(jc:n, j+1) <- updated column imax (its leading row part is read from row imax of mat and
714 // conjugated, the trailing part from column imax).
715 const Index hr = imax - jc;
716 if (hr > 0) W.col(j + 1).segment(jc, hr) = mat.row(imax).segment(jc, hr).adjoint();
717 W.col(j + 1).segment(imax, n - imax) = mat.col(imax).segment(imax, n - imax);
718 EIGEN_IF_CONSTEXPR (is_complex) W.coeffRef(imax, j + 1) = Scalar(numext::real(W.coeff(imax, j + 1)));
719 if (j > 0) {
720 W.col(j + 1).segment(jc, n - jc).noalias() -= mat.block(jc, k0, n - jc, j) * W.row(imax).head(j).adjoint();
721 EIGEN_IF_CONSTEXPR (is_complex) W.coeffRef(imax, j + 1) = Scalar(numext::real(W.coeff(imax, j + 1)));
722 }
723
724 RealScalar rowmax(0);
725 if (imax > jc) rowmax = bunch_kaufman_max(W.col(j + 1).segment(jc, imax - jc));
726 if (imax + 1 < n) {
727 RealScalar rowmax2 = bunch_kaufman_max(W.col(j + 1).segment(imax + 1, n - imax - 1));
728 rowmax = (numext::maxi)(rowmax, rowmax2);
729 }
730 if (absakk >= alpha * colmax * (colmax / rowmax)) {
731 kp = jc;
732 } else if (numext::abs(numext::real(W.coeff(imax, j + 1))) >= alpha * rowmax) {
733 kp = imax;
734 // imax becomes the 1x1 pivot column: its updated column (in W(:,j+1)) replaces W(:,j).
735 W.col(j).segment(jc, n - jc) = W.col(j + 1).segment(jc, n - jc);
736 } else {
737 kp = imax;
738 kstep = 2;
739 }
740 }
741
742 // A 2x2 block must fit in the panel; otherwise defer this column to the next panel.
743 if (kstep == 2 && j + 1 >= nb) break;
744
745 const Index kk = jc + kstep - 1;
746 if (kp != kk) {
747 selfadjoint_swap_lower(mat, kk, kp);
748 const Index nwc = j + kstep; // number of populated W columns
749 W.row(kk).head(nwc).swap(W.row(kp).head(nwc));
750 }
751
752 if (kstep == 1) {
753 transpositions.coeffRef(jc) = StorageIndex(kp);
754 subdiag.coeffRef(jc) = Scalar(0);
755 const RealScalar dval = numext::real(W.coeff(jc, j));
756 mat.coeffRef(jc, jc) = Scalar(dval);
757 const Index rs = n - jc - 1;
758 if (rs > 0) {
759 if (!numext::is_exactly_zero(dval)) {
760 mat.col(jc).tail(rs) = W.col(j).segment(jc + 1, rs) / dval;
761 } else {
762 // Zero pivot (singular): the Schur column is zero too. Store an explicit zero L column so
763 // that matrixL() is well formed, matching the unblocked path (which leaves the already
764 // zeroed Schur column in place).
765 mat.col(jc).tail(rs).setZero();
766 if (info == 0) info = jc + 1;
767 }
768 }
769 j += 1;
770 } else {
771 transpositions.coeffRef(jc) = StorageIndex(jc);
772 transpositions.coeffRef(jc + 1) = StorageIndex(kp);
773 const RealScalar d11 = numext::real(W.coeff(jc, j));
774 const Scalar d21 = W.coeff(jc + 1, j);
775 const RealScalar d22 = numext::real(W.coeff(jc + 1, j + 1));
776 mat.coeffRef(jc, jc) = Scalar(d11);
777 mat.coeffRef(jc + 1, jc + 1) = Scalar(d22);
778 // Scaled 2x2 inverse (see unblocked()): divide through by d21 so the scaled determinant
779 // denom = det/|d21|^2 stays O(1); det = d11*d22 - |d21|^2 and abs2(d21) are never formed (they
780 // over/underflow on extreme-scaled blocks). The deferred level-3 trailing update below uses W
781 // (= L*D, original scale), so it carries no 1/det factor either.
782 const Scalar cjd = numext::conj(d21);
783 const Scalar ak = numext::divide(d22, d21);
784 const Scalar akm1 = numext::divide(d11, cjd);
785 const RealScalar denom = numext::real(ak * akm1) - RealScalar(1);
786 if (info == 0 && !(denom < RealScalar(0) && denom > RealScalar(-2))) info = jc + 1;
787 const Index rs = n - jc - 2;
788 if (rs > 0) {
789 // L(jc+2:n, jc:jc+1) = W(jc+2:n, j:j+1) * D^{-1}, as vectorized column expressions, divided
790 // before being scaled by t for the reason given in unblocked():
791 // L_k = t*((ak*w0 - w1)/conj(d21)), L_{k+1} = t*((akm1*w1 - w0)/d21).
792 const RealScalar t = RealScalar(1) / denom;
793 auto w0 = W.col(j).segment(jc + 2, rs);
794 auto w1 = W.col(j + 1).segment(jc + 2, rs);
795 mat.col(jc).tail(rs) = t * ((ak * w0 - w1) / cjd);
796 mat.col(jc + 1).tail(rs) = t * ((akm1 * w1 - w0) / d21);
797 }
798 subdiag.coeffRef(jc) = d21;
799 subdiag.coeffRef(jc + 1) = Scalar(0);
800 mat.coeffRef(jc + 1, jc) = Scalar(0);
801 j += 2;
802 }
803 }
804 return j;
805 }
806
807 // Blocked (level-3 BLAS) Bunch-Kaufman factorization of the lower triangle of `mat`, in place.
808 template <bool LastOnTies = false, typename MatrixType, typename TranspositionType, typename SubDiagType,
809 typename WorkspaceType>
810 static Index blocked(MatrixType& mat, TranspositionType& transpositions, SubDiagType& subdiag,
811 WorkspaceType& workspace) {
812 const Index n = mat.rows();
813 const Index nb = bunch_kaufman_blocksize<typename MatrixType::Scalar>();
814 if (nb < 2 || n <= nb) return unblocked<LastOnTies>(mat, transpositions, subdiag, 0);
815
816 // One extra workspace column holds the candidate ("imax") column examined during pivot selection.
817 workspace.resize(n, nb + 1);
818 Index info = 0;
819 Index k = 0;
820 while (k < n) {
821 if (n - k > nb) {
822 const Index kb = partial_factor<LastOnTies>(mat, k, nb, workspace, transpositions, subdiag, info);
823 const Index rs = n - k - kb;
824 if (rs > 0) {
825 // Deferred trailing update of the lower triangle: A22 <- A22 - L21 * (L21*D)^*.
826 mat.block(k + kb, k + kb, rs, rs).template triangularView<Lower>() -=
827 mat.block(k + kb, k, rs, kb) * workspace.block(k + kb, 0, rs, kb).adjoint();
828 }
829 if (kb == 0) { // defensive: avoid an infinite loop (should not happen for nb >= 2)
830 info = (info == 0) ? unblocked<LastOnTies>(mat, transpositions, subdiag, k) : info;
831 break;
832 }
833 k += kb;
834 } else {
835 const Index info2 = unblocked<LastOnTies>(mat, transpositions, subdiag, k);
836 if (info == 0) info = info2;
837 break;
838 }
839 }
840 return info;
841 }
842};
843
844template <>
845struct bunch_kaufman<Upper> {
846 template <typename MatrixType, typename TranspositionType, typename SubDiagType>
847 static EIGEN_STRONG_INLINE Index unblocked(MatrixType& mat, TranspositionType& transpositions, SubDiagType& subdiag,
848 Index k0 = 0) {
849 Transpose<MatrixType> matt(mat);
850 return bunch_kaufman<Lower>::unblocked(matt, transpositions, subdiag, k0);
851 }
852
853 template <typename MatrixType, typename TranspositionType, typename SubDiagType, typename WorkspaceType>
854 static EIGEN_STRONG_INLINE Index blocked(MatrixType& mat, TranspositionType& transpositions, SubDiagType& subdiag,
855 WorkspaceType& workspace) {
856 Transpose<MatrixType> matt(mat);
857 return bunch_kaufman<Lower>::blocked(matt, transpositions, subdiag, workspace);
858 }
859};
860
861template <typename MatrixType>
862struct BunchKaufman_Traits<MatrixType, Lower> {
863 using MatrixL = const TriangularView<const MatrixType, UnitLower>;
864 using MatrixU = const TriangularView<const typename MatrixType::AdjointReturnType, UnitUpper>;
865 static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); }
866 static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); }
867};
868
869template <typename MatrixType>
870struct BunchKaufman_Traits<MatrixType, Upper> {
871 using MatrixL = const TriangularView<const typename MatrixType::AdjointReturnType, UnitLower>;
872 using MatrixU = const TriangularView<const MatrixType, UnitUpper>;
873 static inline MatrixL getL(const MatrixType& m) { return MatrixL(m.adjoint()); }
874 static inline MatrixU getU(const MatrixType& m) { return MatrixU(m); }
875};
876
877} // end namespace internal
878
879template <typename MatrixType, int UpLo_>
880template <typename Derived>
881void BunchKaufman<MatrixType, UpLo_>::applyD(MatrixBase<Derived>& x) const {
882 const Index n = m_matrix.rows();
883 Index k = 0;
884 while (k < n) {
885 if (k + 1 < n && !numext::is_exactly_zero(m_subdiag.coeff(k))) {
886 const RealScalar d11 = numext::real(m_matrix.coeff(k, k));
887 const RealScalar d22 = numext::real(m_matrix.coeff(k + 1, k + 1));
888 const Scalar d21 = m_subdiag.coeff(k);
889 for (Index j = 0; j < x.cols(); ++j) {
890 const Scalar x0 = x.coeff(k, j);
891 const Scalar x1 = x.coeff(k + 1, j);
892 x.coeffRef(k, j) = d11 * x0 + numext::conj(d21) * x1;
893 x.coeffRef(k + 1, j) = d21 * x0 + d22 * x1;
894 }
895 k += 2;
896 } else {
897 x.row(k) *= numext::real(m_matrix.coeff(k, k));
898 k += 1;
899 }
900 }
901}
902
903template <typename MatrixType, int UpLo_>
904template <bool Conjugate, typename Derived>
905void BunchKaufman<MatrixType, UpLo_>::solveInPlaceD(MatrixBase<Derived>& x) const {
906 const Index n = m_matrix.rows();
907 // Use the pseudo-inverse of singular 1x1 blocks (see Eigen bug 241 for LDLT). The 2x2 blocks
908 // produced by Bunch-Kaufman pivoting are non-singular by construction.
909 const RealScalar tol = (std::numeric_limits<RealScalar>::min)();
910 Index k = 0;
911 while (k < n) {
912 if (k + 1 < n && !numext::is_exactly_zero(m_subdiag.coeff(k))) {
913 const RealScalar d11 = numext::real(m_matrix.coeff(k, k));
914 const RealScalar d22 = numext::real(m_matrix.coeff(k + 1, k + 1));
915 // D = [ d11 conj(d21) ; d21 d22 ]; for the transpose solve use conj(d21) instead of d21.
916 const Scalar d21 = Conjugate ? m_subdiag.coeff(k) : numext::conj(m_subdiag.coeff(k));
917 // Scaled 2x2 solve (LAPACK xSYTRS/xHETRS): divide through by d21 so the scaled determinant
918 // denom = det/|d21|^2 is O(1); det = d11*d22 - |d21|^2 is never formed (it over/underflows on
919 // extreme-scaled blocks, e.g. [[0,s],[s,0]], s=1e+-200). Every quotient divides by d21 itself:
920 // a hoisted 1/d21 overflows once |d21| is subnormal (issue #3142).
921 const Scalar cjd = numext::conj(d21);
922 const Scalar ak = numext::divide(d22, d21);
923 const Scalar akm1 = numext::divide(d11, cjd);
924 const RealScalar t = RealScalar(1) / (numext::real(ak * akm1) - RealScalar(1));
925 for (Index j = 0; j < x.cols(); ++j) {
926 const Scalar bk = numext::divide(x.coeff(k + 1, j), d21);
927 const Scalar bkm1 = numext::divide(x.coeff(k, j), cjd);
928 x.coeffRef(k, j) = t * (ak * bkm1 - bk);
929 x.coeffRef(k + 1, j) = t * (akm1 * bk - bkm1);
930 }
931 k += 2;
932 } else {
933 const RealScalar dk = numext::real(m_matrix.coeff(k, k));
934 if (numext::abs(dk) > tol)
935 x.row(k) /= dk;
936 else
937 x.row(k).setZero();
938 k += 1;
939 }
940 }
941}
942
943// det(D_k) itself over- or underflows on an extreme-scaled 2x2 block, so it is only ever formed scaled by
944// |d21|^2. Divide by |d21| twice rather than multiply by its reciprocal, which overflows once |d21| is
945// subnormal. The pivot criterion bounds |q| by a^2 < 1 with a = (1+sqrt(17))/8, so |q| >= 1 or NaN is an
946// artifact of d22/d21 overflowing -- the criterion bounds |d22| only against its own row -- and
947// det(D_k) = -|d21|^2 to within that same bound there.
948template <typename MatrixType, int UpLo_>
949typename BunchKaufman<MatrixType, UpLo_>::RealScalar BunchKaufman<MatrixType, UpLo_>::scaledBlockDeterminant(
950 const RealScalar& d11, const RealScalar& d22, const RealScalar& d21) {
951 const RealScalar q = (d11 / d21) * (d22 / d21);
952 return (q > RealScalar(-1) && q < RealScalar(1)) ? q - RealScalar(1) : RealScalar(-1);
953}
954
955template <typename MatrixType, int UpLo_>
956void BunchKaufman<MatrixType, UpLo_>::computeInertia() {
957 const Index n = m_matrix.rows();
958 m_n_pos = m_n_neg = m_n_zero = 0;
959 Index k = 0;
960 while (k < n) {
961 if (k + 1 < n && !numext::is_exactly_zero(m_subdiag.coeff(k))) {
962 const RealScalar d11 = numext::real(m_matrix.coeff(k, k));
963 const RealScalar d22 = numext::real(m_matrix.coeff(k + 1, k + 1));
964 const RealScalar d21 = numext::abs(m_subdiag.coeff(k));
965 // Every Bunch-Kaufman 2x2 block is indefinite: det(D_k) = |d21|^2 (q - 1) with |q| < alpha^2 < 1.
966 if ((numext::isfinite)(d11) && (numext::isfinite)(d22) && (numext::isfinite)(d21)) {
967 ++m_n_pos;
968 ++m_n_neg;
969 }
970 k += 2;
971 } else {
972 const RealScalar dk = numext::real(m_matrix.coeff(k, k));
973 if (!(numext::isfinite)(dk)) {
974 // A non-finite pivot has no inertia to count.
975 } else if (dk > RealScalar(0))
976 ++m_n_pos;
977 else if (dk < RealScalar(0))
978 ++m_n_neg;
979 else
980 ++m_n_zero;
981 k += 1;
982 }
983 }
984}
985
988template <typename MatrixType, int UpLo_>
989template <typename InputType>
990BunchKaufman<MatrixType, UpLo_>& BunchKaufman<MatrixType, UpLo_>::compute(const EigenBase<InputType>& a) {
991 EIGEN_INTERNAL_ASSERT_SQUARE(a);
992 m_matrix = a.derived();
993 return computeInPlace();
994}
995
997template <typename MatrixType, int UpLo_>
998BunchKaufman<MatrixType, UpLo_>& BunchKaufman<MatrixType, UpLo_>::computeInPlace() {
999 EIGEN_INTERNAL_ASSERT_SQUARE(m_matrix);
1000 const Index size = m_matrix.rows();
1001
1002 // L1 norm of the implicit self-adjoint matrix, for rcond().
1003 m_l1_norm = m_matrix.template selfadjointView<UpLo_>().l1Norm();
1004
1005 m_transpositions.resize(size);
1006 m_subdiag.resize(size);
1007 m_isInitialized = false;
1008
1009 Index info = internal::bunch_kaufman<UpLo>::blocked(m_matrix, m_transpositions, m_subdiag, m_workspace);
1010 m_info = (info == 0) ? Success : NumericalIssue;
1011
1012 // The upper variant factorizes the transpose of the (Hermitian) matrix, i.e. its complex conjugate,
1013 // so the recorded 2x2 off-diagonals of D come out conjugated; undo that so that m_subdiag holds the
1014 // true sub-diagonal D(k+1,k) consumed by applyD()/solveInPlaceD()/computeInertia(). (No-op when real.)
1015 EIGEN_IF_CONSTEXPR (int(UpLo) == int(Upper) && NumTraits<Scalar>::IsComplex) {
1016 m_subdiag = m_subdiag.conjugate();
1017 }
1018
1019 computeInertia();
1020
1021 // computeInertia() leaves non-finite pivot blocks out of the counts.
1022 if (m_n_pos + m_n_neg + m_n_zero < size) m_info = NumericalIssue;
1023
1024 m_isInitialized = true;
1025 return *this;
1026}
1027
1028#ifndef EIGEN_PARSED_BY_DOXYGEN
1029template <typename MatrixType_, int UpLo_>
1030template <typename RhsType, typename DstType>
1031void BunchKaufman<MatrixType_, UpLo_>::_solve_impl(const RhsType& rhs, DstType& dst) const {
1032 _solve_impl_transposed<true>(rhs, dst);
1033}
1034
1035template <typename MatrixType_, int UpLo_>
1036template <bool Conjugate, typename RhsType, typename DstType>
1037void BunchKaufman<MatrixType_, UpLo_>::_solve_impl_transposed(const RhsType& rhs, DstType& dst) const {
1038 // A^{-1} b = P^T L^{-*} D^{-1} L^{-1} P b (and the conjugated variants for transpose / adjoint solves).
1039 dst = m_transpositions * rhs;
1040 matrixL().template conjugateIf<!Conjugate>().solveInPlace(dst);
1041 solveInPlaceD<Conjugate>(dst);
1042 matrixL().transpose().template conjugateIf<Conjugate>().solveInPlace(dst);
1043 dst = m_transpositions.transpose() * dst;
1044}
1045#endif
1046
1053template <typename MatrixType, int UpLo_>
1054template <typename Derived>
1055bool BunchKaufman<MatrixType, UpLo_>::solveInPlace(MatrixBase<Derived>& bAndX) const {
1056 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
1057 EIGEN_INTERNAL_ASSERT_SAME_ROWS(m_matrix, bAndX);
1058 bAndX = this->solve(bAndX);
1059 return true;
1060}
1061
1062template <typename MatrixType, int UpLo_>
1063typename BunchKaufman<MatrixType, UpLo_>::DeterminantProduct BunchKaufman<MatrixType, UpLo_>::determinantD() const {
1064 const Index n = m_matrix.rows();
1065 DeterminantProduct product;
1066 Index k = 0;
1067 while (k < n) {
1068 if (k + 1 < n && !numext::is_exactly_zero(m_subdiag.coeff(k))) {
1069 const RealScalar d11 = numext::real(m_matrix.coeff(k, k));
1070 const RealScalar d22 = numext::real(m_matrix.coeff(k + 1, k + 1));
1071 const RealScalar d21 = numext::abs(m_subdiag.coeff(k));
1072 // det(D_k) = |d21| |d21| (det(D_k) / |d21|^2): |d21|^2 can leave the range where det(D) does not.
1073 product.multiply(d21);
1074 product.multiply(d21);
1075 product.multiply(scaledBlockDeterminant(d11, d22, d21));
1076 k += 2;
1077 } else {
1078 product.multiply(numext::real(m_matrix.coeff(k, k)));
1079 k += 1;
1080 }
1081 }
1082 return product;
1083}
1084
1085// A = P^T L D L^* P with L unit triangular, so det(A) = det(D) = prod over the 1x1 and 2x2 blocks of D.
1086
1087template <typename MatrixType, int UpLo_>
1088typename BunchKaufman<MatrixType, UpLo_>::Scalar BunchKaufman<MatrixType, UpLo_>::determinant() const {
1089 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
1090 return Scalar(determinantD().value());
1091}
1092
1093template <typename MatrixType, int UpLo_>
1095 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
1096 return determinantD().abs();
1097}
1098
1099template <typename MatrixType, int UpLo_>
1101 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
1102 EIGEN_IF_CONSTEXPR (internal::has_scaled_product<RealScalar>::value) return determinantD().logAbs();
1103 const Index n = m_matrix.rows();
1104 RealScalar result(0);
1105 Index k = 0;
1106 while (k < n) {
1107 if (k + 1 < n && !numext::is_exactly_zero(m_subdiag.coeff(k))) {
1108 // log|det(D_k)| = 2 log|d21| + log|det(D_k)/|d21|^2|.
1109 const RealScalar d11 = numext::real(m_matrix.coeff(k, k));
1110 const RealScalar d22 = numext::real(m_matrix.coeff(k + 1, k + 1));
1111 const RealScalar d21 = numext::abs(m_subdiag.coeff(k));
1112 const RealScalar scaled = scaledBlockDeterminant(d11, d22, d21);
1113 result += RealScalar(2) * numext::log(d21) + numext::log(numext::abs(scaled));
1114 k += 2;
1115 } else {
1116 result += numext::log(numext::abs(numext::real(m_matrix.coeff(k, k))));
1117 k += 1;
1118 }
1119 }
1120 return result;
1121}
1122
1123template <typename MatrixType, int UpLo_>
1124typename BunchKaufman<MatrixType, UpLo_>::Scalar BunchKaufman<MatrixType, UpLo_>::signDeterminant() const {
1125 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
1126 if (m_n_zero > 0 || m_n_pos + m_n_neg + m_n_zero < rows()) return Scalar(0);
1127 return Scalar((m_n_neg % 2 == 0) ? 1 : -1);
1128}
1129
1132template <typename MatrixType, int UpLo_>
1134 eigen_assert(m_isInitialized && "BunchKaufman is not initialized.");
1135 MatrixType res = matrixU();
1136 applyD(res);
1137 res = matrixL() * res;
1138 // P^T (L D L^*) P; the stored pivots cannot alias the new result.
1139 auto lower_triangle = res.template selfadjointView<Lower>();
1140 for (Index k = m_matrix.rows() - 1; k >= 0; --k) lower_triangle.applyTransposition(k, m_transpositions.coeff(k));
1141 res.template triangularView<StrictlyUpper>() = res.adjoint();
1142
1143 return res;
1144}
1145
1150template <typename MatrixType, unsigned int UpLo>
1155
1160template <typename Derived>
1164
1165} // end namespace Eigen
1166
1167#endif // EIGEN_BUNCHKAUFMAN_H
Bunch-Kaufman factorization of a symmetric / Hermitian indefinite matrix.
Definition BunchKaufman.h:105
RealScalar logAbsDeterminant() const
Definition BunchKaufman.h:1100
Index numZero() const
Definition BunchKaufman.h:269
Traits::MatrixU matrixU() const
Definition BunchKaufman.h:205
Index numPositive() const
Definition BunchKaufman.h:251
Scalar signDeterminant() const
Definition BunchKaufman.h:1124
RealScalar absDeterminant() const
Definition BunchKaufman.h:1094
const MatrixType & matrixLDLT() const
Definition BunchKaufman.h:317
Diagonal< const MatrixType > vectorD() const
Definition BunchKaufman.h:228
BunchKaufman(const EigenBase< InputType > &matrix)
Constructor with decomposition.
Definition BunchKaufman.h:170
const TranspositionType & transpositionsP() const
Definition BunchKaufman.h:218
bool isPositive() const
Definition BunchKaufman.h:277
Index numNegative() const
Definition BunchKaufman.h:257
Solve< BunchKaufman, Rhs > solve(const MatrixBase< Rhs > &b) const
bool isNegative() const
Definition BunchKaufman.h:282
Scalar determinant() const
Definition BunchKaufman.h:1088
BunchKaufman()
Default Constructor.
Definition BunchKaufman.h:131
RealScalar rcond() const
Definition BunchKaufman.h:306
Traits::MatrixL matrixL() const
Definition BunchKaufman.h:211
const TmpVectorType & subDiagonal() const
Definition BunchKaufman.h:238
BunchKaufman(Index size)
Default Constructor with memory preallocation.
Definition BunchKaufman.h:148
BunchKaufman(EigenBase< InputType > &matrix)
Constructs a Bunch-Kaufman factorization from a given matrix.
Definition BunchKaufman.h:191
ComputationInfo info() const
Reports whether previous computation was successful.
Definition BunchKaufman.h:398
MatrixType reconstructedMatrix() const
Definition BunchKaufman.h:1133
const BunchKaufman & adjoint() const
Definition BunchKaufman.h:385
typename internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:63
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition Diagonal.h:78
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
BunchKaufman< PlainObject > bunchKaufman() const
Definition BunchKaufman.h:1161
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
Permutation matrix.
Definition PermutationMatrix.h:346
BunchKaufman< PlainObject, UpLo > bunchKaufman() const
Definition BunchKaufman.h:1152
typename internal::traits< SelfAdjointView >::Scalar Scalar
Definition SelfAdjointView.h:101
typename NumTraits< Scalar >::Real RealScalar
Definition SelfAdjointView.h:103
Pseudo expression representing a solving operation.
Definition Solve.h:63
constexpr BunchKaufman< MatrixType_, UpLo_ > & derived()
Represents a sequence of transpositions (row/column interchange)
Definition Transpositions.h:144
ComputationInfo
Definition Constants.h:455
@ Lower
Definition Constants.h:212
@ Upper
Definition Constants.h:214
@ NumericalIssue
Definition Constants.h:459
@ InvalidInput
Definition Constants.h:464
@ Success
Definition Constants.h:457
Definition EigenBase.h:34
constexpr Derived & derived()
Definition EigenBase.h:50
constexpr Index size() const noexcept
Definition EigenBase.h:65