12#ifndef EIGEN_SPARSELU_SUPERNODAL_MATRIX_H
13#define EIGEN_SPARSELU_SUPERNODAL_MATRIX_H
16#include "./InternalHeaderCheck.h"
32template <
typename Scalar_,
typename StorageIndex_>
33class MappedSuperNodalMatrix {
35 using Scalar = Scalar_;
36 using StorageIndex = StorageIndex_;
41 MappedSuperNodalMatrix() {}
42 MappedSuperNodalMatrix(Index m, Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind,
43 IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col) {
44 setInfos(m, n, nzval, nzval_colptr, rowind, rowind_colptr, col_to_sup, sup_to_col);
53 void setInfos(Index m, Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind,
54 IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col) {
57 m_nzval = nzval.
data();
58 m_nzval_colptr = nzval_colptr.
data();
59 m_rowind = rowind.
data();
60 m_rowind_colptr = rowind_colptr.
data();
61 m_nsuper = col_to_sup(n);
62 m_col_to_sup = col_to_sup.
data();
63 m_sup_to_col = sup_to_col.
data();
69 Index
rows()
const {
return m_row; }
74 Index
cols()
const {
return m_col; }
83 const Scalar*
valuePtr()
const {
return m_nzval; }
89 const StorageIndex*
colIndexPtr()
const {
return m_nzval_colptr; }
96 const StorageIndex*
rowIndex()
const {
return m_rowind; }
103 const StorageIndex*
rowIndexPtr()
const {
return m_rowind_colptr; }
110 const StorageIndex*
colToSup()
const {
return m_col_to_sup; }
116 const StorageIndex*
supToCol()
const {
return m_sup_to_col; }
121 Index
nsuper()
const {
return m_nsuper; }
124 template <
typename Dest>
126 template <
bool Conjugate,
typename Dest>
134 StorageIndex* m_nzval_colptr;
135 StorageIndex* m_rowind;
136 StorageIndex* m_rowind_colptr;
137 StorageIndex* m_col_to_sup;
138 StorageIndex* m_sup_to_col;
147template <
typename Scalar,
typename StorageIndex>
150 InnerIterator(
const MappedSuperNodalMatrix& mat, Index outer)
155 m_startidval(m_idval),
164 inline Scalar value()
const {
return m_matrix.valuePtr()[m_idval]; }
166 inline Scalar& valueRef() {
return const_cast<Scalar&
>(m_matrix.valuePtr()[m_idval]); }
168 inline Index index()
const {
return m_matrix.rowIndex()[m_idrow]; }
169 inline Index row()
const {
return index(); }
170 inline Index col()
const {
return m_outer; }
172 inline Index supIndex()
const {
return m_supno; }
174 inline operator bool()
const {
175 return ((m_idval < m_endidval) && (m_idval >= m_startidval) && (m_idrow < m_endidrow));
179 const MappedSuperNodalMatrix& m_matrix;
183 const Index m_startidval;
184 const Index m_endidval;
193template <
typename Scalar,
typename Index_>
194template <
typename Dest>
197 Index n = int(X.rows());
198 Index nrhs = Index(X.cols());
202 for (Index k = 0; k <=
nsuper(); k++) {
206 Index nsupc =
supToCol()[k + 1] - fsupc;
207 Index nrow = nsupr - nsupc;
211 for (Index j = 0; j < nrhs; j++) {
216 X(irow, j) -= X(fsupc, j) * it.value();
227 typename Dest::RowsBlockXpr U = X.derived().
middleRows(fsupc, nsupc);
228 U = A.template triangularView<UnitLower>().solve(U);
232 work.topRows(nrow).noalias() = A * U;
235 for (Index j = 0; j < nrhs; j++) {
236 Index iptr = istart + nsupc;
237 for (Index i = 0; i < nrow; i++) {
239 X(irow, j) -= work(i, j);
240 work(i, j) = Scalar(0);
248template <
typename Scalar,
typename Index_>
249template <
bool Conjugate,
typename Dest>
250void MappedSuperNodalMatrix<Scalar, Index_>::solveTransposedInPlace(
MatrixBase<Dest>& X)
const {
252 Index n = int(X.rows());
253 Index nrhs = Index(X.cols());
254 const Scalar* Lval = valuePtr();
257 for (Index k = nsuper(); k >= 0; k--) {
258 Index fsupc = supToCol()[k];
259 Index istart = rowIndexPtr()[fsupc];
260 Index nsupr = rowIndexPtr()[fsupc + 1] - istart;
261 Index nsupc = supToCol()[k + 1] - fsupc;
262 Index nrow = nsupr - nsupc;
266 for (Index j = 0; j < nrhs; j++) {
271 X(fsupc, j) -= X(irow, j) * (Conjugate ? conj(it.value()) : it.value());
276 Index luptr = colIndexPtr()[fsupc];
277 Index lda = colIndexPtr()[fsupc + 1] - luptr;
280 for (Index j = 0; j < nrhs; j++) {
281 Index iptr = istart + nsupc;
282 for (Index i = 0; i < nrow; i++) {
283 irow = rowIndex()[iptr];
284 work.topRows(nrow)(i, j) = X(irow, j);
290 Map<const Matrix<Scalar, Dynamic, Dynamic, ColMajor>, 0, OuterStride<> > A(&(Lval[luptr + nsupc]), nrow, nsupc,
292 typename Dest::RowsBlockXpr U = X.derived().
middleRows(fsupc, nsupc);
293 EIGEN_IF_CONSTEXPR (Conjugate)
294 U.noalias() -= A.adjoint() * work.topRows(nrow);
296 U.noalias() -= A.transpose() * work.topRows(nrow);
299 new (&A) Map<
const Matrix<Scalar, Dynamic, Dynamic, ColMajor>, 0, OuterStride<> >(&(Lval[luptr]), nsupc, nsupc,
301 EIGEN_IF_CONSTEXPR (Conjugate)
302 U = A.adjoint().template triangularView<UnitUpper>().solve(U);
304 U = A.transpose().template triangularView<UnitUpper>().solve(U);
constexpr NRowsBlockXpr<... >::Type middleRows(Index startRow, NRowsType n)
Definition DenseBase.h:738
An InnerIterator allows to loop over the element of any matrix expression.
Definition CoreIterators.h:38
A matrix or vector expression mapping an existing array of data.
Definition Map.h:97
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
constexpr const Scalar * data() const
Definition PlainObjectBase.h:261
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:536
InnerIterator class to iterate over nonzero values of the current column in the supernodal matrix L.
Definition SparseLU_SupernodalMatrix.h:148
StorageIndex * rowIndexPtr()
Definition SparseLU_SupernodalMatrix.h:101
void setInfos(Index m, Index n, ScalarVector &nzval, IndexVector &nzval_colptr, IndexVector &rowind, IndexVector &rowind_colptr, IndexVector &col_to_sup, IndexVector &sup_to_col)
Definition SparseLU_SupernodalMatrix.h:53
StorageIndex * rowIndex()
Definition SparseLU_SupernodalMatrix.h:94
Index nsuper() const
Definition SparseLU_SupernodalMatrix.h:121
StorageIndex * colIndexPtr()
Definition SparseLU_SupernodalMatrix.h:87
StorageIndex * supToCol()
Definition SparseLU_SupernodalMatrix.h:114
void solveInPlace(MatrixBase< Dest > &X) const
Solve with the supernode triangular matrix.
Definition SparseLU_SupernodalMatrix.h:195
Index rows() const
Definition SparseLU_SupernodalMatrix.h:69
StorageIndex * colToSup()
Definition SparseLU_SupernodalMatrix.h:108
Index cols() const
Definition SparseLU_SupernodalMatrix.h:74
Scalar * valuePtr()
Definition SparseLU_SupernodalMatrix.h:81