16 #ifndef EIGEN_SVDBASE_H 17 #define EIGEN_SVDBASE_H 47 template<
typename Derived>
53 typedef typename MatrixType::Scalar Scalar;
55 typedef typename MatrixType::StorageIndex StorageIndex;
58 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
59 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
60 DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime),
61 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
62 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
63 MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime,MaxColsAtCompileTime),
64 MatrixOptions = MatrixType::Options
71 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
72 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
85 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
86 eigen_assert(
computeU() &&
"This SVD decomposition didn't compute U. Did you ask for it?");
101 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
102 eigen_assert(
computeV() &&
"This SVD decomposition didn't compute V. Did you ask for it?");
113 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
114 return m_singularValues;
120 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
121 return m_nonzeroSingularValues;
133 eigen_assert(m_isInitialized &&
"JacobiSVD is not initialized.");
134 if(m_singularValues.size()==0)
return 0;
135 RealScalar premultiplied_threshold = numext::maxi<RealScalar>(m_singularValues.coeff(0) *
threshold(), (std::numeric_limits<RealScalar>::min)());
136 Index i = m_nonzeroSingularValues-1;
137 while(i>=0 && m_singularValues.coeff(i) < premultiplied_threshold) --i;
157 m_usePrescribedThreshold =
true;
172 m_usePrescribedThreshold =
false;
182 eigen_assert(m_isInitialized || m_usePrescribedThreshold);
183 return m_usePrescribedThreshold ? m_prescribedThreshold
188 inline bool computeU()
const {
return m_computeFullU || m_computeThinU; }
190 inline bool computeV()
const {
return m_computeFullV || m_computeThinV; }
192 inline Index rows()
const {
return m_rows; }
193 inline Index cols()
const {
return m_cols; }
204 template<
typename Rhs>
208 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
209 eigen_assert(
computeU() &&
computeV() &&
"SVD::solve() requires both unitaries U and V to be computed (thin unitaries suffice).");
213 #ifndef EIGEN_PARSED_BY_DOXYGEN 214 template<
typename RhsType,
typename DstType>
216 void _solve_impl(
const RhsType &rhs, DstType &dst)
const;
221 static void check_template_parameters()
223 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
227 bool allocate(Index rows, Index cols,
unsigned int computationOptions) ;
229 MatrixUType m_matrixU;
230 MatrixVType m_matrixV;
231 SingularValuesType m_singularValues;
232 bool m_isInitialized, m_isAllocated, m_usePrescribedThreshold;
233 bool m_computeFullU, m_computeThinU;
234 bool m_computeFullV, m_computeThinV;
235 unsigned int m_computationOptions;
236 Index m_nonzeroSingularValues, m_rows, m_cols, m_diagSize;
237 RealScalar m_prescribedThreshold;
244 : m_isInitialized(false),
245 m_isAllocated(false),
246 m_usePrescribedThreshold(false),
247 m_computationOptions(0),
248 m_rows(-1), m_cols(-1), m_diagSize(0)
250 check_template_parameters();
256 #ifndef EIGEN_PARSED_BY_DOXYGEN 257 template<
typename Derived>
258 template<
typename RhsType,
typename DstType>
261 eigen_assert(rhs.rows() == rows());
268 tmp.noalias() = m_matrixU.leftCols(l_rank).adjoint() * rhs;
269 tmp = m_singularValues.head(l_rank).asDiagonal().inverse() * tmp;
270 dst = m_matrixV.leftCols(l_rank) * tmp;
274 template<
typename MatrixType>
277 eigen_assert(rows >= 0 && cols >= 0);
282 computationOptions == m_computationOptions)
289 m_isInitialized =
false;
290 m_isAllocated =
true;
291 m_computationOptions = computationOptions;
292 m_computeFullU = (computationOptions &
ComputeFullU) != 0;
293 m_computeThinU = (computationOptions &
ComputeThinU) != 0;
294 m_computeFullV = (computationOptions &
ComputeFullV) != 0;
295 m_computeThinV = (computationOptions &
ComputeThinV) != 0;
296 eigen_assert(!(m_computeFullU && m_computeThinU) &&
"SVDBase: you can't ask for both full and thin U");
297 eigen_assert(!(m_computeFullV && m_computeThinV) &&
"SVDBase: you can't ask for both full and thin V");
298 eigen_assert(EIGEN_IMPLIES(m_computeThinU || m_computeThinV, MatrixType::ColsAtCompileTime==
Dynamic) &&
299 "SVDBase: thin U and V are only available when your matrix has a dynamic number of columns.");
301 m_diagSize = (std::min)(m_rows, m_cols);
302 m_singularValues.resize(m_diagSize);
304 m_matrixU.
resize(m_rows, m_computeFullU ? m_rows : m_computeThinU ? m_diagSize : 0);
306 m_matrixV.
resize(m_cols, m_computeFullV ? m_cols : m_computeThinV ? m_diagSize : 0);
313 #endif // EIGEN_SVDBASE_H Used in JacobiSVD to indicate that the square matrix U is to be computed.
Definition: Constants.h:383
Index rank() const
Definition: SVDBase.h:130
Derived & setThreshold(Default_t)
Allows to come back to the default behavior, letting Eigen use its default formula for determining th...
Definition: SVDBase.h:170
Used in JacobiSVD to indicate that the thin matrix V is to be computed.
Definition: Constants.h:389
const MatrixUType & matrixU() const
Definition: SVDBase.h:83
Eigen::Index Index
Definition: SVDBase.h:56
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SVDBase.h:206
bool computeV() const
Definition: SVDBase.h:190
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Resizes *this to a rows x cols matrix.
Definition: PlainObjectBase.h:273
Base class of SVD algorithms.
Definition: SVDBase.h:48
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
SVDBase()
Default Constructor.
Definition: SVDBase.h:243
Derived & setThreshold(const RealScalar &threshold)
Allows to prescribe a threshold to be used by certain methods, such as rank() and solve()...
Definition: SVDBase.h:155
RealScalar threshold() const
Returns the threshold that will be used by certain methods such as rank().
Definition: SVDBase.h:180
Index nonzeroSingularValues() const
Definition: SVDBase.h:118
const SingularValuesType & singularValues() const
Definition: SVDBase.h:111
bool computeU() const
Definition: SVDBase.h:188
const MatrixVType & matrixV() const
Definition: SVDBase.h:99
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
Pseudo expression representing a solving operation.
Definition: Solve.h:62
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
Used in JacobiSVD to indicate that the square matrix V is to be computed.
Definition: Constants.h:387
Used in JacobiSVD to indicate that the thin matrix U is to be computed.
Definition: Constants.h:385
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17