124 template <
typename Derived_>
125 friend struct internal::solve_assertion;
127 using MatrixType =
typename internal::traits<Derived>::MatrixType;
128 using Scalar =
typename MatrixType::Scalar;
129 using RealScalar =
typename NumTraits<typename MatrixType::Scalar>::Real;
130 using StorageIndex =
typename Eigen::internal::traits<SVDBase>::StorageIndex;
132 static constexpr bool ShouldComputeFullU = internal::traits<Derived>::ShouldComputeFullU;
133 static constexpr bool ShouldComputeThinU = internal::traits<Derived>::ShouldComputeThinU;
134 static constexpr bool ShouldComputeFullV = internal::traits<Derived>::ShouldComputeFullV;
135 static constexpr bool ShouldComputeThinV = internal::traits<Derived>::ShouldComputeThinV;
138 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
139 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
140 DiagSizeAtCompileTime = internal::min_size_prefer_dynamic(RowsAtCompileTime, ColsAtCompileTime),
141 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
142 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
143 MaxDiagSizeAtCompileTime = internal::min_size_prefer_fixed(MaxRowsAtCompileTime, MaxColsAtCompileTime),
144 MatrixOptions = internal::traits<MatrixType>::Options,
145 MatrixUColsAtCompileTime = internal::traits<Derived>::MatrixUColsAtCompileTime,
146 MatrixVColsAtCompileTime = internal::traits<Derived>::MatrixVColsAtCompileTime,
147 MatrixUMaxColsAtCompileTime = internal::traits<Derived>::MatrixUMaxColsAtCompileTime,
148 MatrixVMaxColsAtCompileTime = internal::traits<Derived>::MatrixVMaxColsAtCompileTime
151 EIGEN_STATIC_ASSERT(!(ShouldComputeFullU && ShouldComputeThinU),
"SVDBase: Cannot request both full and thin U")
152 EIGEN_STATIC_ASSERT(!(ShouldComputeFullV && ShouldComputeThinV),
"SVDBase: Cannot request both full and thin V")
155 typename internal::make_proper_matrix_type<Scalar, RowsAtCompileTime, MatrixUColsAtCompileTime, MatrixOptions,
156 MaxRowsAtCompileTime, MatrixUMaxColsAtCompileTime>::type;
158 typename internal::make_proper_matrix_type<Scalar, ColsAtCompileTime, MatrixVColsAtCompileTime, MatrixOptions,
159 MaxColsAtCompileTime, MatrixVMaxColsAtCompileTime>::type;
161 using SingularValuesType =
typename internal::plain_diag_type<MatrixType, RealScalar>::type;
163 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
164 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
177 _check_compute_assertions();
178 eigen_assert(
computeU() &&
"This SVD decomposition didn't compute U. Did you ask for it?");
193 _check_compute_assertions();
194 eigen_assert(
computeV() &&
"This SVD decomposition didn't compute V. Did you ask for it?");
204 _check_compute_assertions();
205 return m_singularValues;
210 _check_compute_assertions();
211 return m_nonzeroSingularValues;
221 _check_compute_assertions();
222 if (m_singularValues.size() == 0)
return 0;
223 RealScalar premultiplied_threshold =
224 numext::maxi<RealScalar>(m_singularValues.coeff(0) *
threshold(), (std::numeric_limits<RealScalar>::min)());
225 Index i = m_nonzeroSingularValues - 1;
226 while (i >= 0 && m_singularValues.coeff(i) < premultiplied_threshold) --i;
245 m_usePrescribedThreshold =
true;
259 m_usePrescribedThreshold =
false;
268 eigen_assert(m_isInitialized || m_usePrescribedThreshold);
270 Index diagSize = (std::max<Index>)(1, m_diagSize);
271 return m_usePrescribedThreshold ? m_prescribedThreshold : RealScalar(diagSize) * NumTraits<Scalar>::epsilon();
275 inline bool computeU()
const {
return m_computeFullU || m_computeThinU; }
277 inline bool computeV()
const {
return m_computeFullV || m_computeThinV; }
279 inline Index rows()
const {
return m_rows.value(); }
280 inline Index cols()
const {
return m_cols.value(); }
281 inline Index diagSize()
const {
return m_diagSize.value(); }
283#ifdef EIGEN_PARSED_BY_DOXYGEN
294 template <
typename Rhs>
303 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
307#ifndef EIGEN_PARSED_BY_DOXYGEN
308 template <
typename RhsType,
typename DstType>
309 void _solve_impl(
const RhsType& rhs, DstType& dst)
const;
311 template <
bool Conjugate,
typename RhsType,
typename DstType>
312 void _solve_impl_transposed(
const RhsType& rhs, DstType& dst)
const;
316 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
318 void _check_compute_assertions()
const { eigen_assert(m_isInitialized &&
"SVD is not initialized."); }
320 template <
bool Transpose_,
typename Rhs>
321 void _check_solve_assertion(
const Rhs& b)
const {
322 _check_compute_assertions();
324 "SVDBase::solve(): Both unitaries U and V are required to be computed (thin unitaries suffice).");
325 EIGEN_INTERNAL_ASSERT_SOLVER_RHS_MSG(derived(), b, Transpose_,
326 "SVDBase::solve(): invalid number of rows of the right hand side matrix b");
330 bool allocate(
Index rows,
Index cols,
unsigned int computationOptions);
332 MatrixUType m_matrixU;
333 MatrixVType m_matrixV;
334 SingularValuesType m_singularValues;
336 bool m_isInitialized, m_isAllocated, m_usePrescribedThreshold;
337 bool m_computeFullU, m_computeThinU;
338 bool m_computeFullV, m_computeThinV;
339 unsigned int m_computationOptions;
340 Index m_nonzeroSingularValues;
341 internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
342 internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
343 internal::variable_if_dynamic<Index, DiagSizeAtCompileTime> m_diagSize;
344 RealScalar m_prescribedThreshold;
351 : m_matrixU(MatrixUType()),
352 m_matrixV(MatrixVType()),
353 m_singularValues(SingularValuesType()),
355 m_isInitialized(false),
356 m_isAllocated(false),
357 m_usePrescribedThreshold(false),
358 m_computeFullU(ShouldComputeFullU),
359 m_computeThinU(ShouldComputeThinU),
360 m_computeFullV(ShouldComputeFullV),
361 m_computeThinV(ShouldComputeThinV),
362 m_computationOptions(internal::traits<Derived>::Options),
363 m_nonzeroSingularValues(0),
364 m_rows(RowsAtCompileTime),
365 m_cols(ColsAtCompileTime),
366 m_diagSize(DiagSizeAtCompileTime),
367 m_prescribedThreshold(0) {}