mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Updates to the Sparse unsupported solvers module.
* change Sparse* specialization's signatures from <..., int Backend> to <..., typename Backend>. Update SparseExtra accordingly to use structs instead of the SparseBackend enum. * add SparseLDLT Cholmod specialization * for Cholmod and UmfPack, SparseLU, SparseLLT and SparseLDLT now use ei_solve_retval and have the new solve() method (to be closer to the 3.0 API). * fix doc
This commit is contained in:
@@ -117,22 +117,24 @@ inline int umfpack_get_determinant(std::complex<double> *Mx, double *Ex, void *N
|
||||
}
|
||||
|
||||
|
||||
template<typename MatrixType>
|
||||
class SparseLU<MatrixType,UmfPack> : public SparseLU<MatrixType>
|
||||
template<typename _MatrixType>
|
||||
class SparseLU<_MatrixType,UmfPack> : public SparseLU<_MatrixType>
|
||||
{
|
||||
protected:
|
||||
typedef SparseLU<MatrixType> Base;
|
||||
typedef SparseLU<_MatrixType> Base;
|
||||
typedef typename Base::Scalar Scalar;
|
||||
typedef typename Base::RealScalar RealScalar;
|
||||
typedef Matrix<Scalar,Dynamic,1> Vector;
|
||||
typedef Matrix<int, 1, MatrixType::ColsAtCompileTime> IntRowVectorType;
|
||||
typedef Matrix<int, MatrixType::RowsAtCompileTime, 1> IntColVectorType;
|
||||
typedef Matrix<int, 1, _MatrixType::ColsAtCompileTime> IntRowVectorType;
|
||||
typedef Matrix<int, _MatrixType::RowsAtCompileTime, 1> IntColVectorType;
|
||||
typedef SparseMatrix<Scalar,Lower|UnitDiag> LMatrixType;
|
||||
typedef SparseMatrix<Scalar,Upper> UMatrixType;
|
||||
using Base::m_flags;
|
||||
using Base::m_status;
|
||||
|
||||
public:
|
||||
typedef _MatrixType MatrixType;
|
||||
typedef typename MatrixType::Index Index;
|
||||
|
||||
SparseLU(int flags = NaturalOrdering)
|
||||
: Base(flags), m_numeric(0)
|
||||
@@ -180,8 +182,30 @@ class SparseLU<MatrixType,UmfPack> : public SparseLU<MatrixType>
|
||||
template<typename BDerived, typename XDerived>
|
||||
bool solve(const MatrixBase<BDerived> &b, MatrixBase<XDerived>* x) const;
|
||||
|
||||
template<typename Rhs>
|
||||
inline const ei_solve_retval<SparseLU<MatrixType, UmfPack>, Rhs>
|
||||
solve(const MatrixBase<Rhs>& b) const
|
||||
{
|
||||
ei_assert(true && "SparseLU is not initialized.");
|
||||
return ei_solve_retval<SparseLU<MatrixType, UmfPack>, Rhs>(*this, b.derived());
|
||||
}
|
||||
|
||||
void compute(const MatrixType& matrix);
|
||||
|
||||
inline Index cols() const { return m_matrixRef->cols(); }
|
||||
inline Index rows() const { return m_matrixRef->rows(); }
|
||||
|
||||
inline const MatrixType& matrixLU() const
|
||||
{
|
||||
//ei_assert(m_isInitialized && "LU is not initialized.");
|
||||
return *m_matrixRef;
|
||||
}
|
||||
|
||||
const void* numeric() const
|
||||
{
|
||||
return m_numeric;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void extractData() const;
|
||||
@@ -197,6 +221,37 @@ class SparseLU<MatrixType,UmfPack> : public SparseLU<MatrixType>
|
||||
mutable bool m_extractedDataAreDirty;
|
||||
};
|
||||
|
||||
|
||||
template<typename _MatrixType, typename Rhs>
|
||||
struct ei_solve_retval<SparseLU<_MatrixType, UmfPack>, Rhs>
|
||||
: ei_solve_retval_base<SparseLU<_MatrixType, UmfPack>, Rhs>
|
||||
{
|
||||
typedef SparseLU<_MatrixType, UmfPack> SpLUDecType;
|
||||
EIGEN_MAKE_SOLVE_HELPERS(SpLUDecType,Rhs)
|
||||
|
||||
template<typename Dest> void evalTo(Dest& dst) const
|
||||
{
|
||||
const int rhsCols = rhs().cols();
|
||||
|
||||
ei_assert((Rhs::Flags&RowMajorBit)==0 && "UmfPack backend does not support non col-major rhs yet");
|
||||
ei_assert((Dest::Flags&RowMajorBit)==0 && "UmfPack backend does not support non col-major result yet");
|
||||
|
||||
void* numeric = const_cast<void*>(dec().numeric());
|
||||
|
||||
int errorCode = 0;
|
||||
for (int j=0; j<rhsCols; ++j)
|
||||
{
|
||||
errorCode = umfpack_solve(UMFPACK_A,
|
||||
dec().matrixLU()._outerIndexPtr(), dec().matrixLU()._innerIndexPtr(), dec().matrixLU()._valuePtr(),
|
||||
&dst.col(j).coeffRef(0), &rhs().const_cast_derived().col(j).coeffRef(0), numeric, 0, 0);
|
||||
ei_assert(!errorCode && "UmfPack could not solve the system.");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename MatrixType>
|
||||
void SparseLU<MatrixType,UmfPack>::compute(const MatrixType& a)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user