45 template<
typename _MatrixType>
50 typedef _MatrixType MatrixType;
51 typedef typename MatrixType::Scalar Scalar;
52 typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
53 typedef typename MatrixType::Index Index;
55 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
56 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
57 DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime),
58 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
59 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
60 MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime,MaxColsAtCompileTime),
61 MatrixOptions = MatrixType::Options
64 typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime,
65 MatrixOptions, MaxRowsAtCompileTime, MaxRowsAtCompileTime>
67 typedef Matrix<Scalar, ColsAtCompileTime, ColsAtCompileTime,
68 MatrixOptions, MaxColsAtCompileTime, MaxColsAtCompileTime>
70 typedef typename internal::plain_diag_type<MatrixType, RealScalar>::type SingularValuesType;
71 typedef typename internal::plain_row_type<MatrixType>::type RowType;
72 typedef typename internal::plain_col_type<MatrixType>::type ColType;
73 typedef Matrix<Scalar, DiagSizeAtCompileTime, DiagSizeAtCompileTime,
74 MatrixOptions, MaxDiagSizeAtCompileTime, MaxDiagSizeAtCompileTime>
90 SVDBase&
compute(
const MatrixType& matrix,
unsigned int computationOptions);
112 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
113 eigen_assert(
computeU() &&
"This SVD decomposition didn't compute U. Did you ask for it?");
128 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
129 eigen_assert(
computeV() &&
"This SVD decomposition didn't compute V. Did you ask for it?");
140 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
141 return m_singularValues;
149 eigen_assert(m_isInitialized &&
"SVD is not initialized.");
150 return m_nonzeroSingularValues;
155 inline bool computeU()
const {
return m_computeFullU || m_computeThinU; }
157 inline bool computeV()
const {
return m_computeFullV || m_computeThinV; }
160 inline Index rows()
const {
return m_rows; }
161 inline Index cols()
const {
return m_cols; }
166 bool allocate(Index rows, Index cols,
unsigned int computationOptions) ;
168 MatrixUType m_matrixU;
169 MatrixVType m_matrixV;
170 SingularValuesType m_singularValues;
171 bool m_isInitialized, m_isAllocated;
172 bool m_computeFullU, m_computeThinU;
173 bool m_computeFullV, m_computeThinV;
174 unsigned int m_computationOptions;
175 Index m_nonzeroSingularValues, m_rows, m_cols, m_diagSize;
183 : m_isInitialized(false),
184 m_isAllocated(false),
185 m_computationOptions(0),
186 m_rows(-1), m_cols(-1)
193 template<
typename MatrixType>
194 bool SVDBase<MatrixType>::allocate(Index rows, Index cols,
unsigned int computationOptions)
196 eigen_assert(rows >= 0 && cols >= 0);
201 computationOptions == m_computationOptions)
208 m_isInitialized =
false;
209 m_isAllocated =
true;
210 m_computationOptions = computationOptions;
211 m_computeFullU = (computationOptions & ComputeFullU) != 0;
212 m_computeThinU = (computationOptions & ComputeThinU) != 0;
213 m_computeFullV = (computationOptions & ComputeFullV) != 0;
214 m_computeThinV = (computationOptions & ComputeThinV) != 0;
215 eigen_assert(!(m_computeFullU && m_computeThinU) &&
"SVDBase: you can't ask for both full and thin U");
216 eigen_assert(!(m_computeFullV && m_computeThinV) &&
"SVDBase: you can't ask for both full and thin V");
217 eigen_assert(EIGEN_IMPLIES(m_computeThinU || m_computeThinV, MatrixType::ColsAtCompileTime==Dynamic) &&
218 "SVDBase: thin U and V are only available when your matrix has a dynamic number of columns.");
220 m_diagSize = (std::min)(m_rows, m_cols);
221 m_singularValues.resize(m_diagSize);
222 if(RowsAtCompileTime==Dynamic)
223 m_matrixU.resize(m_rows, m_computeFullU ? m_rows
224 : m_computeThinU ? m_diagSize
226 if(ColsAtCompileTime==Dynamic)
227 m_matrixV.resize(m_cols, m_computeFullV ? m_cols
228 : m_computeThinV ? m_diagSize
236 #endif // EIGEN_SVD_H
const MatrixUType & matrixU() const
Definition: SVDBase.h:110
bool computeU() const
Definition: SVDBase.h:155
Mother class of SVD classes algorithms.
Definition: SVDBase.h:46
SVDBase()
Default Constructor.
Definition: SVDBase.h:182
const SingularValuesType & singularValues() const
Definition: SVDBase.h:138
SVDBase & compute(const MatrixType &matrix, unsigned int computationOptions)
Method performing the decomposition of given matrix using custom options.
const MatrixVType & matrixV() const
Definition: SVDBase.h:126
bool computeV() const
Definition: SVDBase.h:157
Index nonzeroSingularValues() const
Definition: SVDBase.h:147