10 #ifndef EIGEN_UMFPACKSUPPORT_H
11 #define EIGEN_UMFPACKSUPPORT_H
15 #ifndef SuiteSparse_long
17 #define SuiteSparse_long UF_long
19 #error neither SuiteSparse_long nor UF_long are defined
33 inline void umfpack_defaults(
double control[UMFPACK_CONTROL],
double,
int) { umfpack_di_defaults(control); }
35 inline void umfpack_defaults(
double control[UMFPACK_CONTROL], std::complex<double>,
int) {
36 umfpack_zi_defaults(control);
39 inline void umfpack_defaults(
double control[UMFPACK_CONTROL],
double, SuiteSparse_long) {
40 umfpack_dl_defaults(control);
43 inline void umfpack_defaults(
double control[UMFPACK_CONTROL], std::complex<double>, SuiteSparse_long) {
44 umfpack_zl_defaults(control);
49 umfpack_di_report_info(control,
info);
53 umfpack_zi_report_info(control,
info);
57 umfpack_dl_report_info(control,
info);
62 umfpack_zl_report_info(control,
info);
67 umfpack_di_report_status(control, status);
71 umfpack_zi_report_status(control, status);
75 umfpack_dl_report_status(control, status);
78 inline void umfpack_report_status(
double control[UMFPACK_CONTROL],
int status, std::complex<double>, SuiteSparse_long) {
79 umfpack_zl_report_status(control, status);
83 inline void umfpack_report_control(
double control[UMFPACK_CONTROL],
double,
int) { umfpack_di_report_control(control); }
86 umfpack_zi_report_control(control);
90 umfpack_dl_report_control(control);
94 umfpack_zl_report_control(control);
99 umfpack_di_free_numeric(Numeric);
104 umfpack_zi_free_numeric(Numeric);
109 umfpack_dl_free_numeric(Numeric);
114 umfpack_zl_free_numeric(Numeric);
120 umfpack_di_free_symbolic(Symbolic);
125 umfpack_zi_free_symbolic(Symbolic);
130 umfpack_dl_free_symbolic(Symbolic);
135 umfpack_zl_free_symbolic(Symbolic);
140 inline int umfpack_symbolic(
int n_row,
int n_col,
const int Ap[],
const int Ai[],
const double Ax[],
void **Symbolic,
141 const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
142 return umfpack_di_symbolic(n_row, n_col, Ap, Ai, Ax, Symbolic, Control, Info);
145 inline int umfpack_symbolic(
int n_row,
int n_col,
const int Ap[],
const int Ai[],
const std::complex<double> Ax[],
146 void **Symbolic,
const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
147 return umfpack_zi_symbolic(n_row, n_col, Ap, Ai, &
numext::real_ref(Ax[0]), 0, Symbolic, Control, Info);
149 inline SuiteSparse_long
umfpack_symbolic(SuiteSparse_long n_row, SuiteSparse_long n_col,
const SuiteSparse_long Ap[],
150 const SuiteSparse_long Ai[],
const double Ax[],
void **Symbolic,
151 const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
152 return umfpack_dl_symbolic(n_row, n_col, Ap, Ai, Ax, Symbolic, Control, Info);
155 inline SuiteSparse_long
umfpack_symbolic(SuiteSparse_long n_row, SuiteSparse_long n_col,
const SuiteSparse_long Ap[],
156 const SuiteSparse_long Ai[],
const std::complex<double> Ax[],
void **Symbolic,
157 const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
158 return umfpack_zl_symbolic(n_row, n_col, Ap, Ai, &
numext::real_ref(Ax[0]), 0, Symbolic, Control, Info);
162 inline int umfpack_numeric(
const int Ap[],
const int Ai[],
const double Ax[],
void *Symbolic,
void **Numeric,
163 const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
164 return umfpack_di_numeric(Ap, Ai, Ax, Symbolic, Numeric, Control, Info);
167 inline int umfpack_numeric(
const int Ap[],
const int Ai[],
const std::complex<double> Ax[],
void *Symbolic,
168 void **Numeric,
const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
169 return umfpack_zi_numeric(Ap, Ai, &
numext::real_ref(Ax[0]), 0, Symbolic, Numeric, Control, Info);
171 inline SuiteSparse_long
umfpack_numeric(
const SuiteSparse_long Ap[],
const SuiteSparse_long Ai[],
const double Ax[],
172 void *Symbolic,
void **Numeric,
const double Control[UMFPACK_CONTROL],
173 double Info[UMFPACK_INFO]) {
174 return umfpack_dl_numeric(Ap, Ai, Ax, Symbolic, Numeric, Control, Info);
177 inline SuiteSparse_long
umfpack_numeric(
const SuiteSparse_long Ap[],
const SuiteSparse_long Ai[],
178 const std::complex<double> Ax[],
void *Symbolic,
void **Numeric,
179 const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
180 return umfpack_zl_numeric(Ap, Ai, &
numext::real_ref(Ax[0]), 0, Symbolic, Numeric, Control, Info);
184 inline int umfpack_solve(
int sys,
const int Ap[],
const int Ai[],
const double Ax[],
double X[],
const double B[],
185 void *Numeric,
const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
186 return umfpack_di_solve(sys, Ap, Ai, Ax,
X,
B, Numeric, Control, Info);
189 inline int umfpack_solve(
int sys,
const int Ap[],
const int Ai[],
const std::complex<double> Ax[],
190 std::complex<double>
X[],
const std::complex<double>
B[],
void *Numeric,
191 const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
193 0, Numeric, Control, Info);
196 inline SuiteSparse_long
umfpack_solve(
int sys,
const SuiteSparse_long Ap[],
const SuiteSparse_long Ai[],
197 const double Ax[],
double X[],
const double B[],
void *Numeric,
198 const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
199 return umfpack_dl_solve(sys, Ap, Ai, Ax,
X,
B, Numeric, Control, Info);
202 inline SuiteSparse_long
umfpack_solve(
int sys,
const SuiteSparse_long Ap[],
const SuiteSparse_long Ai[],
203 const std::complex<double> Ax[], std::complex<double>
X[],
204 const std::complex<double>
B[],
void *Numeric,
205 const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]) {
207 0, Numeric, Control, Info);
211 inline int umfpack_get_lunz(
int *lnz,
int *unz,
int *n_row,
int *n_col,
int *nz_udiag,
void *Numeric,
double) {
212 return umfpack_di_get_lunz(lnz, unz, n_row, n_col, nz_udiag, Numeric);
215 inline int umfpack_get_lunz(
int *lnz,
int *unz,
int *n_row,
int *n_col,
int *nz_udiag,
void *Numeric,
216 std::complex<double>) {
217 return umfpack_zi_get_lunz(lnz, unz, n_row, n_col, nz_udiag, Numeric);
220 inline SuiteSparse_long
umfpack_get_lunz(SuiteSparse_long *lnz, SuiteSparse_long *unz, SuiteSparse_long *n_row,
221 SuiteSparse_long *n_col, SuiteSparse_long *nz_udiag,
void *Numeric,
double) {
222 return umfpack_dl_get_lunz(lnz, unz, n_row, n_col, nz_udiag, Numeric);
225 inline SuiteSparse_long
umfpack_get_lunz(SuiteSparse_long *lnz, SuiteSparse_long *unz, SuiteSparse_long *n_row,
226 SuiteSparse_long *n_col, SuiteSparse_long *nz_udiag,
void *Numeric,
227 std::complex<double>) {
228 return umfpack_zl_get_lunz(lnz, unz, n_row, n_col, nz_udiag, Numeric);
233 double Dx[],
int *do_recip,
double Rs[],
void *Numeric) {
234 return umfpack_di_get_numeric(Lp, Lj,
Lx, Up, Ui, Ux,
P,
Q,
Dx, do_recip, Rs, Numeric);
238 std::complex<double> Ux[],
int P[],
int Q[], std::complex<double>
Dx[],
int *do_recip,
239 double Rs[],
void *Numeric) {
243 return umfpack_zi_get_numeric(Lp, Lj,
Lx ? &lx0_real : 0, 0, Up, Ui, Ux ? &ux0_real : 0, 0,
P,
Q,
Dx ? &dx0_real : 0,
244 0, do_recip, Rs, Numeric);
247 SuiteSparse_long Up[], SuiteSparse_long Ui[],
double Ux[],
248 SuiteSparse_long
P[], SuiteSparse_long
Q[],
double Dx[],
249 SuiteSparse_long *do_recip,
double Rs[],
void *Numeric) {
250 return umfpack_dl_get_numeric(Lp, Lj,
Lx, Up, Ui, Ux,
P,
Q,
Dx, do_recip, Rs, Numeric);
253 inline SuiteSparse_long
umfpack_get_numeric(SuiteSparse_long Lp[], SuiteSparse_long Lj[], std::complex<double>
Lx[],
254 SuiteSparse_long Up[], SuiteSparse_long Ui[], std::complex<double> Ux[],
255 SuiteSparse_long
P[], SuiteSparse_long
Q[], std::complex<double>
Dx[],
256 SuiteSparse_long *do_recip,
double Rs[],
void *Numeric) {
260 return umfpack_zl_get_numeric(Lp, Lj,
Lx ? &lx0_real : 0, 0, Up, Ui, Ux ? &ux0_real : 0, 0,
P,
Q,
Dx ? &dx0_real : 0,
261 0, do_recip, Rs, Numeric);
266 return umfpack_di_get_determinant(Mx, Ex, NumericHandle, User_Info);
270 double User_Info[UMFPACK_INFO],
int) {
272 return umfpack_zi_get_determinant(&mx_real, 0, Ex, NumericHandle, User_Info);
276 double User_Info[UMFPACK_INFO], SuiteSparse_long) {
277 return umfpack_dl_get_determinant(Mx, Ex, NumericHandle, User_Info);
281 double User_Info[UMFPACK_INFO], SuiteSparse_long) {
283 return umfpack_zl_get_determinant(&mx_real, 0, Ex, NumericHandle, User_Info);
301 template <
typename MatrixType_>
327 template <
typename InputMatrixType>
375 template <
typename InputMatrixType>
390 template <
typename InputMatrixType>
432 template <
typename InputMatrixType>
468 template <
typename BDerived,
typename XDerived>
488 internal::convert_index<StorageIndex>(
mp_matrix.cols()),
508 template <
typename MatrixDerived>
546 template <
typename MatrixType>
548 if (m_extractedDataAreDirty) {
555 m_l.resizeNonZeros(lnz);
558 m_u.resizeNonZeros(unz);
564 umfpack_get_numeric(m_l.outerIndexPtr(), m_l.innerIndexPtr(), m_l.valuePtr(), m_u.outerIndexPtr(),
565 m_u.innerIndexPtr(), m_u.valuePtr(), m_p.data(), m_q.data(), 0, 0, 0, m_numeric);
567 m_extractedDataAreDirty =
false;
571 template <
typename MatrixType>
578 template <
typename MatrixType>
579 template <
typename BDerived,
typename XDerived>
582 eigen_assert((BDerived::Flags &
RowMajorBit) == 0 &&
"UmfPackLU backend does not support non col-major rhs yet");
583 eigen_assert((XDerived::Flags &
RowMajorBit) == 0 &&
"UmfPackLU backend does not support non col-major result yet");
584 eigen_assert(
b.derived().data() !=
x.derived().data() &&
" Umfpack does not support inplace solve");
588 if (
x.innerStride() != 1) {
590 x_ptr = x_tmp.
data();
592 for (
int j = 0;
j < rhsCols; ++
j) {
593 if (
x.innerStride() == 1) x_ptr = &
x.col(
j).coeffRef(0);
595 umfpack_solve(UMFPACK_A, mp_matrix.outerIndexPtr(), mp_matrix.innerIndexPtr(), mp_matrix.valuePtr(), x_ptr,
596 &
b.const_cast_derived().col(
j).coeffRef(0), m_numeric, m_control.data(), m_umfpackInfo.data());
597 if (
x.innerStride() != 1)
x.col(
j) = x_tmp;
598 if (errorCode != 0)
return false;
MatrixXf Q
Definition: HouseholderQR_householderQ.cpp:1
#define eigen_assert(x)
Definition: Macros.h:910
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar * b
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
constexpr EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: PlainObjectBase.h:273
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:294
A base class for sparse solvers.
Definition: SparseSolverBase.h:67
void _solve_impl(const SparseMatrixBase< Rhs > &b, SparseMatrixBase< Dest > &dest) const
Definition: SparseSolverBase.h:104
bool m_isInitialized
Definition: SparseSolverBase.h:110
A sparse LU factorization and solver based on UmfPack.
Definition: UmfPackSupport.h:302
Index cols() const
Definition: UmfPackSupport.h:339
void analyzePattern_impl()
Definition: UmfPackSupport.h:486
UmfPackLU(const UmfPackLU &)
Definition: UmfPackSupport.h:543
const LUMatrixType & matrixL() const
Definition: UmfPackSupport.h:351
Index rows() const
Definition: UmfPackSupport.h:338
Array< double, UMFPACK_CONTROL, 1 > UmfpackControl
Definition: UmfPackSupport.h:322
UmfpackMatrixRef mp_matrix
Definition: UmfPackSupport.h:532
Matrix< int, MatrixType::RowsAtCompileTime, 1 > IntColVectorType
Definition: UmfPackSupport.h:315
int m_analysisIsOk
Definition: UmfPackSupport.h:539
void printUmfpackControl()
Definition: UmfPackSupport.h:446
const IntColVectorType & permutationP() const
Definition: UmfPackSupport.h:361
MatrixType::RealScalar RealScalar
Definition: UmfPackSupport.h:311
bool m_extractedDataAreDirty
Definition: UmfPackSupport.h:540
void compute(const InputMatrixType &matrix)
Definition: UmfPackSupport.h:376
UmfPackLU(const InputMatrixType &matrix)
Definition: UmfPackSupport.h:328
UmfpackMatrixType m_dummy
Definition: UmfPackSupport.h:531
UmfpackInfo m_umfpackInfo
Definition: UmfPackSupport.h:525
Scalar determinant() const
Definition: UmfPackSupport.h:572
const IntRowVectorType & permutationQ() const
Definition: UmfPackSupport.h:366
void factorize(const InputMatrixType &matrix)
Definition: UmfPackSupport.h:433
UmfpackControl & umfpackControl()
Definition: UmfPackSupport.h:424
void factorize_impl()
Definition: UmfPackSupport.h:499
ComputationInfo m_info
Definition: UmfPackSupport.h:537
MatrixType::Scalar Scalar
Definition: UmfPackSupport.h:310
void grab(const UmfpackMatrixRef &A)
Definition: UmfPackSupport.h:514
SparseSolverBase< UmfPackLU< MatrixType_ > > Base
Definition: UmfPackSupport.h:304
StorageIndex m_fact_errorCode
Definition: UmfPackSupport.h:523
void init()
Definition: UmfPackSupport.h:476
IntColVectorType m_p
Definition: UmfPackSupport.h:528
void extractData() const
Definition: UmfPackSupport.h:547
SparseMatrix< Scalar > LUMatrixType
Definition: UmfPackSupport.h:316
int umfpackFactorizeReturncode() const
Definition: UmfPackSupport.h:405
bool _solve_impl(const MatrixBase< BDerived > &b, MatrixBase< XDerived > &x) const
Definition: UmfPackSupport.h:580
int m_factorizationIsOk
Definition: UmfPackSupport.h:538
Matrix< Scalar, Dynamic, 1 > Vector
Definition: UmfPackSupport.h:313
Matrix< int, 1, MatrixType::ColsAtCompileTime > IntRowVectorType
Definition: UmfPackSupport.h:314
MatrixType_ MatrixType
Definition: UmfPackSupport.h:309
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: UmfPackSupport.h:346
Array< double, UMFPACK_INFO, 1 > UmfpackInfo
Definition: UmfPackSupport.h:323
UmfpackControl m_control
Definition: UmfPackSupport.h:524
void grab(const EigenBase< MatrixDerived > &A)
Definition: UmfPackSupport.h:509
void * m_numeric
Definition: UmfPackSupport.h:534
void printUmfpackInfo()
Definition: UmfPackSupport.h:452
const LUMatrixType & matrixU() const
Definition: UmfPackSupport.h:356
@ ColsAtCompileTime
Definition: UmfPackSupport.h:319
@ MaxColsAtCompileTime
Definition: UmfPackSupport.h:319
Ref< const UmfpackMatrixType, StandardCompressedFormat > UmfpackMatrixRef
Definition: UmfPackSupport.h:318
LUMatrixType m_l
Definition: UmfPackSupport.h:522
void analyzePattern(const InputMatrixType &matrix)
Definition: UmfPackSupport.h:391
const UmfpackControl & umfpackControl() const
Definition: UmfPackSupport.h:416
IntRowVectorType m_q
Definition: UmfPackSupport.h:529
~UmfPackLU()
Definition: UmfPackSupport.h:333
SparseMatrix< Scalar, ColMajor, StorageIndex > UmfpackMatrixType
Definition: UmfPackSupport.h:317
UmfPackLU()
Definition: UmfPackSupport.h:325
LUMatrixType m_u
Definition: UmfPackSupport.h:527
MatrixType::StorageIndex StorageIndex
Definition: UmfPackSupport.h:312
void printUmfpackStatus()
Definition: UmfPackSupport.h:462
void * m_symbolic
Definition: UmfPackSupport.h:535
Definition: matrices.h:74
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
#define min(a, b)
Definition: datatypes.h:22
ComputationInfo
Definition: Constants.h:438
@ NumericalIssue
Definition: Constants.h:442
@ InvalidInput
Definition: Constants.h:447
@ Success
Definition: Constants.h:440
const unsigned int RowMajorBit
Definition: Constants.h:70
#define X
Definition: icosphere.cpp:20
int info
Definition: level2_cplx_impl.h:39
EIGEN_DEVICE_FUNC T * construct_at(T *p, Args &&... args)
Definition: Memory.h:1321
EIGEN_DEVICE_FUNC void destroy_at(T *p)
Definition: Memory.h:1335
EIGEN_DEVICE_FUNC internal::add_const_on_value_type_t< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar)> real_ref(const Scalar &x)
Definition: MathFunctions.h:1051
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
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)
Definition: UmfPackSupport.h:232
int umfpack_get_determinant(double *Mx, double *Ex, void *NumericHandle, double User_Info[UMFPACK_INFO], int)
Definition: UmfPackSupport.h:265
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])
Definition: UmfPackSupport.h:184
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
void umfpack_report_control(double control[UMFPACK_CONTROL], double, int)
Definition: UmfPackSupport.h:83
void umfpack_free_numeric(void **Numeric, double, int)
Definition: UmfPackSupport.h:98
void umfpack_defaults(double control[UMFPACK_CONTROL], double, int)
Definition: UmfPackSupport.h:33
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])
Definition: UmfPackSupport.h:140
void umfpack_report_status(double control[UMFPACK_CONTROL], int status, double, int)
Definition: UmfPackSupport.h:66
void umfpack_report_info(double control[UMFPACK_CONTROL], double info[UMFPACK_INFO], double, int)
Definition: UmfPackSupport.h:48
void umfpack_free_symbolic(void **Symbolic, double, int)
Definition: UmfPackSupport.h:119
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])
Definition: UmfPackSupport.h:162
int umfpack_get_lunz(int *lnz, int *unz, int *n_row, int *n_col, int *nz_udiag, void *Numeric, double)
Definition: UmfPackSupport.h:211
double Lx
Length of domain in x direction.
Definition: periodic_load.cc:55
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
Vector< double > Dx(2, 0.0)
Increments in bin.
list x
Definition: plotDoE.py:28
Definition: EigenBase.h:33
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2