2008-10-19 22:44:21 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2008-10-19 22:44:21 +00:00
|
|
|
//
|
2011-09-24 14:19:39 +02:00
|
|
|
// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2008-10-19 22:44:21 +00:00
|
|
|
//
|
|
|
|
|
// Eigen is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
|
// version 3 of the License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// Alternatively, you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2 of
|
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License and a copy of the GNU General Public License along with
|
|
|
|
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
#ifndef EIGEN_UMFPACKSUPPORT_H
|
|
|
|
|
#define EIGEN_UMFPACKSUPPORT_H
|
|
|
|
|
|
2008-10-20 17:03:09 +00:00
|
|
|
/* TODO extract L, extract U, compute det, etc... */
|
|
|
|
|
|
|
|
|
|
// generic double/complex<double> wrapper functions:
|
|
|
|
|
|
|
|
|
|
inline void umfpack_free_numeric(void **Numeric, double)
|
2011-09-24 14:19:39 +02:00
|
|
|
{ umfpack_di_free_numeric(Numeric); *Numeric = 0; }
|
2008-10-20 17:03:09 +00:00
|
|
|
|
|
|
|
|
inline void umfpack_free_numeric(void **Numeric, std::complex<double>)
|
2011-09-24 14:19:39 +02:00
|
|
|
{ umfpack_zi_free_numeric(Numeric); *Numeric = 0; }
|
2008-10-20 17:03:09 +00:00
|
|
|
|
|
|
|
|
inline void umfpack_free_symbolic(void **Symbolic, double)
|
2011-09-24 14:19:39 +02:00
|
|
|
{ umfpack_di_free_symbolic(Symbolic); *Symbolic = 0; }
|
2008-10-20 17:03:09 +00:00
|
|
|
|
|
|
|
|
inline void umfpack_free_symbolic(void **Symbolic, std::complex<double>)
|
2011-09-24 14:19:39 +02:00
|
|
|
{ umfpack_zi_free_symbolic(Symbolic); *Symbolic = 0; }
|
2008-10-20 00:39:11 +00:00
|
|
|
|
|
|
|
|
inline int umfpack_symbolic(int n_row,int n_col,
|
|
|
|
|
const int Ap[], const int Ai[], const double Ax[], void **Symbolic,
|
|
|
|
|
const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
|
|
|
|
|
{
|
|
|
|
|
return umfpack_di_symbolic(n_row,n_col,Ap,Ai,Ax,Symbolic,Control,Info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_symbolic(int n_row,int n_col,
|
|
|
|
|
const int Ap[], const int Ai[], const std::complex<double> Ax[], void **Symbolic,
|
|
|
|
|
const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
|
|
|
|
|
{
|
2011-02-18 18:07:59 +01:00
|
|
|
return umfpack_zi_symbolic(n_row,n_col,Ap,Ai,&internal::real_ref(Ax[0]),0,Symbolic,Control,Info);
|
2008-10-20 00:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_numeric( const int Ap[], const int Ai[], const double Ax[],
|
|
|
|
|
void *Symbolic, void **Numeric,
|
|
|
|
|
const double Control[UMFPACK_CONTROL],double Info [UMFPACK_INFO])
|
|
|
|
|
{
|
|
|
|
|
return umfpack_di_numeric(Ap,Ai,Ax,Symbolic,Numeric,Control,Info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_numeric( const int Ap[], const int Ai[], const std::complex<double> Ax[],
|
|
|
|
|
void *Symbolic, void **Numeric,
|
|
|
|
|
const double Control[UMFPACK_CONTROL],double Info [UMFPACK_INFO])
|
|
|
|
|
{
|
2011-02-18 18:07:59 +01:00
|
|
|
return umfpack_zi_numeric(Ap,Ai,&internal::real_ref(Ax[0]),0,Symbolic,Numeric,Control,Info);
|
2008-10-20 00:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_solve( int sys, const int Ap[], const int Ai[], const double Ax[],
|
|
|
|
|
double X[], const double B[], void *Numeric,
|
|
|
|
|
const double Control[UMFPACK_CONTROL], double Info[UMFPACK_INFO])
|
|
|
|
|
{
|
|
|
|
|
return umfpack_di_solve(sys,Ap,Ai,Ax,X,B,Numeric,Control,Info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_solve( int sys, const int Ap[], const int Ai[], const std::complex<double> Ax[],
|
|
|
|
|
std::complex<double> X[], const std::complex<double> B[], void *Numeric,
|
|
|
|
|
const double Control[UMFPACK_CONTROL], double Info[UMFPACK_INFO])
|
|
|
|
|
{
|
2011-02-18 18:07:59 +01:00
|
|
|
return umfpack_zi_solve(sys,Ap,Ai,&internal::real_ref(Ax[0]),0,&internal::real_ref(X[0]),0,&internal::real_ref(B[0]),0,Numeric,Control,Info);
|
2008-10-20 00:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
2008-10-20 17:03:09 +00:00
|
|
|
inline int umfpack_get_lunz(int *lnz, int *unz, int *n_row, int *n_col, int *nz_udiag, void *Numeric, double)
|
|
|
|
|
{
|
|
|
|
|
return umfpack_di_get_lunz(lnz,unz,n_row,n_col,nz_udiag,Numeric);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_get_lunz(int *lnz, int *unz, int *n_row, int *n_col, int *nz_udiag, void *Numeric, std::complex<double>)
|
|
|
|
|
{
|
|
|
|
|
return umfpack_zi_get_lunz(lnz,unz,n_row,n_col,nz_udiag,Numeric);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_get_numeric(int Lp[], int Lj[], double Lx[], int Up[], int Ui[], double Ux[],
|
|
|
|
|
int P[], int Q[], double Dx[], int *do_recip, double Rs[], void *Numeric)
|
|
|
|
|
{
|
|
|
|
|
return umfpack_di_get_numeric(Lp,Lj,Lx,Up,Ui,Ux,P,Q,Dx,do_recip,Rs,Numeric);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_get_numeric(int Lp[], int Lj[], std::complex<double> Lx[], int Up[], int Ui[], std::complex<double> Ux[],
|
|
|
|
|
int P[], int Q[], std::complex<double> Dx[], int *do_recip, double Rs[], void *Numeric)
|
|
|
|
|
{
|
2011-02-18 18:07:59 +01:00
|
|
|
double& lx0_real = internal::real_ref(Lx[0]);
|
|
|
|
|
double& ux0_real = internal::real_ref(Ux[0]);
|
|
|
|
|
double& dx0_real = internal::real_ref(Dx[0]);
|
2011-01-07 10:27:22 +01:00
|
|
|
return umfpack_zi_get_numeric(Lp,Lj,Lx?&lx0_real:0,0,Up,Ui,Ux?&ux0_real:0,0,P,Q,
|
2011-02-18 18:07:59 +01:00
|
|
|
Dx?&dx0_real:0,0,do_recip,Rs,Numeric);
|
2008-10-20 17:03:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_get_determinant(double *Mx, double *Ex, void *NumericHandle, double User_Info [UMFPACK_INFO])
|
|
|
|
|
{
|
|
|
|
|
return umfpack_di_get_determinant(Mx,Ex,NumericHandle,User_Info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int umfpack_get_determinant(std::complex<double> *Mx, double *Ex, void *NumericHandle, double User_Info [UMFPACK_INFO])
|
|
|
|
|
{
|
2011-02-18 18:07:59 +01:00
|
|
|
double& mx_real = internal::real_ref(*Mx);
|
2011-01-07 10:27:22 +01:00
|
|
|
return umfpack_zi_get_determinant(&mx_real,0,Ex,NumericHandle,User_Info);
|
2008-10-20 17:03:09 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-28 16:36:37 +01:00
|
|
|
/** \ingroup UmfPackSupport_Module
|
|
|
|
|
* \brief A sparse LU factorization and solver based on UmfPack
|
2011-09-24 14:19:39 +02:00
|
|
|
*
|
|
|
|
|
* This class allows to solve for A.X = B sparse linear problems via a LU factorization
|
|
|
|
|
* using the UmfPack library. The sparse matrix A must be column-major, squared and full rank.
|
|
|
|
|
* The vectors or matrices X and B can be either dense or sparse.
|
|
|
|
|
*
|
|
|
|
|
* \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<>
|
|
|
|
|
*
|
2011-11-28 16:36:37 +01:00
|
|
|
* \sa \ref TutorialSparseDirectSolvers
|
2011-09-24 14:19:39 +02:00
|
|
|
*/
|
2010-10-04 20:56:54 +02:00
|
|
|
template<typename _MatrixType>
|
2011-09-24 14:19:39 +02:00
|
|
|
class UmfPackLU
|
2008-10-19 22:44:21 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2010-10-04 20:56:54 +02:00
|
|
|
typedef _MatrixType MatrixType;
|
2011-09-24 14:19:39 +02:00
|
|
|
typedef typename MatrixType::Scalar Scalar;
|
|
|
|
|
typedef typename MatrixType::RealScalar RealScalar;
|
2010-10-04 20:56:54 +02:00
|
|
|
typedef typename MatrixType::Index Index;
|
2011-09-24 14:19:39 +02:00
|
|
|
typedef Matrix<Scalar,Dynamic,1> Vector;
|
|
|
|
|
typedef Matrix<int, 1, MatrixType::ColsAtCompileTime> IntRowVectorType;
|
|
|
|
|
typedef Matrix<int, MatrixType::RowsAtCompileTime, 1> IntColVectorType;
|
|
|
|
|
typedef SparseMatrix<Scalar> LUMatrixType;
|
2008-10-19 22:44:21 +00:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
UmfPackLU() { init(); }
|
|
|
|
|
|
|
|
|
|
UmfPackLU(const MatrixType& matrix)
|
2008-10-19 22:44:21 +00:00
|
|
|
{
|
2011-09-24 14:19:39 +02:00
|
|
|
init();
|
|
|
|
|
compute(matrix);
|
2008-10-19 22:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
~UmfPackLU()
|
2008-10-19 22:44:21 +00:00
|
|
|
{
|
2011-09-24 14:19:39 +02:00
|
|
|
if(m_symbolic) umfpack_free_symbolic(&m_symbolic,Scalar());
|
|
|
|
|
if(m_numeric) umfpack_free_numeric(&m_numeric,Scalar());
|
2008-10-19 22:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
inline Index rows() const { return m_matrixRef->rows(); }
|
|
|
|
|
inline Index cols() const { return m_matrixRef->cols(); }
|
|
|
|
|
|
|
|
|
|
/** \brief Reports whether previous computation was successful.
|
|
|
|
|
*
|
|
|
|
|
* \returns \c Success if computation was succesful,
|
|
|
|
|
* \c NumericalIssue if the matrix.appears to be negative.
|
|
|
|
|
*/
|
|
|
|
|
ComputationInfo info() const
|
2008-10-19 22:44:21 +00:00
|
|
|
{
|
2011-09-24 14:19:39 +02:00
|
|
|
eigen_assert(m_isInitialized && "Decomposition is not initialized.");
|
|
|
|
|
return m_info;
|
2008-10-20 17:03:09 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
inline const LUMatrixType& matrixL() const
|
2008-10-20 17:03:09 +00:00
|
|
|
{
|
|
|
|
|
if (m_extractedDataAreDirty) extractData();
|
|
|
|
|
return m_l;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
inline const LUMatrixType& matrixU() const
|
2008-10-20 17:03:09 +00:00
|
|
|
{
|
|
|
|
|
if (m_extractedDataAreDirty) extractData();
|
|
|
|
|
return m_u;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline const IntColVectorType& permutationP() const
|
|
|
|
|
{
|
|
|
|
|
if (m_extractedDataAreDirty) extractData();
|
|
|
|
|
return m_p;
|
2008-10-19 22:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
2008-10-20 17:03:09 +00:00
|
|
|
inline const IntRowVectorType& permutationQ() const
|
|
|
|
|
{
|
|
|
|
|
if (m_extractedDataAreDirty) extractData();
|
|
|
|
|
return m_q;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
/** Computes the sparse Cholesky decomposition of \a matrix */
|
|
|
|
|
void compute(const MatrixType& matrix)
|
|
|
|
|
{
|
|
|
|
|
analyzePattern(matrix);
|
|
|
|
|
factorize(matrix);
|
|
|
|
|
}
|
2008-10-19 22:44:21 +00:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
/** \returns the solution x of \f$ A x = b \f$ using the current decomposition of A.
|
|
|
|
|
*
|
|
|
|
|
* \sa compute()
|
|
|
|
|
*/
|
2010-10-04 20:56:54 +02:00
|
|
|
template<typename Rhs>
|
2011-09-24 14:19:39 +02:00
|
|
|
inline const internal::solve_retval<UmfPackLU, Rhs> solve(const MatrixBase<Rhs>& b) const
|
2010-10-04 20:56:54 +02:00
|
|
|
{
|
2011-09-24 14:19:39 +02:00
|
|
|
eigen_assert(m_isInitialized && "UmfPAckLU is not initialized.");
|
|
|
|
|
eigen_assert(rows()==b.rows()
|
|
|
|
|
&& "UmfPAckLU::solve(): invalid number of rows of the right hand side matrix b");
|
|
|
|
|
return internal::solve_retval<UmfPackLU, Rhs>(*this, b.derived());
|
2010-10-04 20:56:54 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
/** \returns the solution x of \f$ A x = b \f$ using the current decomposition of A.
|
|
|
|
|
*
|
|
|
|
|
* \sa compute()
|
|
|
|
|
*/
|
|
|
|
|
// template<typename Rhs>
|
|
|
|
|
// inline const internal::sparse_solve_retval<UmfPAckLU, Rhs> solve(const SparseMatrixBase<Rhs>& b) const
|
|
|
|
|
// {
|
|
|
|
|
// eigen_assert(m_isInitialized && "UmfPAckLU is not initialized.");
|
|
|
|
|
// eigen_assert(rows()==b.rows()
|
|
|
|
|
// && "UmfPAckLU::solve(): invalid number of rows of the right hand side matrix b");
|
|
|
|
|
// return internal::sparse_solve_retval<UmfPAckLU, Rhs>(*this, b.derived());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/** Performs a symbolic decomposition on the sparcity of \a matrix.
|
|
|
|
|
*
|
|
|
|
|
* This function is particularly useful when solving for several problems having the same structure.
|
|
|
|
|
*
|
|
|
|
|
* \sa factorize()
|
|
|
|
|
*/
|
|
|
|
|
void analyzePattern(const MatrixType& matrix)
|
|
|
|
|
{
|
|
|
|
|
eigen_assert((MatrixType::Flags&RowMajorBit)==0 && "UmfPackLU: Row major matrices are not supported yet");
|
2008-10-19 22:44:21 +00:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
if(m_symbolic)
|
|
|
|
|
umfpack_free_symbolic(&m_symbolic,Scalar());
|
|
|
|
|
if(m_numeric)
|
|
|
|
|
umfpack_free_numeric(&m_numeric,Scalar());
|
2010-10-04 20:56:54 +02:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
int errorCode = 0;
|
2011-12-04 12:19:26 +01:00
|
|
|
errorCode = umfpack_symbolic(matrix.rows(), matrix.cols(), matrix.outerIndexPtr(), matrix.innerIndexPtr(), matrix.valuePtr(),
|
2011-09-24 14:19:39 +02:00
|
|
|
&m_symbolic, 0, 0);
|
|
|
|
|
|
|
|
|
|
m_isInitialized = true;
|
|
|
|
|
m_info = errorCode ? InvalidInput : Success;
|
|
|
|
|
m_analysisIsOk = true;
|
|
|
|
|
m_factorizationIsOk = false;
|
2010-10-04 20:56:54 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
/** Performs a numeric decomposition of \a matrix
|
|
|
|
|
*
|
|
|
|
|
* The given matrix must has the same sparcity than the matrix on which the symbolic decomposition has been performed.
|
|
|
|
|
*
|
|
|
|
|
* \sa analyzePattern()
|
|
|
|
|
*/
|
|
|
|
|
void factorize(const MatrixType& matrix)
|
2010-10-04 20:56:54 +02:00
|
|
|
{
|
2011-09-24 14:19:39 +02:00
|
|
|
eigen_assert(m_analysisIsOk && "UmfPackLU: you must first call analyzePattern()");
|
|
|
|
|
if(m_numeric)
|
|
|
|
|
umfpack_free_numeric(&m_numeric,Scalar());
|
2010-10-04 20:56:54 +02:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
m_matrixRef = &matrix;
|
2008-10-20 17:03:09 +00:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
int errorCode;
|
2011-12-04 12:19:26 +01:00
|
|
|
errorCode = umfpack_numeric(matrix.outerIndexPtr(), matrix.innerIndexPtr(), matrix.valuePtr(),
|
2011-09-24 14:19:39 +02:00
|
|
|
m_symbolic, &m_numeric, 0, 0);
|
2008-10-19 22:44:21 +00:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
m_info = errorCode ? NumericalIssue : Success;
|
|
|
|
|
m_factorizationIsOk = true;
|
|
|
|
|
}
|
2010-10-04 20:56:54 +02:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
|
|
|
|
/** \internal */
|
|
|
|
|
template<typename BDerived,typename XDerived>
|
|
|
|
|
bool _solve(const MatrixBase<BDerived> &b, MatrixBase<XDerived> &x) const;
|
|
|
|
|
#endif
|
2010-10-04 20:56:54 +02:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
Scalar determinant() const;
|
2010-10-04 20:56:54 +02:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
void extractData() const;
|
|
|
|
|
|
|
|
|
|
protected:
|
2010-10-04 20:56:54 +02:00
|
|
|
|
|
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
void init()
|
2011-02-14 15:41:00 +01:00
|
|
|
{
|
2011-09-24 14:19:39 +02:00
|
|
|
m_info = InvalidInput;
|
|
|
|
|
m_isInitialized = false;
|
|
|
|
|
m_numeric = 0;
|
|
|
|
|
m_symbolic = 0;
|
2011-02-14 15:41:00 +01:00
|
|
|
}
|
2008-10-19 22:44:21 +00:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
// cached data to reduce reallocation, etc.
|
|
|
|
|
mutable LUMatrixType m_l;
|
|
|
|
|
mutable LUMatrixType m_u;
|
|
|
|
|
mutable IntColVectorType m_p;
|
|
|
|
|
mutable IntRowVectorType m_q;
|
2008-10-19 22:44:21 +00:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
const MatrixType* m_matrixRef;
|
|
|
|
|
void* m_numeric;
|
|
|
|
|
void* m_symbolic;
|
2008-10-20 17:03:09 +00:00
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
mutable ComputationInfo m_info;
|
|
|
|
|
bool m_isInitialized;
|
|
|
|
|
int m_factorizationIsOk;
|
|
|
|
|
int m_analysisIsOk;
|
|
|
|
|
mutable bool m_extractedDataAreDirty;
|
|
|
|
|
};
|
2008-10-19 22:44:21 +00:00
|
|
|
|
|
|
|
|
|
2008-10-20 17:03:09 +00:00
|
|
|
template<typename MatrixType>
|
2011-09-24 14:19:39 +02:00
|
|
|
void UmfPackLU<MatrixType>::extractData() const
|
2008-10-20 17:03:09 +00:00
|
|
|
{
|
|
|
|
|
if (m_extractedDataAreDirty)
|
|
|
|
|
{
|
|
|
|
|
// get size of the data
|
|
|
|
|
int lnz, unz, rows, cols, nz_udiag;
|
|
|
|
|
umfpack_get_lunz(&lnz, &unz, &rows, &cols, &nz_udiag, m_numeric, Scalar());
|
|
|
|
|
|
|
|
|
|
// allocate data
|
2011-07-21 11:19:36 +02:00
|
|
|
m_l.resize(rows,(std::min)(rows,cols));
|
2008-10-20 17:03:09 +00:00
|
|
|
m_l.resizeNonZeros(lnz);
|
2011-09-24 14:19:39 +02:00
|
|
|
|
2011-07-21 11:19:36 +02:00
|
|
|
m_u.resize((std::min)(rows,cols),cols);
|
2008-10-20 17:03:09 +00:00
|
|
|
m_u.resizeNonZeros(unz);
|
|
|
|
|
|
|
|
|
|
m_p.resize(rows);
|
|
|
|
|
m_q.resize(cols);
|
|
|
|
|
|
|
|
|
|
// extract
|
2011-12-04 12:19:26 +01:00
|
|
|
umfpack_get_numeric(m_l.outerIndexPtr(), m_l.innerIndexPtr(), m_l.valuePtr(),
|
|
|
|
|
m_u.outerIndexPtr(), m_u.innerIndexPtr(), m_u.valuePtr(),
|
2008-10-20 17:03:09 +00:00
|
|
|
m_p.data(), m_q.data(), 0, 0, 0, m_numeric);
|
2011-09-24 14:19:39 +02:00
|
|
|
|
2008-10-20 17:03:09 +00:00
|
|
|
m_extractedDataAreDirty = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename MatrixType>
|
2011-09-24 14:19:39 +02:00
|
|
|
typename UmfPackLU<MatrixType>::Scalar UmfPackLU<MatrixType>::determinant() const
|
2008-10-20 17:03:09 +00:00
|
|
|
{
|
|
|
|
|
Scalar det;
|
|
|
|
|
umfpack_get_determinant(&det, 0, m_numeric, 0);
|
|
|
|
|
return det;
|
|
|
|
|
}
|
2008-10-19 22:44:21 +00:00
|
|
|
|
|
|
|
|
template<typename MatrixType>
|
|
|
|
|
template<typename BDerived,typename XDerived>
|
2011-09-24 14:19:39 +02:00
|
|
|
bool UmfPackLU<MatrixType>::_solve(const MatrixBase<BDerived> &b, MatrixBase<XDerived> &x) const
|
2008-10-19 22:44:21 +00:00
|
|
|
{
|
|
|
|
|
const int rhsCols = b.cols();
|
2011-09-24 14:19:39 +02:00
|
|
|
eigen_assert((BDerived::Flags&RowMajorBit)==0 && "UmfPackLU backend does not support non col-major rhs yet");
|
|
|
|
|
eigen_assert((XDerived::Flags&RowMajorBit)==0 && "UmfPackLU backend does not support non col-major result yet");
|
2008-10-19 22:44:21 +00:00
|
|
|
|
|
|
|
|
int errorCode;
|
|
|
|
|
for (int j=0; j<rhsCols; ++j)
|
|
|
|
|
{
|
2008-10-20 00:39:11 +00:00
|
|
|
errorCode = umfpack_solve(UMFPACK_A,
|
2011-12-04 12:19:26 +01:00
|
|
|
m_matrixRef->outerIndexPtr(), m_matrixRef->innerIndexPtr(), m_matrixRef->valuePtr(),
|
2011-09-24 14:19:39 +02:00
|
|
|
&x.col(j).coeffRef(0), &b.const_cast_derived().col(j).coeffRef(0), m_numeric, 0, 0);
|
2008-10-19 22:44:21 +00:00
|
|
|
if (errorCode!=0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-24 14:19:39 +02:00
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
template<typename _MatrixType, typename Rhs>
|
|
|
|
|
struct solve_retval<UmfPackLU<_MatrixType>, Rhs>
|
|
|
|
|
: solve_retval_base<UmfPackLU<_MatrixType>, Rhs>
|
|
|
|
|
{
|
|
|
|
|
typedef UmfPackLU<_MatrixType> Dec;
|
|
|
|
|
EIGEN_MAKE_SOLVE_HELPERS(Dec,Rhs)
|
|
|
|
|
|
|
|
|
|
template<typename Dest> void evalTo(Dest& dst) const
|
|
|
|
|
{
|
|
|
|
|
dec()._solve(rhs(),dst);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename _MatrixType, typename Rhs>
|
|
|
|
|
struct sparse_solve_retval<UmfPackLU<_MatrixType>, Rhs>
|
|
|
|
|
: sparse_solve_retval_base<UmfPackLU<_MatrixType>, Rhs>
|
|
|
|
|
{
|
|
|
|
|
typedef UmfPackLU<_MatrixType> Dec;
|
|
|
|
|
EIGEN_MAKE_SPARSE_SOLVE_HELPERS(Dec,Rhs)
|
|
|
|
|
|
|
|
|
|
template<typename Dest> void evalTo(Dest& dst) const
|
|
|
|
|
{
|
|
|
|
|
dec()._solve(rhs(),dst);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-19 22:44:21 +00:00
|
|
|
#endif // EIGEN_UMFPACKSUPPORT_H
|