20 #ifndef EIGEN_BDCSVD_H
21 #define EIGEN_BDCSVD_H
25 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
26 #undef eigen_internal_assert
27 #define eigen_internal_assert(X) assert(X);
30 #include "./InternalHeaderCheck.h"
32 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
38 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
39 IOFormat bdcsvdfmt(8, 0,
", ",
"\n",
" [",
"]");
42 template <
typename MatrixType_,
int Options>
47 template <
typename MatrixType_,
int Options>
48 struct traits<BDCSVD<MatrixType_, Options> > : svd_traits<MatrixType_, Options> {
49 typedef MatrixType_ MatrixType;
52 template <
typename MatrixType,
int Options>
53 struct allocate_small_svd {
54 static void run(JacobiSVD<MatrixType, Options>& smallSvd,
Index rows,
Index cols,
unsigned int computationOptions) {
55 (void)computationOptions;
56 smallSvd = JacobiSVD<MatrixType, Options>(rows, cols);
60 template <
typename MatrixType>
61 struct allocate_small_svd<MatrixType, 0> {
62 static void run(JacobiSVD<MatrixType>& smallSvd,
Index rows,
Index cols,
unsigned int computationOptions) {
63 smallSvd = JacobiSVD<MatrixType>(rows, cols, computationOptions);
96 template <
typename MatrixType_,
int Options_>
106 typedef MatrixType_ MatrixType;
107 typedef typename Base::Scalar Scalar;
108 typedef typename Base::RealScalar RealScalar;
113 RowsAtCompileTime = Base::RowsAtCompileTime,
114 ColsAtCompileTime = Base::ColsAtCompileTime,
115 DiagSizeAtCompileTime = Base::DiagSizeAtCompileTime,
116 MaxRowsAtCompileTime = Base::MaxRowsAtCompileTime,
117 MaxColsAtCompileTime = Base::MaxColsAtCompileTime,
118 MaxDiagSizeAtCompileTime = Base::MaxDiagSizeAtCompileTime,
119 MatrixOptions = Base::MatrixOptions
122 typedef typename Base::MatrixUType MatrixUType;
123 typedef typename Base::MatrixVType MatrixVType;
124 typedef typename Base::SingularValuesType SingularValuesType;
139 BDCSVD() : m_algoswap(16), m_isTranspose(false), m_compU(false), m_compV(false), m_numIters(0)
149 allocate(
rows,
cols, internal::get_computation_options(Options));
168 internal::check_svd_options_assertions<MatrixType, Options>(computationOptions,
rows,
cols);
169 allocate(
rows,
cols, computationOptions);
177 BDCSVD(
const MatrixType& matrix) : m_algoswap(16), m_numIters(0) {
178 compute_impl(matrix, internal::get_computation_options(Options));
194 BDCSVD(
const MatrixType& matrix,
unsigned int computationOptions) : m_algoswap(16), m_numIters(0) {
195 internal::check_svd_options_assertions<MatrixType, Options>(computationOptions, matrix.rows(), matrix.cols());
196 compute_impl(matrix, computationOptions);
206 BDCSVD&
compute(
const MatrixType& matrix) {
return compute_impl(matrix, m_computationOptions); }
218 BDCSVD&
compute(
const MatrixType& matrix,
unsigned int computationOptions) {
219 internal::check_svd_options_assertions<MatrixType, Options>(computationOptions, matrix.rows(), matrix.cols());
220 return compute_impl(matrix, computationOptions);
223 void setSwitchSize(
int s)
225 eigen_assert(s>=3 &&
"BDCSVD the size of the algo switch has to be at least 3.");
230 void allocate(Index
rows, Index
cols,
unsigned int computationOptions);
231 BDCSVD& compute_impl(
const MatrixType& matrix,
unsigned int computationOptions);
232 void divide(Index firstCol, Index lastCol, Index firstRowW, Index firstColW, Index shift);
233 void computeSVDofM(Index firstCol, Index n, MatrixXr& U, VectorType& singVals, MatrixXr& V);
234 void computeSingVals(
const ArrayRef& col0,
const ArrayRef& diag,
const IndicesRef& perm, VectorType& singVals, ArrayRef shifts, ArrayRef mus);
235 void perturbCol0(
const ArrayRef& col0,
const ArrayRef& diag,
const IndicesRef& perm,
const VectorType& singVals,
const ArrayRef& shifts,
const ArrayRef& mus, ArrayRef zhat);
236 void computeSingVecs(
const ArrayRef& zhat,
const ArrayRef& diag,
const IndicesRef& perm,
const VectorType& singVals,
const ArrayRef& shifts,
const ArrayRef& mus, MatrixXr& U, MatrixXr& V);
237 void deflation43(Index firstCol, Index shift, Index i, Index
size);
238 void deflation44(Index firstColu , Index firstColm, Index firstRowW, Index firstColW, Index i, Index j, Index
size);
239 void deflation(Index firstCol, Index lastCol, Index k, Index firstRowW, Index firstColW, Index shift);
240 template<
typename HouseholderU,
typename HouseholderV,
typename NaiveU,
typename NaiveV>
241 void copyUV(
const HouseholderU &householderU,
const HouseholderV &householderV,
const NaiveU &naiveU,
const NaiveV &naivev);
242 void structured_update(Block<MatrixXr,Dynamic,Dynamic> A,
const MatrixXr &B, Index n1);
243 static RealScalar secularEq(RealScalar x,
const ArrayRef& col0,
const ArrayRef& diag,
const IndicesRef &perm,
const ArrayRef& diagShifted, RealScalar shift);
244 template <
typename SVDType>
245 void computeBaseCase(SVDType& svd, Index n, Index firstCol, Index firstRowW, Index firstColW, Index shift);
248 MatrixXr m_naiveU, m_naiveV;
252 ArrayXi m_workspaceI;
254 bool m_isTranspose, m_compU, m_compV;
255 JacobiSVD<MatrixType, Options> smallSvd;
257 using Base::m_computationOptions;
258 using Base::m_computeThinU;
259 using Base::m_computeThinV;
260 using Base::m_diagSize;
262 using Base::m_isInitialized;
263 using Base::m_matrixU;
264 using Base::m_matrixV;
265 using Base::m_nonzeroSingularValues;
266 using Base::m_singularValues;
273 template <
typename MatrixType,
int Options>
274 void BDCSVD<MatrixType, Options>::allocate(
Index rows,
Index cols,
unsigned int computationOptions) {
275 if (Base::allocate(rows, cols, computationOptions))
278 if (cols < m_algoswap)
279 internal::allocate_small_svd<MatrixType, Options>::run(smallSvd, rows, cols, computationOptions);
281 m_computed = MatrixXr::Zero(m_diagSize + 1, m_diagSize );
282 m_compU = computeV();
283 m_compV = computeU();
284 m_isTranspose = (cols > rows);
286 std::swap(m_compU, m_compV);
288 if (m_compU) m_naiveU = MatrixXr::Zero(m_diagSize + 1, m_diagSize + 1 );
289 else m_naiveU = MatrixXr::Zero(2, m_diagSize + 1 );
291 if (m_compV) m_naiveV = MatrixXr::Zero(m_diagSize, m_diagSize);
293 m_workspace.resize((m_diagSize+1)*(m_diagSize+1)*3);
294 m_workspaceI.resize(3*m_diagSize);
297 template <
typename MatrixType,
int Options>
298 BDCSVD<MatrixType, Options>& BDCSVD<MatrixType, Options>::compute_impl(
const MatrixType& matrix,
299 unsigned int computationOptions) {
300 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
301 std::cout <<
"\n\n\n======================================================================================================================\n\n\n";
305 allocate(matrix.rows(), matrix.cols(), computationOptions);
307 const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)();
310 if(matrix.cols() < m_algoswap)
312 smallSvd.compute(matrix);
313 m_isInitialized =
true;
314 m_info = smallSvd.info();
316 if (computeU()) m_matrixU = smallSvd.matrixU();
317 if (computeV()) m_matrixV = smallSvd.matrixV();
318 m_singularValues = smallSvd.singularValues();
319 m_nonzeroSingularValues = smallSvd.nonzeroSingularValues();
325 RealScalar scale = matrix.cwiseAbs().template maxCoeff<PropagateNaN>();
326 if (!(numext::isfinite)(scale)) {
327 m_isInitialized =
true;
332 if(numext::is_exactly_zero(scale)) scale = Literal(1);
334 if (m_isTranspose) copy = matrix.adjoint()/scale;
335 else copy = matrix/scale;
339 internal::UpperBidiagonalization<MatrixX> bid(copy);
345 m_computed.topRows(m_diagSize) = bid.bidiagonal().toDenseMatrix().transpose();
346 m_computed.template bottomRows<1>().setZero();
347 divide(0, m_diagSize - 1, 0, 0, 0);
349 m_isInitialized =
true;
354 for (
int i=0; i<m_diagSize; i++)
356 RealScalar a =
abs(m_computed.coeff(i, i));
357 m_singularValues.coeffRef(i) = a * scale;
360 m_nonzeroSingularValues = i;
361 m_singularValues.tail(m_diagSize - i - 1).setZero();
364 else if (i == m_diagSize - 1)
366 m_nonzeroSingularValues = i + 1;
371 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
375 if(m_isTranspose) copyUV(bid.householderV(), bid.householderU(), m_naiveV, m_naiveU);
376 else copyUV(bid.householderU(), bid.householderV(), m_naiveU, m_naiveV);
378 m_isInitialized =
true;
382 template <
typename MatrixType,
int Options>
383 template <
typename HouseholderU,
typename HouseholderV,
typename NaiveU,
typename NaiveV>
384 void BDCSVD<MatrixType, Options>::copyUV(
const HouseholderU& householderU,
const HouseholderV& householderV,
385 const NaiveU& naiveU,
const NaiveV& naiveV) {
389 Index Ucols = m_computeThinU ? m_diagSize : householderU.cols();
391 m_matrixU.topLeftCorner(m_diagSize, m_diagSize) = naiveV.template cast<Scalar>().topLeftCorner(m_diagSize, m_diagSize);
392 householderU.applyThisOnTheLeft(m_matrixU);
396 Index Vcols = m_computeThinV ? m_diagSize : householderV.cols();
398 m_matrixV.topLeftCorner(m_diagSize, m_diagSize) = naiveU.template cast<Scalar>().topLeftCorner(m_diagSize, m_diagSize);
399 householderV.applyThisOnTheLeft(m_matrixV);
411 template <
typename MatrixType,
int Options>
412 void BDCSVD<MatrixType, Options>::structured_update(Block<MatrixXr, Dynamic, Dynamic> A,
const MatrixXr& B,
Index n1) {
419 Map<MatrixXr> A1(m_workspace.data() , n1, n);
420 Map<MatrixXr> A2(m_workspace.data()+ n1*n, n2, n);
421 Map<MatrixXr> B1(m_workspace.data()+ n*n, n, n);
422 Map<MatrixXr> B2(m_workspace.data()+2*n*n, n, n);
424 for(
Index j=0; j<n; ++j)
426 if( (A.col(j).head(n1).array()!=Literal(0)).any() )
428 A1.col(k1) = A.col(j).head(n1);
429 B1.row(k1) = B.row(j);
432 if( (A.col(j).tail(n2).array()!=Literal(0)).any() )
434 A2.col(k2) = A.col(j).tail(n2);
435 B2.row(k2) = B.row(j);
440 A.topRows(n1).noalias() = A1.leftCols(k1) * B1.topRows(k1);
441 A.bottomRows(n2).noalias() = A2.leftCols(k2) * B2.topRows(k2);
445 Map<MatrixXr,Aligned> tmp(m_workspace.data(),n,n);
451 template <
typename MatrixType,
int Options>
452 template <
typename SVDType>
453 void BDCSVD<MatrixType, Options>::computeBaseCase(SVDType& svd,
Index n,
Index firstCol,
Index firstRowW,
455 svd.compute(m_computed.block(firstCol, firstCol, n + 1, n));
459 m_naiveU.block(firstCol, firstCol, n + 1, n + 1).real() = svd.matrixU();
461 m_naiveU.row(0).segment(firstCol, n + 1).real() = svd.matrixU().row(0);
462 m_naiveU.row(1).segment(firstCol, n + 1).real() = svd.matrixU().row(n);
464 if (m_compV) m_naiveV.block(firstRowW, firstColW, n, n).real() = svd.matrixV();
465 m_computed.block(firstCol + shift, firstCol + shift, n + 1, n).setZero();
466 m_computed.diagonal().segment(firstCol + shift, n) = svd.singularValues().head(n);
479 template <
typename MatrixType,
int Options>
480 void BDCSVD<MatrixType, Options>::divide(
Index firstCol,
Index lastCol,
Index firstRowW,
486 const Index n = lastCol - firstCol + 1;
488 const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)();
492 RealScalar lambda, phi, c0, s0;
500 JacobiSVD<MatrixXr, ComputeFullU | ComputeFullV> baseSvd;
501 computeBaseCase(baseSvd, n, firstCol, firstRowW, firstColW, shift);
503 JacobiSVD<MatrixXr, ComputeFullU> baseSvd;
504 computeBaseCase(baseSvd, n, firstCol, firstRowW, firstColW, shift);
509 alphaK = m_computed(firstCol + k, firstCol + k);
510 betaK = m_computed(firstCol + k + 1, firstCol + k);
514 divide(k + 1 + firstCol, lastCol, k + 1 + firstRowW, k + 1 + firstColW, shift);
516 divide(firstCol, k - 1 + firstCol, firstRowW, firstColW + 1, shift + 1);
521 lambda = m_naiveU(firstCol + k, firstCol + k);
522 phi = m_naiveU(firstCol + k + 1, lastCol + 1);
526 lambda = m_naiveU(1, firstCol + k);
527 phi = m_naiveU(0, lastCol + 1);
529 r0 =
sqrt((
abs(alphaK * lambda) *
abs(alphaK * lambda)) +
abs(betaK * phi) *
abs(betaK * phi));
532 l = m_naiveU.row(firstCol + k).segment(firstCol, k);
533 f = m_naiveU.row(firstCol + k + 1).segment(firstCol + k + 1, n - k - 1);
537 l = m_naiveU.row(1).segment(firstCol, k);
538 f = m_naiveU.row(0).segment(firstCol + k + 1, n - k - 1);
540 if (m_compV) m_naiveV(firstRowW+k, firstColW) = Literal(1);
548 c0 = alphaK * lambda / r0;
549 s0 = betaK * phi / r0;
552 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
553 assert(m_naiveU.allFinite());
554 assert(m_naiveV.allFinite());
555 assert(m_computed.allFinite());
560 MatrixXr q1 (m_naiveU.col(firstCol + k).segment(firstCol, k + 1));
562 for (
Index i = firstCol + k - 1; i >= firstCol; i--)
563 m_naiveU.col(i + 1).segment(firstCol, k + 1) = m_naiveU.col(i).segment(firstCol, k + 1);
565 m_naiveU.col(firstCol).segment( firstCol, k + 1) = (q1 * c0);
567 m_naiveU.col(lastCol + 1).segment(firstCol, k + 1) = (q1 * ( - s0));
569 m_naiveU.col(firstCol).segment(firstCol + k + 1, n - k) = m_naiveU.col(lastCol + 1).segment(firstCol + k + 1, n - k) * s0;
571 m_naiveU.col(lastCol + 1).segment(firstCol + k + 1, n - k) *= c0;
575 RealScalar q1 = m_naiveU(0, firstCol + k);
577 for (
Index i = firstCol + k - 1; i >= firstCol; i--)
578 m_naiveU(0, i + 1) = m_naiveU(0, i);
580 m_naiveU(0, firstCol) = (q1 * c0);
582 m_naiveU(0, lastCol + 1) = (q1 * ( - s0));
584 m_naiveU(1, firstCol) = m_naiveU(1, lastCol + 1) *s0;
586 m_naiveU(1, lastCol + 1) *= c0;
587 m_naiveU.row(1).segment(firstCol + 1, k).setZero();
588 m_naiveU.row(0).segment(firstCol + k + 1, n - k - 1).setZero();
591 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
592 assert(m_naiveU.allFinite());
593 assert(m_naiveV.allFinite());
594 assert(m_computed.allFinite());
597 m_computed(firstCol + shift, firstCol + shift) = r0;
598 m_computed.col(firstCol + shift).segment(firstCol + shift + 1, k) = alphaK * l.transpose().real();
599 m_computed.col(firstCol + shift).segment(firstCol + shift + k + 1, n - k - 1) = betaK * f.transpose().real();
601 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
602 ArrayXr tmp1 = (m_computed.block(firstCol+shift, firstCol+shift, n, n)).jacobiSvd().singularValues();
605 deflation(firstCol, lastCol, k, firstRowW, firstColW, shift);
606 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
607 ArrayXr tmp2 = (m_computed.block(firstCol+shift, firstCol+shift, n, n)).jacobiSvd().singularValues();
608 std::cout <<
"\n\nj1 = " << tmp1.transpose().format(bdcsvdfmt) <<
"\n";
609 std::cout <<
"j2 = " << tmp2.transpose().format(bdcsvdfmt) <<
"\n\n";
610 std::cout <<
"err: " << ((tmp1-tmp2).
abs()>1e-12*tmp2.abs()).transpose() <<
"\n";
611 static int count = 0;
612 std::cout <<
"# " << ++count <<
"\n\n";
613 assert((tmp1-tmp2).matrix().norm() < 1e-14*tmp2.matrix().norm());
619 MatrixXr UofSVD, VofSVD;
621 computeSVDofM(firstCol + shift, n, UofSVD, singVals, VofSVD);
623 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
624 assert(UofSVD.allFinite());
625 assert(VofSVD.allFinite());
629 structured_update(m_naiveU.block(firstCol, firstCol, n + 1, n + 1), UofSVD, (n+2)/2);
632 Map<Matrix<RealScalar,2,Dynamic>,
Aligned> tmp(m_workspace.data(),2,n+1);
633 tmp.noalias() = m_naiveU.middleCols(firstCol, n+1) * UofSVD;
634 m_naiveU.middleCols(firstCol, n + 1) = tmp;
637 if (m_compV) structured_update(m_naiveV.block(firstRowW, firstColW, n, n), VofSVD, (n+1)/2);
639 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
640 assert(m_naiveU.allFinite());
641 assert(m_naiveV.allFinite());
642 assert(m_computed.allFinite());
645 m_computed.block(firstCol + shift, firstCol + shift, n, n).setZero();
646 m_computed.block(firstCol + shift, firstCol + shift, n, n).diagonal() = singVals;
657 template <
typename MatrixType,
int Options>
658 void BDCSVD<MatrixType, Options>::computeSVDofM(
Index firstCol,
Index n, MatrixXr& U,
659 VectorType& singVals, MatrixXr& V) {
660 const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)();
662 ArrayRef col0 = m_computed.col(firstCol).segment(firstCol, n);
663 m_workspace.head(n) = m_computed.block(firstCol, firstCol, n, n).diagonal();
664 ArrayRef diag = m_workspace.head(n);
665 diag(0) = Literal(0);
670 if (m_compV) V.resize(n, n);
672 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
673 if (col0.hasNaN() || diag.hasNaN())
674 std::cout <<
"\n\nHAS NAN\n\n";
681 while(actual_n>1 && numext::is_exactly_zero(diag(actual_n - 1))) {
683 eigen_internal_assert(numext::is_exactly_zero(col0(actual_n)));
686 for(
Index k=0;k<actual_n;++k)
687 if(
abs(col0(k))>considerZero)
688 m_workspaceI(m++) = k;
689 Map<ArrayXi> perm(m_workspaceI.data(),m);
691 Map<ArrayXr> shifts(m_workspace.data()+1*n, n);
692 Map<ArrayXr> mus(m_workspace.data()+2*n, n);
693 Map<ArrayXr> zhat(m_workspace.data()+3*n, n);
695 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
696 std::cout <<
"computeSVDofM using:\n";
697 std::cout <<
" z: " << col0.transpose() <<
"\n";
698 std::cout <<
" d: " << diag.transpose() <<
"\n";
702 computeSingVals(col0, diag, perm, singVals, shifts, mus);
704 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
705 std::cout <<
" j: " << (m_computed.block(firstCol, firstCol, n, n)).jacobiSvd().singularValues().transpose().reverse() <<
"\n\n";
706 std::cout <<
" sing-val: " << singVals.transpose() <<
"\n";
707 std::cout <<
" mu: " << mus.transpose() <<
"\n";
708 std::cout <<
" shift: " << shifts.transpose() <<
"\n";
711 std::cout <<
"\n\n mus: " << mus.head(actual_n).transpose() <<
"\n\n";
712 std::cout <<
" check1 (expect0) : " << ((singVals.array()-(shifts+mus)) / singVals.array()).head(actual_n).transpose() <<
"\n\n";
713 assert((((singVals.array()-(shifts+mus)) / singVals.array()).head(actual_n) >= 0).all());
714 std::cout <<
" check2 (>0) : " << ((singVals.array()-diag) / singVals.array()).head(actual_n).transpose() <<
"\n\n";
715 assert((((singVals.array()-diag) / singVals.array()).head(actual_n) >= 0).all());
719 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
720 assert(singVals.allFinite());
721 assert(mus.allFinite());
722 assert(shifts.allFinite());
726 perturbCol0(col0, diag, perm, singVals, shifts, mus, zhat);
727 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
728 std::cout <<
" zhat: " << zhat.transpose() <<
"\n";
731 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
732 assert(zhat.allFinite());
735 computeSingVecs(zhat, diag, perm, singVals, shifts, mus, U, V);
737 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
738 std::cout <<
"U^T U: " << (U.transpose() * U - MatrixXr(MatrixXr::Identity(U.cols(),U.cols()))).norm() <<
"\n";
739 std::cout <<
"V^T V: " << (V.transpose() * V - MatrixXr(MatrixXr::Identity(V.cols(),V.cols()))).norm() <<
"\n";
742 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
743 assert(m_naiveU.allFinite());
744 assert(m_naiveV.allFinite());
745 assert(m_computed.allFinite());
746 assert(U.allFinite());
747 assert(V.allFinite());
754 for(
Index i=0; i<actual_n-1; ++i)
756 if(singVals(i)>singVals(i+1))
759 swap(singVals(i),singVals(i+1));
760 U.col(i).swap(U.col(i+1));
761 if(m_compV) V.col(i).swap(V.col(i+1));
765 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
767 bool singular_values_sorted = (((singVals.segment(1,actual_n-1)-singVals.head(actual_n-1))).array() >= 0).
all();
768 if(!singular_values_sorted)
769 std::cout <<
"Singular values are not sorted: " << singVals.segment(1,actual_n).transpose() <<
"\n";
770 assert(singular_values_sorted);
776 singVals.head(actual_n).reverseInPlace();
777 U.leftCols(actual_n).rowwise().reverseInPlace();
778 if (m_compV) V.leftCols(actual_n).rowwise().reverseInPlace();
780 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
781 JacobiSVD<MatrixXr> jsvd(m_computed.block(firstCol, firstCol, n, n) );
782 std::cout <<
" * j: " << jsvd.singularValues().transpose() <<
"\n\n";
783 std::cout <<
" * sing-val: " << singVals.transpose() <<
"\n";
788 template <
typename MatrixType,
int Options>
789 typename BDCSVD<MatrixType, Options>::RealScalar BDCSVD<MatrixType, Options>::secularEq(
790 RealScalar mu,
const ArrayRef& col0,
const ArrayRef& diag,
const IndicesRef& perm,
const ArrayRef& diagShifted,
792 Index m = perm.size();
793 RealScalar res = Literal(1);
794 for(
Index i=0; i<m; ++i)
799 res += (col0(j) / (diagShifted(j) - mu)) * (col0(j) / (diag(j) + shift + mu));
804 template <
typename MatrixType,
int Options>
805 void BDCSVD<MatrixType, Options>::computeSingVals(
const ArrayRef& col0,
const ArrayRef& diag,
const IndicesRef& perm,
806 VectorType& singVals, ArrayRef shifts, ArrayRef mus) {
811 Index n = col0.size();
815 while(actual_n>1 && numext::is_exactly_zero(col0(actual_n - 1))) --actual_n;
817 for (
Index k = 0; k < n; ++k)
819 if (numext::is_exactly_zero(col0(k)) || actual_n == 1)
823 singVals(k) = k==0 ? col0(0) : diag(k);
825 shifts(k) = k==0 ? col0(0) : diag(k);
830 RealScalar left = diag(k);
833 right = (diag(actual_n-1) + col0.matrix().norm());
840 while(numext::is_exactly_zero(col0(l))) { ++l; eigen_internal_assert(l < actual_n); }
845 RealScalar mid = left + (right-left) / Literal(2);
846 RealScalar fMid = secularEq(mid, col0, diag, perm, diag, Literal(0));
847 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
848 std::cout <<
"right-left = " << right-left <<
"\n";
851 std::cout <<
" = " << secularEq(left+RealScalar(0.000001)*(right-left), col0, diag, perm, diag, 0)
852 <<
" " << secularEq(left+RealScalar(0.1) *(right-left), col0, diag, perm, diag, 0)
853 <<
" " << secularEq(left+RealScalar(0.2) *(right-left), col0, diag, perm, diag, 0)
854 <<
" " << secularEq(left+RealScalar(0.3) *(right-left), col0, diag, perm, diag, 0)
855 <<
" " << secularEq(left+RealScalar(0.4) *(right-left), col0, diag, perm, diag, 0)
856 <<
" " << secularEq(left+RealScalar(0.49) *(right-left), col0, diag, perm, diag, 0)
857 <<
" " << secularEq(left+RealScalar(0.5) *(right-left), col0, diag, perm, diag, 0)
858 <<
" " << secularEq(left+RealScalar(0.51) *(right-left), col0, diag, perm, diag, 0)
859 <<
" " << secularEq(left+RealScalar(0.6) *(right-left), col0, diag, perm, diag, 0)
860 <<
" " << secularEq(left+RealScalar(0.7) *(right-left), col0, diag, perm, diag, 0)
861 <<
" " << secularEq(left+RealScalar(0.8) *(right-left), col0, diag, perm, diag, 0)
862 <<
" " << secularEq(left+RealScalar(0.9) *(right-left), col0, diag, perm, diag, 0)
863 <<
" " << secularEq(left+RealScalar(0.999999)*(right-left), col0, diag, perm, diag, 0) <<
"\n";
865 RealScalar shift = (k == actual_n-1 || fMid > Literal(0)) ? left : right;
868 Map<ArrayXr> diagShifted(m_workspace.data()+4*n, n);
869 diagShifted = diag - shift;
874 RealScalar midShifted = (right - left) / RealScalar(2);
876 if(numext::equal_strict(shift, right))
877 midShifted = -midShifted;
878 RealScalar fMidShifted = secularEq(midShifted, col0, diag, perm, diagShifted, shift);
882 shift = fMidShifted > Literal(0) ? left : right;
883 diagShifted = diag - shift;
888 RealScalar muPrev, muCur;
890 if (numext::equal_strict(shift, left))
892 muPrev = (right - left) * RealScalar(0.1);
893 if (k == actual_n-1) muCur = right - left;
894 else muCur = (right - left) * RealScalar(0.5);
898 muPrev = -(right - left) * RealScalar(0.1);
899 muCur = -(right - left) * RealScalar(0.5);
902 RealScalar fPrev = secularEq(muPrev, col0, diag, perm, diagShifted, shift);
903 RealScalar fCur = secularEq(muCur, col0, diag, perm, diagShifted, shift);
904 if (
abs(fPrev) <
abs(fCur))
912 bool useBisection = fPrev*fCur>Literal(0);
913 while (!numext::is_exactly_zero(fCur) &&
abs(muCur - muPrev) > Literal(8) * NumTraits<RealScalar>::epsilon() * numext::maxi<RealScalar>(
abs(muCur),
abs(muPrev)) &&
abs(fCur - fPrev) > NumTraits<RealScalar>::epsilon() && !useBisection)
918 RealScalar a = (fCur - fPrev) / (Literal(1)/muCur - Literal(1)/muPrev);
919 RealScalar b = fCur - a / muCur;
921 RealScalar muZero = -a/b;
922 RealScalar fZero = secularEq(muZero, col0, diag, perm, diagShifted, shift);
924 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
925 assert((numext::isfinite)(fZero));
934 if (numext::equal_strict(shift, left) && (muCur < Literal(0) || muCur > right - left)) useBisection =
true;
935 if (numext::equal_strict(shift, right) && (muCur < -(right - left) || muCur > Literal(0))) useBisection =
true;
936 if (
abs(fCur)>
abs(fPrev)) useBisection =
true;
942 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
943 std::cout <<
"useBisection for k = " << k <<
", actual_n = " << actual_n <<
"\n";
945 RealScalar leftShifted, rightShifted;
947 if (numext::equal_strict(shift, left))
951 leftShifted = numext::maxi<RealScalar>( (std::numeric_limits<RealScalar>::min)(), Literal(2) *
abs(col0(k)) /
sqrt((std::numeric_limits<RealScalar>::max)()) );
954 eigen_internal_assert( (numext::isfinite)( (col0(k)/leftShifted)*(col0(k)/(diag(k)+shift+leftShifted)) ) );
957 rightShifted = (k==actual_n-1) ? right : ((right - left) * RealScalar(0.51));
961 leftShifted = -(right - left) * RealScalar(0.51);
963 rightShifted = -numext::maxi<RealScalar>( (std::numeric_limits<RealScalar>::min)(),
abs(col0(k+1)) /
sqrt((std::numeric_limits<RealScalar>::max)()) );
965 rightShifted = -(std::numeric_limits<RealScalar>::min)();
968 RealScalar fLeft = secularEq(leftShifted, col0, diag, perm, diagShifted, shift);
969 eigen_internal_assert(fLeft<Literal(0));
971 #if defined EIGEN_BDCSVD_DEBUG_VERBOSE || defined EIGEN_BDCSVD_SANITY_CHECKS || defined EIGEN_INTERNAL_DEBUGGING
972 RealScalar fRight = secularEq(rightShifted, col0, diag, perm, diagShifted, shift);
975 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
976 if(!(numext::isfinite)(fLeft))
977 std::cout <<
"f(" << leftShifted <<
") =" << fLeft <<
" ; " << left <<
" " << shift <<
" " << right <<
"\n";
978 assert((numext::isfinite)(fLeft));
980 if(!(numext::isfinite)(fRight))
981 std::cout <<
"f(" << rightShifted <<
") =" << fRight <<
" ; " << left <<
" " << shift <<
" " << right <<
"\n";
985 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
986 if(!(fLeft * fRight<0))
988 std::cout <<
"f(leftShifted) using leftShifted=" << leftShifted <<
" ; diagShifted(1:10):" << diagShifted.head(10).transpose() <<
"\n ; "
989 <<
"left==shift=" << bool(left==shift) <<
" ; left-shift = " << (left-shift) <<
"\n";
990 std::cout <<
"k=" << k <<
", " << fLeft <<
" * " << fRight <<
" == " << fLeft * fRight <<
" ; "
991 <<
"[" << left <<
" .. " << right <<
"] -> [" << leftShifted <<
" " << rightShifted <<
"], shift=" << shift
992 <<
" , f(right)=" << secularEq(0, col0, diag, perm, diagShifted, shift)
993 <<
" == " << secularEq(right, col0, diag, perm, diag, 0) <<
" == " << fRight <<
"\n";
996 eigen_internal_assert(fLeft * fRight < Literal(0));
1000 while (rightShifted - leftShifted > Literal(2) * NumTraits<RealScalar>::epsilon() * numext::maxi<RealScalar>(
abs(leftShifted),
abs(rightShifted)))
1002 RealScalar midShifted = (leftShifted + rightShifted) / Literal(2);
1003 fMid = secularEq(midShifted, col0, diag, perm, diagShifted, shift);
1004 eigen_internal_assert((numext::isfinite)(fMid));
1006 if (fLeft * fMid < Literal(0))
1008 rightShifted = midShifted;
1012 leftShifted = midShifted;
1016 muCur = (leftShifted + rightShifted) / Literal(2);
1024 muCur = (right - left) * RealScalar(0.5);
1026 if(numext::equal_strict(shift, right))
1031 singVals[k] = shift + muCur;
1035 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1037 std::cout <<
"found " << singVals[k] <<
" == " << shift <<
" + " << muCur <<
" from " << diag(k) <<
" .. " << diag(k+1) <<
"\n";
1039 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1040 assert(k==0 || singVals[k]>=singVals[k-1]);
1041 assert(singVals[k]>=diag(k));
1053 template <
typename MatrixType,
int Options>
1054 void BDCSVD<MatrixType, Options>::perturbCol0(
const ArrayRef& col0,
const ArrayRef& diag,
const IndicesRef& perm,
1055 const VectorType& singVals,
const ArrayRef& shifts,
const ArrayRef& mus,
1058 Index n = col0.size();
1059 Index m = perm.size();
1065 Index lastIdx = perm(m-1);
1067 for (
Index k = 0; k < n; ++k)
1069 if (numext::is_exactly_zero(col0(k)))
1070 zhat(k) = Literal(0);
1074 RealScalar dk = diag(k);
1075 RealScalar prod = (singVals(lastIdx) + dk) * (mus(lastIdx) + (shifts(lastIdx) - dk));
1076 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1078 std::cout <<
"k = " << k <<
" ; z(k)=" << col0(k) <<
", diag(k)=" << dk <<
"\n";
1079 std::cout <<
"prod = " <<
"(" << singVals(lastIdx) <<
" + " << dk <<
") * (" << mus(lastIdx) <<
" + (" << shifts(lastIdx) <<
" - " << dk <<
"))" <<
"\n";
1080 std::cout <<
" = " << singVals(lastIdx) + dk <<
" * " << mus(lastIdx) + (shifts(lastIdx) - dk) <<
"\n";
1085 for(
Index l = 0; l<m; ++l)
1090 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1091 if(i>=k && (l==0 || l-1>=m))
1093 std::cout <<
"Error in perturbCol0\n";
1094 std::cout <<
" " << k <<
"/" << n <<
" " << l <<
"/" << m <<
" " << i <<
"/" << n <<
" ; " << col0(k) <<
" " << diag(k) <<
" " <<
"\n";
1095 std::cout <<
" " <<diag(i) <<
"\n";
1096 Index j = (i<k ) ? i : perm(l-1);
1097 std::cout <<
" " <<
"j=" << j <<
"\n";
1100 Index j = i<k ? i : perm(l-1);
1101 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1102 if(!(dk!=Literal(0) || diag(i)!=Literal(0)))
1104 std::cout <<
"k=" << k <<
", i=" << i <<
", l=" << l <<
", perm.size()=" << perm.size() <<
"\n";
1106 assert(dk!=Literal(0) || diag(i)!=Literal(0));
1108 prod *= ((singVals(j)+dk) / ((diag(i)+dk))) * ((mus(j)+(shifts(j)-dk)) / ((diag(i)-dk)));
1109 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1112 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1113 if(i!=k && numext::abs(((singVals(j)+dk)*(mus(j)+(shifts(j)-dk)))/((diag(i)+dk)*(diag(i)-dk)) - 1) > 0.9 )
1114 std::cout <<
" " << ((singVals(j)+dk)*(mus(j)+(shifts(j)-dk)))/((diag(i)+dk)*(diag(i)-dk)) <<
" == (" << (singVals(j)+dk) <<
" * " << (mus(j)+(shifts(j)-dk))
1115 <<
") / (" << (diag(i)+dk) <<
" * " << (diag(i)-dk) <<
")\n";
1119 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1120 std::cout <<
"zhat(" << k <<
") = sqrt( " << prod <<
") ; " << (singVals(lastIdx) + dk) <<
" * " << mus(lastIdx) + shifts(lastIdx) <<
" - " << dk <<
"\n";
1122 RealScalar tmp =
sqrt(prod);
1123 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1124 assert((numext::isfinite)(tmp));
1126 zhat(k) = col0(k) > Literal(0) ? RealScalar(tmp) : RealScalar(-tmp);
1132 template <
typename MatrixType,
int Options>
1133 void BDCSVD<MatrixType, Options>::computeSingVecs(
const ArrayRef& zhat,
const ArrayRef& diag,
const IndicesRef& perm,
1134 const VectorType& singVals,
const ArrayRef& shifts,
1135 const ArrayRef& mus, MatrixXr& U, MatrixXr& V) {
1136 Index n = zhat.size();
1137 Index m = perm.size();
1139 for (
Index k = 0; k < n; ++k)
1141 if (numext::is_exactly_zero(zhat(k)))
1143 U.col(k) = VectorType::Unit(n+1, k);
1144 if (m_compV) V.col(k) = VectorType::Unit(n, k);
1149 for(
Index l=0;l<m;++l)
1152 U(i,k) = zhat(i)/(((diag(i) - shifts(k)) - mus(k)) )/( (diag(i) + singVals[k]));
1154 U(n,k) = Literal(0);
1155 U.col(k).normalize();
1160 for(
Index l=1;l<m;++l)
1163 V(i,k) = diag(i) * zhat(i) / (((diag(i) - shifts(k)) - mus(k)) )/( (diag(i) + singVals[k]));
1165 V(0,k) = Literal(-1);
1166 V.col(k).normalize();
1170 U.col(n) = VectorType::Unit(n+1, n);
1176 template <
typename MatrixType,
int Options>
1177 void BDCSVD<MatrixType, Options>::deflation43(
Index firstCol,
Index shift,
Index i,
1182 Index start = firstCol + shift;
1183 RealScalar c = m_computed(start, start);
1184 RealScalar s = m_computed(start+i, start);
1185 RealScalar r = numext::hypot(c,s);
1186 if (numext::is_exactly_zero(r))
1188 m_computed(start+i, start+i) = Literal(0);
1191 m_computed(start,start) = r;
1192 m_computed(start+i, start) = Literal(0);
1193 m_computed(start+i, start+i) = Literal(0);
1195 JacobiRotation<RealScalar> J(c/r,-s/r);
1196 if (m_compU) m_naiveU.middleRows(firstCol, size+1).applyOnTheRight(firstCol, firstCol+i, J);
1197 else m_naiveU.applyOnTheRight(firstCol, firstCol+i, J);
1204 template <
typename MatrixType,
int Options>
1205 void BDCSVD<MatrixType, Options>::deflation44(
Index firstColu,
Index firstColm,
Index firstRowW,
1212 RealScalar c = m_computed(firstColm+i, firstColm);
1213 RealScalar s = m_computed(firstColm+j, firstColm);
1214 RealScalar r =
sqrt(numext::abs2(c) + numext::abs2(s));
1215 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1216 std::cout <<
"deflation 4.4: " << i <<
"," << j <<
" -> " << c <<
" " << s <<
" " << r <<
" ; "
1217 << m_computed(firstColm + i-1, firstColm) <<
" "
1218 << m_computed(firstColm + i, firstColm) <<
" "
1219 << m_computed(firstColm + i+1, firstColm) <<
" "
1220 << m_computed(firstColm + i+2, firstColm) <<
"\n";
1221 std::cout << m_computed(firstColm + i-1, firstColm + i-1) <<
" "
1222 << m_computed(firstColm + i, firstColm+i) <<
" "
1223 << m_computed(firstColm + i+1, firstColm+i+1) <<
" "
1224 << m_computed(firstColm + i+2, firstColm+i+2) <<
"\n";
1226 if (numext::is_exactly_zero(r))
1228 m_computed(firstColm + i, firstColm + i) = m_computed(firstColm + j, firstColm + j);
1233 m_computed(firstColm + i, firstColm) = r;
1234 m_computed(firstColm + j, firstColm + j) = m_computed(firstColm + i, firstColm + i);
1235 m_computed(firstColm + j, firstColm) = Literal(0);
1237 JacobiRotation<RealScalar> J(c,-s);
1238 if (m_compU) m_naiveU.middleRows(firstColu, size+1).applyOnTheRight(firstColu + i, firstColu + j, J);
1239 else m_naiveU.applyOnTheRight(firstColu+i, firstColu+j, J);
1240 if (m_compV) m_naiveV.middleRows(firstRowW, size).applyOnTheRight(firstColW + i, firstColW + j, J);
1244 template <
typename MatrixType,
int Options>
1245 void BDCSVD<MatrixType, Options>::deflation(
Index firstCol,
Index lastCol,
Index k,
1249 const Index length = lastCol + 1 - firstCol;
1251 Block<MatrixXr,Dynamic,1> col0(m_computed, firstCol+shift, firstCol+shift, length, 1);
1252 Diagonal<MatrixXr> fulldiag(m_computed);
1253 VectorBlock<Diagonal<MatrixXr>,
Dynamic> diag(fulldiag, firstCol+shift, length);
1255 const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)();
1256 RealScalar maxDiag = diag.tail((std::max)(
Index(1),length-1)).cwiseAbs().maxCoeff();
1257 RealScalar epsilon_strict = numext::maxi<RealScalar>(considerZero,NumTraits<RealScalar>::epsilon() * maxDiag);
1258 RealScalar epsilon_coarse = Literal(8) * NumTraits<RealScalar>::epsilon() * numext::maxi<RealScalar>(col0.cwiseAbs().maxCoeff(), maxDiag);
1260 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1261 assert(m_naiveU.allFinite());
1262 assert(m_naiveV.allFinite());
1263 assert(m_computed.allFinite());
1266 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1267 std::cout <<
"\ndeflate:" << diag.head(k+1).transpose() <<
" | " << diag.segment(k+1,length-k-1).transpose() <<
"\n";
1271 if (diag(0) < epsilon_coarse)
1273 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1274 std::cout <<
"deflation 4.1, because " << diag(0) <<
" < " << epsilon_coarse <<
"\n";
1276 diag(0) = epsilon_coarse;
1280 for (
Index i=1;i<length;++i)
1281 if (
abs(col0(i)) < epsilon_strict)
1283 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1284 std::cout <<
"deflation 4.2, set z(" << i <<
") to zero because " <<
abs(col0(i)) <<
" < " << epsilon_strict <<
" (diag(" << i <<
")=" << diag(i) <<
")\n";
1286 col0(i) = Literal(0);
1290 for (
Index i=1;i<length; i++)
1291 if (diag(i) < epsilon_coarse)
1293 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1294 std::cout <<
"deflation 4.3, cancel z(" << i <<
")=" << col0(i) <<
" because diag(" << i <<
")=" << diag(i) <<
" < " << epsilon_coarse <<
"\n";
1296 deflation43(firstCol, shift, i, length);
1299 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1300 assert(m_naiveU.allFinite());
1301 assert(m_naiveV.allFinite());
1302 assert(m_computed.allFinite());
1304 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1305 std::cout <<
"to be sorted: " << diag.transpose() <<
"\n\n";
1306 std::cout <<
" : " << col0.transpose() <<
"\n\n";
1311 const bool total_deflation = (col0.tail(length-1).array().abs()<considerZero).
all();
1315 Index *permutation = m_workspaceI.data();
1321 for(
Index i=1; i<length; ++i)
1322 if(
abs(diag(i))<considerZero)
1323 permutation[p++] = i;
1326 for( ; p < length; ++p)
1328 if (i > k) permutation[p] = j++;
1329 else if (j >= length) permutation[p] = i++;
1330 else if (diag(i) < diag(j)) permutation[p] = j++;
1331 else permutation[p] = i++;
1338 for(
Index i=1; i<length; ++i)
1340 Index pi = permutation[i];
1341 if(
abs(diag(pi))<considerZero || diag(0)<diag(pi))
1342 permutation[i-1] = permutation[i];
1345 permutation[i-1] = 0;
1352 Index *realInd = m_workspaceI.data()+length;
1353 Index *realCol = m_workspaceI.data()+2*length;
1355 for(
int pos = 0; pos< length; pos++)
1361 for(
Index i = total_deflation?0:1; i < length; i++)
1363 const Index pi = permutation[length - (total_deflation ? i+1 : i)];
1364 const Index J = realCol[pi];
1368 swap(diag(i), diag(J));
1369 if(i!=0 && J!=0) swap(col0(i), col0(J));
1372 if (m_compU) m_naiveU.col(firstCol+i).segment(firstCol, length + 1).swap(m_naiveU.col(firstCol+J).segment(firstCol, length + 1));
1373 else m_naiveU.col(firstCol+i).segment(0, 2) .swap(m_naiveU.col(firstCol+J).segment(0, 2));
1374 if (m_compV) m_naiveV.col(firstColW + i).segment(firstRowW, length).swap(m_naiveV.col(firstColW + J).segment(firstRowW, length));
1377 const Index realI = realInd[i];
1384 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1385 std::cout <<
"sorted: " << diag.transpose().format(bdcsvdfmt) <<
"\n";
1386 std::cout <<
" : " << col0.transpose() <<
"\n\n";
1392 while(i>0 && (
abs(diag(i))<considerZero ||
abs(col0(i))<considerZero)) --i;
1394 if( (diag(i) - diag(i-1)) < NumTraits<RealScalar>::epsilon()*maxDiag )
1396 #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
1397 std::cout <<
"deflation 4.4 with i = " << i <<
" because " << diag(i) <<
" - " << diag(i-1) <<
" == " << (diag(i) - diag(i-1)) <<
" < " << NumTraits<RealScalar>::epsilon()*maxDiag <<
"\n";
1399 eigen_internal_assert(
abs(diag(i) - diag(i-1))<epsilon_coarse &&
" diagonal entries are not properly sorted");
1400 deflation44(firstCol, firstCol + shift, firstRowW, firstColW, i-1, i, length);
1404 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1405 for(
Index j=2;j<length;++j)
1406 assert(diag(j-1)<=diag(j) ||
abs(diag(j))<considerZero);
1409 #ifdef EIGEN_BDCSVD_SANITY_CHECKS
1410 assert(m_naiveU.allFinite());
1411 assert(m_naiveV.allFinite());
1412 assert(m_computed.allFinite());
1422 template <
typename Derived>
1423 template <
int Options>
1434 template <
typename Derived>
1435 template <
int Options>
1437 unsigned int computationOptions)
const {
class Bidiagonal Divide and Conquer SVD
Definition: BDCSVD.h:97
BDCSVD & compute(const MatrixType &matrix)
Method performing the decomposition of given matrix. Computes Thin/Full unitaries U/V if specified us...
Definition: BDCSVD.h:206
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: EigenBase.h:65
EIGEN_DEPRECATED BDCSVD(const MatrixType &matrix, unsigned int computationOptions)
Constructor performing the decomposition of given matrix using specified options for computing unitar...
Definition: BDCSVD.h:194
BDCSVD(const MatrixType &matrix)
Constructor performing the decomposition of given matrix, using the custom options specified with the...
Definition: BDCSVD.h:177
EIGEN_DEPRECATED BDCSVD(Index rows, Index cols, unsigned int computationOptions)
Default Constructor with memory preallocation.
Definition: BDCSVD.h:167
BDCSVD()
Default Constructor.
Definition: BDCSVD.h:139
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:62
EIGEN_DEPRECATED BDCSVD & compute(const MatrixType &matrix, unsigned int computationOptions)
Method performing the decomposition of given matrix, as specified by the computationOptions parameter...
Definition: BDCSVD.h:218
BDCSVD(Index rows, Index cols)
Default Constructor with memory preallocation.
Definition: BDCSVD.h:148
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
static const IdentityReturnType Identity()
Definition: CwiseNullaryOp.h:801
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:285
Base class of SVD algorithms.
Definition: SVDBase.h:120
bool computeV() const
Definition: SVDBase.h:284
Eigen::Index Index
Definition: SVDBase.h:130
bool computeU() const
Definition: SVDBase.h:282
static const Eigen::internal::all_t all
Definition: IndexedViewHelper.h:189
@ Aligned
Definition: Constants.h:242
@ InvalidInput
Definition: Constants.h:451
@ Success
Definition: Constants.h:444
@ NoConvergence
Definition: Constants.h:448
Matrix< Type, Dynamic, Dynamic > MatrixX
[c++11] Dynamic×Dynamic matrix of type Type.
Definition: Matrix.h:536
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
Definition: EigenBase.h:32
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition: EigenBase.h:69
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:231