10 #ifndef EIGEN_SUPERLUSUPPORT_H
11 #define EIGEN_SUPERLUSUPPORT_H
17 #if defined(SUPERLU_MAJOR_VERSION) && (SUPERLU_MAJOR_VERSION >= 5)
18 #define DECL_GSSVX(PREFIX,FLOATTYPE,KEYTYPE) \
20 extern void PREFIX##gssvx(superlu_options_t *, SuperMatrix *, int *, int *, int *, \
21 char *, FLOATTYPE *, FLOATTYPE *, SuperMatrix *, SuperMatrix *, \
22 void *, int, SuperMatrix *, SuperMatrix *, \
23 FLOATTYPE *, FLOATTYPE *, FLOATTYPE *, FLOATTYPE *, \
24 GlobalLU_t *, mem_usage_t *, SuperLUStat_t *, int *); \
26 inline float SuperLU_gssvx(superlu_options_t *options, SuperMatrix *A, \
27 int *perm_c, int *perm_r, int *etree, char *equed, \
28 FLOATTYPE *R, FLOATTYPE *C, SuperMatrix *L, \
29 SuperMatrix *U, void *work, int lwork, \
30 SuperMatrix *B, SuperMatrix *X, \
31 FLOATTYPE *recip_pivot_growth, \
32 FLOATTYPE *rcond, FLOATTYPE *ferr, FLOATTYPE *berr, \
33 SuperLUStat_t *stats, int *info, KEYTYPE) { \
34 mem_usage_t mem_usage; \
36 PREFIX##gssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, \
37 U, work, lwork, B, X, recip_pivot_growth, rcond, \
38 ferr, berr, &gLU, &mem_usage, stats, info); \
39 return mem_usage.for_lu;
\
42 #define DECL_GSSVX(PREFIX,FLOATTYPE,KEYTYPE) \
44 extern void PREFIX##gssvx(superlu_options_t *, SuperMatrix *, int *, int *, int *, \
45 char *, FLOATTYPE *, FLOATTYPE *, SuperMatrix *, SuperMatrix *, \
46 void *, int, SuperMatrix *, SuperMatrix *, \
47 FLOATTYPE *, FLOATTYPE *, FLOATTYPE *, FLOATTYPE *, \
48 mem_usage_t *, SuperLUStat_t *, int *); \
50 inline float SuperLU_gssvx(superlu_options_t *options, SuperMatrix *A, \
51 int *perm_c, int *perm_r, int *etree, char *equed, \
52 FLOATTYPE *R, FLOATTYPE *C, SuperMatrix *L, \
53 SuperMatrix *U, void *work, int lwork, \
54 SuperMatrix *B, SuperMatrix *X, \
55 FLOATTYPE *recip_pivot_growth, \
56 FLOATTYPE *rcond, FLOATTYPE *ferr, FLOATTYPE *berr, \
57 SuperLUStat_t *stats, int *info, KEYTYPE) { \
58 mem_usage_t mem_usage; \
59 PREFIX##gssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, \
60 U, work, lwork, B, X, recip_pivot_growth, rcond, \
61 ferr, berr, &mem_usage, stats, info); \
62 return mem_usage.for_lu;
\
72 #define EIGEN_SUPERLU_HAS_ILU
75 #ifdef EIGEN_SUPERLU_HAS_ILU
78 #define DECL_GSISX(PREFIX,FLOATTYPE,KEYTYPE) \
80 extern void PREFIX##gsisx(superlu_options_t *, SuperMatrix *, int *, int *, int *, \
81 char *, FLOATTYPE *, FLOATTYPE *, SuperMatrix *, SuperMatrix *, \
82 void *, int, SuperMatrix *, SuperMatrix *, FLOATTYPE *, FLOATTYPE *, \
83 mem_usage_t *, SuperLUStat_t *, int *); \
85 inline float SuperLU_gsisx(superlu_options_t *options, SuperMatrix *A, \
86 int *perm_c, int *perm_r, int *etree, char *equed, \
87 FLOATTYPE *R, FLOATTYPE *C, SuperMatrix *L, \
88 SuperMatrix *U, void *work, int lwork, \
89 SuperMatrix *B, SuperMatrix *X, \
90 FLOATTYPE *recip_pivot_growth, \
92 SuperLUStat_t *stats, int *info, KEYTYPE) { \
93 mem_usage_t mem_usage; \
94 PREFIX##gsisx(options, A, perm_c, perm_r, etree, equed, R, C, L, \
95 U, work, lwork, B, X, recip_pivot_growth, rcond, \
96 &mem_usage, stats, info); \
97 return mem_usage.for_lu;
\
100 DECL_GSISX(s,
float,
float)
101 DECL_GSISX(
c,
float,std::complex<float>)
102 DECL_GSISX(d,
double,
double)
103 DECL_GSISX(z,
double,std::complex<double>)
107 template<
typename MatrixType>
133 SuperMatrix::operator=(
static_cast<const SuperMatrix&
>(other));
150 if (t==SLU_NC || t==SLU_NR || t==SLU_DN)
159 template<
typename Scalar>
162 if (internal::is_same<Scalar,float>::value)
164 else if (internal::is_same<Scalar,double>::value)
166 else if (internal::is_same<Scalar,std::complex<float> >::value)
168 else if (internal::is_same<Scalar,std::complex<double> >::value)
172 eigen_assert(
false &&
"Scalar type not supported by SuperLU");
176 template<
typename MatrixType>
182 res.setStorageType(SLU_DN);
186 res.nrow = internal::convert_index<int>(
mat.rows());
187 res.ncol = internal::convert_index<int>(
mat.cols());
189 res.storage.lda = internal::convert_index<int>(MatrixType::IsVectorAtCompileTime ?
mat.size() :
mat.outerStride());
190 res.storage.values = (
void*)(
mat.data());
194 template<
typename MatrixType>
201 res.setStorageType(SLU_NR);
202 res.nrow = internal::convert_index<int>(
mat.cols());
203 res.ncol = internal::convert_index<int>(
mat.rows());
207 res.setStorageType(SLU_NC);
208 res.nrow = internal::convert_index<int>(
mat.rows());
209 res.ncol = internal::convert_index<int>(
mat.cols());
214 res.storage.nnz = internal::convert_index<int>(
mat.nonZeros());
215 res.storage.values =
mat.valuePtr();
216 res.storage.innerInd =
mat.innerIndexPtr();
217 res.storage.outerInd =
mat.outerIndexPtr();
222 if (
int(MatrixType::Flags) & int(
Upper))
224 if (
int(MatrixType::Flags) & int(
Lower))
227 eigen_assert(((
int(MatrixType::Flags) &
int(
SelfAdjoint))==0) &&
"SelfAdjoint matrix shape not supported by SuperLU");
233 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MRows,
int MCols>
240 res.setStorageType(SLU_DN);
241 res.setScalarType<Scalar>();
247 res.storage.lda =
mat.outerStride();
248 res.storage.values =
mat.data();
252 template<
typename Derived>
260 res.setStorageType(SLU_NR);
266 res.setStorageType(SLU_NC);
273 res.storage.nnz =
mat.nonZeros();
274 res.storage.values =
mat.valuePtr();
275 res.storage.innerInd =
mat.innerIndexPtr();
276 res.storage.outerInd =
mat.outerIndexPtr();
281 if (MatrixType::Flags &
Upper)
283 if (MatrixType::Flags &
Lower)
292 template<
typename MatrixType>
299 template<
typename Scalar,
int Flags,
typename Index>
318 template<
typename MatrixType_,
typename Derived>
369 derived().analyzePattern(matrix);
387 template<
typename Stream>
435 Destroy_SuperNode_Matrix(&
m_sluL);
437 Destroy_CompCol_Matrix(&
m_sluU);
489 template<
typename MatrixType_>
506 using Base::_solve_impl;
542 template<
typename Rhs,
typename Dest>
614 template<
typename MatrixType>
617 eigen_assert(m_analysisIsOk &&
"You must first call analyzePattern()");
624 this->initFactorization(
a);
626 m_sluOptions.ColPerm = COLAMD;
631 StatInit(&m_sluStat);
632 SuperLU_gssvx(&m_sluOptions, &m_sluA, m_q.data(), m_p.data(), &m_sluEtree[0],
633 &m_sluEqued, &m_sluRscale[0], &m_sluCscale[0],
637 &recip_pivot_growth, &rcond,
639 &m_sluStat, &info,
Scalar());
640 StatFree(&m_sluStat);
642 m_extractedDataAreDirty =
true;
646 m_factorizationIsOk =
true;
649 template<
typename MatrixType>
650 template<
typename Rhs,
typename Dest>
653 eigen_assert(m_factorizationIsOk &&
"The decomposition is not in a valid state for solving, you must first call either compute() or analyzePattern()/factorize()");
655 const Index rhsCols =
b.cols();
658 m_sluOptions.Trans = NOTRANS;
659 m_sluOptions.Fact = FACTORED;
660 m_sluOptions.IterRefine = NOREFINE;
663 m_sluFerr.resize(rhsCols);
664 m_sluBerr.resize(rhsCols);
672 typename Rhs::PlainObject b_cpy;
679 StatInit(&m_sluStat);
682 SuperLU_gssvx(&m_sluOptions, &m_sluA,
683 m_q.data(), m_p.data(),
684 &m_sluEtree[0], &m_sluEqued,
685 &m_sluRscale[0], &m_sluCscale[0],
689 &recip_pivot_growth, &rcond,
690 &m_sluFerr[0], &m_sluBerr[0],
691 &m_sluStat, &info,
Scalar());
692 StatFree(&m_sluStat);
694 if(
x.derived().data() != x_ref.data())
707 template<
typename MatrixType,
typename Derived>
710 eigen_assert(m_factorizationIsOk &&
"The decomposition is not in a valid state for extracting factors, you must first call either compute() or analyzePattern()/factorize()");
711 if (m_extractedDataAreDirty)
714 int fsupc, istart, nsupr;
715 int lastl = 0, lastu = 0;
716 SCformat *Lstore =
static_cast<SCformat*
>(m_sluL.Store);
717 NCformat *Ustore =
static_cast<NCformat*
>(m_sluU.Store);
722 m_l.resizeNonZeros(Lstore->nnz);
724 m_u.resizeNonZeros(Ustore->nnz);
726 int* Lcol = m_l.outerIndexPtr();
727 int* Lrow = m_l.innerIndexPtr();
728 Scalar* Lval = m_l.valuePtr();
730 int* Ucol = m_u.outerIndexPtr();
731 int* Urow = m_u.innerIndexPtr();
732 Scalar* Uval = m_u.valuePtr();
738 for (
int k = 0; k <= Lstore->nsuper; ++k)
740 fsupc = L_FST_SUPC(k);
741 istart = L_SUB_START(fsupc);
742 nsupr = L_SUB_START(fsupc+1) - istart;
746 for (
int j = fsupc;
j < L_FST_SUPC(k+1); ++
j)
748 SNptr = &((
Scalar*)Lstore->nzval)[L_NZ_START(
j)];
751 for (
int i = U_NZ_START(
j);
i < U_NZ_START(
j+1); ++
i)
753 Uval[lastu] = ((
Scalar*)Ustore->nzval)[
i];
755 if (Uval[lastu] != 0.0)
756 Urow[lastu++] = U_SUB(
i);
758 for (
int i = 0;
i < upper; ++
i)
761 Uval[lastu] = SNptr[
i];
763 if (Uval[lastu] != 0.0)
764 Urow[lastu++] = L_SUB(istart+
i);
770 Lrow[lastl++] = L_SUB(istart + upper - 1);
771 for (
int i = upper;
i < nsupr; ++
i)
773 Lval[lastl] = SNptr[
i];
775 if (Lval[lastl] != 0.0)
776 Lrow[lastl++] = L_SUB(istart+
i);
786 m_l.resizeNonZeros(lastl);
787 m_u.resizeNonZeros(lastu);
789 m_extractedDataAreDirty =
false;
793 template<
typename MatrixType>
796 eigen_assert(m_factorizationIsOk &&
"The decomposition is not in a valid state for computing the determinant, you must first call either compute() or analyzePattern()/factorize()");
798 if (m_extractedDataAreDirty)
802 for (
int j=0;
j<m_u.cols(); ++
j)
804 if (m_u.outerIndexPtr()[
j+1]-m_u.outerIndexPtr()[
j] > 0)
806 int lastId = m_u.outerIndexPtr()[
j+1]-1;
808 if (m_u.innerIndexPtr()[lastId]==
j)
809 det *= m_u.valuePtr()[lastId];
815 return det/m_sluRscale.prod()/m_sluCscale.prod();
820 #ifdef EIGEN_PARSED_BY_DOXYGEN
821 #define EIGEN_SUPERLU_HAS_ILU
824 #ifdef EIGEN_SUPERLU_HAS_ILU
842 template<
typename MatrixType_>
852 using Base::_solve_impl;
885 #ifndef EIGEN_PARSED_BY_DOXYGEN
887 template<
typename Rhs,
typename Dest>
941 template<
typename MatrixType>
944 eigen_assert(m_analysisIsOk &&
"You must first call analyzePattern()");
951 this->initFactorization(
a);
956 StatInit(&m_sluStat);
957 SuperLU_gsisx(&m_sluOptions, &m_sluA, m_q.data(), m_p.data(), &m_sluEtree[0],
958 &m_sluEqued, &m_sluRscale[0], &m_sluCscale[0],
962 &recip_pivot_growth, &rcond,
963 &m_sluStat, &info,
Scalar());
964 StatFree(&m_sluStat);
968 m_factorizationIsOk =
true;
971 #ifndef EIGEN_PARSED_BY_DOXYGEN
972 template<
typename MatrixType>
973 template<
typename Rhs,
typename Dest>
976 eigen_assert(m_factorizationIsOk &&
"The decomposition is not in a valid state for solving, you must first call either compute() or analyzePattern()/factorize()");
978 const int rhsCols =
b.cols();
981 m_sluOptions.Trans = NOTRANS;
982 m_sluOptions.Fact = FACTORED;
983 m_sluOptions.IterRefine = NOREFINE;
985 m_sluFerr.resize(rhsCols);
986 m_sluBerr.resize(rhsCols);
994 typename Rhs::PlainObject b_cpy;
1002 RealScalar recip_pivot_growth, rcond;
1004 StatInit(&m_sluStat);
1005 SuperLU_gsisx(&m_sluOptions, &m_sluA,
1006 m_q.data(), m_p.data(),
1007 &m_sluEtree[0], &m_sluEqued,
1008 &m_sluRscale[0], &m_sluCscale[0],
1012 &recip_pivot_growth, &rcond,
1013 &m_sluStat, &info, Scalar());
1014 StatFree(&m_sluStat);
1016 if(
x.derived().data() != x_ref.data())
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define DECL_GSSVX(PREFIX, FLOATTYPE, KEYTYPE)
Matrix< float, 1, Dynamic > MatrixType
NumTraits< Scalar >::Real RealScalar
internal::traits< Derived >::StorageIndex StorageIndex
The type used to store indices.
internal::traits< Derived >::Scalar Scalar
A matrix or vector expression mapping an existing array of data.
Base class for all dense matrices, vectors, and expressions.
The matrix class, also used for vectors and row-vectors.
constexpr void resize(Index rows, Index cols)
A matrix or vector expression mapping an existing expression.
Base class of any sparse matrices or sparse expressions.
A versatible sparse matrix representation.
A base class for sparse solvers.
A sparse direct incomplete LU factorization and solver based on the SuperLU library.
void analyzePattern(const MatrixType &matrix)
Base::RealScalar RealScalar
void factorize(const MatrixType &matrix)
SuperLUBase< MatrixType_, SuperILU > Base
SuperILU(const MatrixType &matrix)
superlu_options_t m_sluOptions
The base class for the direct and incomplete LU factorization of SuperLU.
std::vector< int > m_sluEtree
Matrix< RealScalar, Dynamic, 1 > m_sluRscale
void compute(const MatrixType &matrix)
bool m_extractedDataAreDirty
ComputationInfo info() const
Reports whether previous computation was successful.
MatrixType::StorageIndex StorageIndex
MatrixType::RealScalar RealScalar
SparseSolverBase< Derived > Base
Map< PermutationMatrix< Dynamic, Dynamic, int > > PermutationMap
Matrix< RealScalar, Dynamic, 1 > m_sluCscale
MatrixType::Scalar Scalar
superlu_options_t & options()
void dumpMemory(Stream &)
void analyzePattern(const MatrixType &)
Matrix< int, MatrixType::RowsAtCompileTime, 1 > IntColVectorType
Matrix< RealScalar, Dynamic, 1 > m_sluFerr
SuperLUBase(SuperLUBase &)
Matrix< RealScalar, Dynamic, 1 > m_sluBerr
superlu_options_t m_sluOptions
void initFactorization(const MatrixType &a)
Matrix< Scalar, Dynamic, 1 > Vector
SparseMatrix< Scalar > LUMatrixType
Matrix< int, 1, MatrixType::ColsAtCompileTime > IntRowVectorType
A sparse direct LU factorization and solver based on the SuperLU library.
Base::IntRowVectorType IntRowVectorType
void factorize(const MatrixType &matrix)
void analyzePattern(const MatrixType &matrix)
bool m_extractedDataAreDirty
Base::IntColVectorType IntColVectorType
TriangularView< LUMatrixType, Lower|UnitDiag > LMatrixType
const IntColVectorType & permutationP() const
Base::RealScalar RealScalar
TriangularView< LUMatrixType, Upper > UMatrixType
const UMatrixType & matrixU() const
SuperLUBase< MatrixType_, SuperLU > Base
const LMatrixType & matrixL() const
Base::LUMatrixType LUMatrixType
superlu_options_t m_sluOptions
Scalar determinant() const
const IntRowVectorType & permutationQ() const
SuperLU(const MatrixType &matrix)
Base::StorageIndex StorageIndex
Base::PermutationMap PermutationMap
void _solve_impl(const MatrixBase< Rhs > &b, MatrixBase< Dest > &dest) const
Expression of a triangular part in a matrix.
const unsigned int RowMajorBit
SluMatrix asSluMatrix(MatrixType &mat)
Map< SparseMatrix< Scalar, Flags, Index > > map_superlu(SluMatrix &sluMat)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
static void run(MatrixType &mat, SluMatrix &res)
Matrix< Scalar, Rows, Cols, Options, MRows, MCols > MatrixType
static void run(MatrixType &mat, SluMatrix &res)
SluMatrix & operator=(const SluMatrix &other)
SluMatrix(const SluMatrix &other)
static SluMatrix Map(SparseMatrixBase< MatrixType > &a_mat)
void setStorageType(Stype_t t)
static SluMatrix Map(MatrixBase< MatrixType > &_mat)
struct Eigen::SluMatrix::@838 storage