ADD: added other eigen lib
This commit is contained in:
@@ -16,9 +16,42 @@
|
||||
#ifndef EIGEN_SVDBASE_H
|
||||
#define EIGEN_SVDBASE_H
|
||||
|
||||
#include "./InternalHeaderCheck.h"
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
namespace internal {
|
||||
|
||||
enum OptionsMasks {
|
||||
QRPreconditionerBits = NoQRPreconditioner | HouseholderQRPreconditioner | ColPivHouseholderQRPreconditioner |
|
||||
FullPivHouseholderQRPreconditioner,
|
||||
ComputationOptionsBits = ComputeThinU | ComputeFullU | ComputeThinV | ComputeFullV
|
||||
};
|
||||
|
||||
constexpr int get_qr_preconditioner(int options) { return options & QRPreconditionerBits; }
|
||||
|
||||
constexpr int get_computation_options(int options) { return options & ComputationOptionsBits; }
|
||||
|
||||
constexpr bool should_svd_compute_thin_u(int options) { return (options & ComputeThinU) != 0; }
|
||||
constexpr bool should_svd_compute_full_u(int options) { return (options & ComputeFullU) != 0; }
|
||||
constexpr bool should_svd_compute_thin_v(int options) { return (options & ComputeThinV) != 0; }
|
||||
constexpr bool should_svd_compute_full_v(int options) { return (options & ComputeFullV) != 0; }
|
||||
|
||||
template<typename MatrixType, int Options>
|
||||
void check_svd_options_assertions(unsigned int computationOptions, Index rows, Index cols) {
|
||||
EIGEN_STATIC_ASSERT((Options & ComputationOptionsBits) == 0,
|
||||
"SVDBase: Cannot request U or V using both static and runtime options, even if they match. "
|
||||
"Requesting unitaries at runtime is DEPRECATED: "
|
||||
"Prefer requesting unitaries statically, using the Options template parameter.");
|
||||
eigen_assert(!(should_svd_compute_thin_u(computationOptions) && cols < rows && MatrixType::RowsAtCompileTime != Dynamic) &&
|
||||
!(should_svd_compute_thin_v(computationOptions) && rows < cols && MatrixType::ColsAtCompileTime != Dynamic) &&
|
||||
"SVDBase: If thin U is requested at runtime, your matrix must have more rows than columns or a dynamic number of rows."
|
||||
"Similarly, if thin V is requested at runtime, you matrix must have more columns than rows or a dynamic number of columns.");
|
||||
(void)computationOptions;
|
||||
(void)rows;
|
||||
(void)cols;
|
||||
}
|
||||
|
||||
template<typename Derived> struct traits<SVDBase<Derived> >
|
||||
: traits<Derived>
|
||||
{
|
||||
@@ -27,6 +60,29 @@ template<typename Derived> struct traits<SVDBase<Derived> >
|
||||
typedef int StorageIndex;
|
||||
enum { Flags = 0 };
|
||||
};
|
||||
|
||||
template <typename MatrixType, int Options_>
|
||||
struct svd_traits : traits<MatrixType> {
|
||||
static constexpr int Options = Options_;
|
||||
static constexpr bool ShouldComputeFullU = internal::should_svd_compute_full_u(Options);
|
||||
static constexpr bool ShouldComputeThinU = internal::should_svd_compute_thin_u(Options);
|
||||
static constexpr bool ShouldComputeFullV = internal::should_svd_compute_full_v(Options);
|
||||
static constexpr bool ShouldComputeThinV = internal::should_svd_compute_thin_v(Options);
|
||||
enum {
|
||||
DiagSizeAtCompileTime =
|
||||
internal::min_size_prefer_dynamic(MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime),
|
||||
MaxDiagSizeAtCompileTime =
|
||||
internal::min_size_prefer_dynamic(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime),
|
||||
MatrixUColsAtCompileTime = ShouldComputeThinU ? DiagSizeAtCompileTime
|
||||
: MatrixType::RowsAtCompileTime,
|
||||
MatrixVColsAtCompileTime = ShouldComputeThinV ? DiagSizeAtCompileTime
|
||||
: MatrixType::ColsAtCompileTime,
|
||||
MatrixUMaxColsAtCompileTime = ShouldComputeThinU ? MaxDiagSizeAtCompileTime
|
||||
: MatrixType::MaxRowsAtCompileTime,
|
||||
MatrixVMaxColsAtCompileTime = ShouldComputeThinV ? MaxDiagSizeAtCompileTime
|
||||
: MatrixType::MaxColsAtCompileTime
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** \ingroup SVD_Module
|
||||
@@ -52,7 +108,7 @@ template<typename Derived> struct traits<SVDBase<Derived> >
|
||||
* singular vectors. Asking for \em thin \a U or \a V means asking for only their \a m first columns to be formed. So \a U is then a n-by-m matrix,
|
||||
* and \a V is then a p-by-m matrix. Notice that thin \a U and \a V are all you need for (least squares) solving.
|
||||
*
|
||||
* The status of the computation can be retrived using the \a info() method. Unless \a info() returns \a Success, the results should be not
|
||||
* The status of the computation can be retrieved using the \a info() method. Unless \a info() returns \a Success, the results should be not
|
||||
* considered well defined.
|
||||
*
|
||||
* If the input matrix has inf or nan coefficients, the result of the computation is undefined, and \a info() will return \a InvalidInput, but the computation is guaranteed to
|
||||
@@ -72,20 +128,38 @@ public:
|
||||
typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
|
||||
typedef typename Eigen::internal::traits<SVDBase>::StorageIndex StorageIndex;
|
||||
typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
|
||||
|
||||
static constexpr bool ShouldComputeFullU = internal::traits<Derived>::ShouldComputeFullU;
|
||||
static constexpr bool ShouldComputeThinU = internal::traits<Derived>::ShouldComputeThinU;
|
||||
static constexpr bool ShouldComputeFullV = internal::traits<Derived>::ShouldComputeFullV;
|
||||
static constexpr bool ShouldComputeThinV = internal::traits<Derived>::ShouldComputeThinV;
|
||||
|
||||
enum {
|
||||
RowsAtCompileTime = MatrixType::RowsAtCompileTime,
|
||||
ColsAtCompileTime = MatrixType::ColsAtCompileTime,
|
||||
DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime),
|
||||
DiagSizeAtCompileTime = internal::min_size_prefer_dynamic(RowsAtCompileTime, ColsAtCompileTime),
|
||||
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
|
||||
MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime,MaxColsAtCompileTime),
|
||||
MatrixOptions = MatrixType::Options
|
||||
MaxDiagSizeAtCompileTime = internal::min_size_prefer_fixed(MaxRowsAtCompileTime, MaxColsAtCompileTime),
|
||||
MatrixOptions = MatrixType::Options,
|
||||
MatrixUColsAtCompileTime = internal::traits<Derived>::MatrixUColsAtCompileTime,
|
||||
MatrixVColsAtCompileTime = internal::traits<Derived>::MatrixVColsAtCompileTime,
|
||||
MatrixUMaxColsAtCompileTime = internal::traits<Derived>::MatrixUMaxColsAtCompileTime,
|
||||
MatrixVMaxColsAtCompileTime = internal::traits<Derived>::MatrixVMaxColsAtCompileTime
|
||||
};
|
||||
|
||||
typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime, MatrixOptions, MaxRowsAtCompileTime, MaxRowsAtCompileTime> MatrixUType;
|
||||
typedef Matrix<Scalar, ColsAtCompileTime, ColsAtCompileTime, MatrixOptions, MaxColsAtCompileTime, MaxColsAtCompileTime> MatrixVType;
|
||||
EIGEN_STATIC_ASSERT(!(ShouldComputeFullU && ShouldComputeThinU), "SVDBase: Cannot request both full and thin U")
|
||||
EIGEN_STATIC_ASSERT(!(ShouldComputeFullV && ShouldComputeThinV), "SVDBase: Cannot request both full and thin V")
|
||||
|
||||
typedef
|
||||
typename internal::make_proper_matrix_type<Scalar, RowsAtCompileTime, MatrixUColsAtCompileTime, MatrixOptions,
|
||||
MaxRowsAtCompileTime, MatrixUMaxColsAtCompileTime>::type MatrixUType;
|
||||
typedef
|
||||
typename internal::make_proper_matrix_type<Scalar, ColsAtCompileTime, MatrixVColsAtCompileTime, MatrixOptions,
|
||||
MaxColsAtCompileTime, MatrixVMaxColsAtCompileTime>::type MatrixVType;
|
||||
|
||||
typedef typename internal::plain_diag_type<MatrixType, RealScalar>::type SingularValuesType;
|
||||
|
||||
|
||||
Derived& derived() { return *static_cast<Derived*>(this); }
|
||||
const Derived& derived() const { return *static_cast<const Derived*>(this); }
|
||||
|
||||
@@ -249,10 +323,7 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
static void check_template_parameters()
|
||||
{
|
||||
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
|
||||
}
|
||||
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
||||
|
||||
void _check_compute_assertions() const {
|
||||
eigen_assert(m_isInitialized && "SVD is not initialized.");
|
||||
@@ -267,7 +338,7 @@ protected:
|
||||
}
|
||||
|
||||
// return true if already allocated
|
||||
bool allocate(Index rows, Index cols, unsigned int computationOptions) ;
|
||||
bool allocate(Index rows, Index cols, unsigned int computationOptions);
|
||||
|
||||
MatrixUType m_matrixU;
|
||||
MatrixVType m_matrixV;
|
||||
@@ -285,21 +356,18 @@ protected:
|
||||
* Default constructor of SVDBase
|
||||
*/
|
||||
SVDBase()
|
||||
: m_info(Success),
|
||||
m_isInitialized(false),
|
||||
m_isAllocated(false),
|
||||
m_usePrescribedThreshold(false),
|
||||
m_computeFullU(false),
|
||||
m_computeThinU(false),
|
||||
m_computeFullV(false),
|
||||
m_computeThinV(false),
|
||||
m_computationOptions(0),
|
||||
m_rows(-1), m_cols(-1), m_diagSize(0)
|
||||
{
|
||||
check_template_parameters();
|
||||
}
|
||||
|
||||
|
||||
: m_info(Success),
|
||||
m_isInitialized(false),
|
||||
m_isAllocated(false),
|
||||
m_usePrescribedThreshold(false),
|
||||
m_computeFullU(false),
|
||||
m_computeThinU(false),
|
||||
m_computeFullV(false),
|
||||
m_computeThinV(false),
|
||||
m_computationOptions(0),
|
||||
m_rows(-1),
|
||||
m_cols(-1),
|
||||
m_diagSize(0) {}
|
||||
};
|
||||
|
||||
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
||||
@@ -333,9 +401,8 @@ void SVDBase<Derived>::_solve_impl_transposed(const RhsType &rhs, DstType &dst)
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename MatrixType>
|
||||
bool SVDBase<MatrixType>::allocate(Index rows, Index cols, unsigned int computationOptions)
|
||||
{
|
||||
template <typename Derived>
|
||||
bool SVDBase<Derived>::allocate(Index rows, Index cols, unsigned int computationOptions) {
|
||||
eigen_assert(rows >= 0 && cols >= 0);
|
||||
|
||||
if (m_isAllocated &&
|
||||
@@ -352,14 +419,13 @@ bool SVDBase<MatrixType>::allocate(Index rows, Index cols, unsigned int computat
|
||||
m_isInitialized = false;
|
||||
m_isAllocated = true;
|
||||
m_computationOptions = computationOptions;
|
||||
m_computeFullU = (computationOptions & ComputeFullU) != 0;
|
||||
m_computeThinU = (computationOptions & ComputeThinU) != 0;
|
||||
m_computeFullV = (computationOptions & ComputeFullV) != 0;
|
||||
m_computeThinV = (computationOptions & ComputeThinV) != 0;
|
||||
m_computeFullU = ShouldComputeFullU || internal::should_svd_compute_full_u(computationOptions);
|
||||
m_computeThinU = ShouldComputeThinU || internal::should_svd_compute_thin_u(computationOptions);
|
||||
m_computeFullV = ShouldComputeFullV || internal::should_svd_compute_full_v(computationOptions);
|
||||
m_computeThinV = ShouldComputeThinV || internal::should_svd_compute_thin_v(computationOptions);
|
||||
|
||||
eigen_assert(!(m_computeFullU && m_computeThinU) && "SVDBase: you can't ask for both full and thin U");
|
||||
eigen_assert(!(m_computeFullV && m_computeThinV) && "SVDBase: you can't ask for both full and thin V");
|
||||
eigen_assert(EIGEN_IMPLIES(m_computeThinU || m_computeThinV, MatrixType::ColsAtCompileTime==Dynamic) &&
|
||||
"SVDBase: thin U and V are only available when your matrix has a dynamic number of columns.");
|
||||
|
||||
m_diagSize = (std::min)(m_rows, m_cols);
|
||||
m_singularValues.resize(m_diagSize);
|
||||
|
||||
Reference in New Issue
Block a user