133 template <
typename Derived_>
134 friend struct internal::solve_assertion;
136 using MatrixType =
typename internal::traits<Derived>::MatrixType;
137 using Scalar =
typename MatrixType::Scalar;
138 using RealScalar =
typename NumTraits<typename MatrixType::Scalar>::Real;
139 using StorageIndex =
typename Eigen::internal::traits<SVDBase>::StorageIndex;
141 static constexpr bool ShouldComputeFullU = internal::traits<Derived>::ShouldComputeFullU;
142 static constexpr bool ShouldComputeThinU = internal::traits<Derived>::ShouldComputeThinU;
143 static constexpr bool ShouldComputeFullV = internal::traits<Derived>::ShouldComputeFullV;
144 static constexpr bool ShouldComputeThinV = internal::traits<Derived>::ShouldComputeThinV;
147 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
148 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
149 DiagSizeAtCompileTime = internal::min_size_prefer_dynamic(RowsAtCompileTime, ColsAtCompileTime),
150 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
151 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
152 MaxDiagSizeAtCompileTime = internal::min_size_prefer_fixed(MaxRowsAtCompileTime, MaxColsAtCompileTime),
153 MatrixOptions = internal::traits<MatrixType>::Options,
154 MatrixUColsAtCompileTime = internal::traits<Derived>::MatrixUColsAtCompileTime,
155 MatrixVColsAtCompileTime = internal::traits<Derived>::MatrixVColsAtCompileTime,
156 MatrixUMaxColsAtCompileTime = internal::traits<Derived>::MatrixUMaxColsAtCompileTime,
157 MatrixVMaxColsAtCompileTime = internal::traits<Derived>::MatrixVMaxColsAtCompileTime
160 EIGEN_STATIC_ASSERT(!(ShouldComputeFullU && ShouldComputeThinU),
"SVDBase: Cannot request both full and thin U")
161 EIGEN_STATIC_ASSERT(!(ShouldComputeFullV && ShouldComputeThinV),
"SVDBase: Cannot request both full and thin V")
164 typename internal::make_proper_matrix_type<Scalar, RowsAtCompileTime, MatrixUColsAtCompileTime, MatrixOptions,
165 MaxRowsAtCompileTime, MatrixUMaxColsAtCompileTime>::type;
167 typename internal::make_proper_matrix_type<Scalar, ColsAtCompileTime, MatrixVColsAtCompileTime, MatrixOptions,
168 MaxColsAtCompileTime, MatrixVMaxColsAtCompileTime>::type;
170 using SingularValuesType =
typename internal::plain_diag_type<MatrixType, RealScalar>::type;
172 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
173 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
186 _check_compute_assertions();
187 eigen_assert(
computeU() &&
"This SVD decomposition didn't compute U. Did you ask for it?");
202 _check_compute_assertions();
203 eigen_assert(
computeV() &&
"This SVD decomposition didn't compute V. Did you ask for it?");
213 _check_compute_assertions();
214 return m_singularValues;
219 _check_compute_assertions();
220 return m_nonzeroSingularValues;
230 _check_compute_assertions();
231 if (m_singularValues.size() == 0)
return 0;
232 RealScalar premultiplied_threshold =
233 numext::maxi<RealScalar>(m_singularValues.coeff(0) *
threshold(), (std::numeric_limits<RealScalar>::min)());
234 Index i = m_nonzeroSingularValues - 1;
235 while (i >= 0 && m_singularValues.coeff(i) < premultiplied_threshold) --i;
254 m_usePrescribedThreshold =
true;
268 m_usePrescribedThreshold =
false;
277 eigen_assert(m_isInitialized || m_usePrescribedThreshold);
279 Index diagSize = (std::max<Index>)(1, m_diagSize);
280 return m_usePrescribedThreshold ? m_prescribedThreshold : RealScalar(diagSize) * NumTraits<Scalar>::epsilon();
284 inline bool computeU()
const {
return m_computeFullU || m_computeThinU; }
286 inline bool computeV()
const {
return m_computeFullV || m_computeThinV; }
288 inline Index rows()
const {
return m_rows.value(); }
289 inline Index cols()
const {
return m_cols.value(); }
290 inline Index diagSize()
const {
return m_diagSize.value(); }
292#ifdef EIGEN_PARSED_BY_DOXYGEN
303 template <
typename Rhs>
312 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
316#ifndef EIGEN_PARSED_BY_DOXYGEN
317 template <
typename RhsType,
typename DstType>
318 void _solve_impl(
const RhsType& rhs, DstType& dst)
const;
320 template <
bool Conjugate,
typename RhsType,
typename DstType>
321 void _solve_impl_transposed(
const RhsType& rhs, DstType& dst)
const;
325 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
327 void _check_compute_assertions()
const { eigen_assert(m_isInitialized &&
"SVD is not initialized."); }
329 template <
bool Transpose_,
typename Rhs>
330 void _check_solve_assertion(
const Rhs& b)
const {
331 _check_compute_assertions();
333 "SVDBase::solve(): Both unitaries U and V are required to be computed (thin unitaries suffice).");
334 EIGEN_INTERNAL_ASSERT_SOLVER_RHS_MSG(derived(), b, Transpose_,
335 "SVDBase::solve(): invalid number of rows of the right hand side matrix b");
339 bool allocate(
Index rows,
Index cols,
unsigned int computationOptions);
341 MatrixUType m_matrixU;
342 MatrixVType m_matrixV;
343 SingularValuesType m_singularValues;
345 bool m_isInitialized, m_isAllocated, m_usePrescribedThreshold;
346 bool m_computeFullU, m_computeThinU;
347 bool m_computeFullV, m_computeThinV;
348 unsigned int m_computationOptions;
349 Index m_nonzeroSingularValues;
350 internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
351 internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
352 internal::variable_if_dynamic<Index, DiagSizeAtCompileTime> m_diagSize;
353 RealScalar m_prescribedThreshold;
360 : m_matrixU(MatrixUType()),
361 m_matrixV(MatrixVType()),
362 m_singularValues(SingularValuesType()),
364 m_isInitialized(false),
365 m_isAllocated(false),
366 m_usePrescribedThreshold(false),
367 m_computeFullU(ShouldComputeFullU),
368 m_computeThinU(ShouldComputeThinU),
369 m_computeFullV(ShouldComputeFullV),
370 m_computeThinV(ShouldComputeThinV),
371 m_computationOptions(internal::traits<Derived>::Options),
372 m_nonzeroSingularValues(0),
373 m_rows(RowsAtCompileTime),
374 m_cols(ColsAtCompileTime),
375 m_diagSize(DiagSizeAtCompileTime),
376 m_prescribedThreshold(0) {}