11#ifndef EIGEN_SPARSELU_SUPERNODAL_MATRIX_H
12#define EIGEN_SPARSELU_SUPERNODAL_MATRIX_H
15#include "./InternalHeaderCheck.h"
35template <
typename Scalar_,
typename StorageIndex_>
36class MappedSuperNodalMatrix {
38 typedef Scalar_ Scalar;
39 typedef StorageIndex_ StorageIndex;
44 MappedSuperNodalMatrix() {}
45 MappedSuperNodalMatrix(
Index m,
Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind,
46 IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col) {
47 setInfos(m, n, nzval, nzval_colptr, rowind, rowind_colptr, col_to_sup, sup_to_col);
50 ~MappedSuperNodalMatrix() {}
57 void setInfos(
Index m,
Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind,
58 IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col) {
61 m_nzval = nzval.
data();
62 m_nzval_colptr = nzval_colptr.
data();
63 m_rowind = rowind.
data();
64 m_rowind_colptr = rowind_colptr.
data();
65 m_nsuper = col_to_sup(n);
66 m_col_to_sup = col_to_sup.
data();
67 m_sup_to_col = sup_to_col.
data();
87 const Scalar*
valuePtr()
const {
return m_nzval; }
93 const StorageIndex*
colIndexPtr()
const {
return m_nzval_colptr; }
100 const StorageIndex*
rowIndex()
const {
return m_rowind; }
107 const StorageIndex*
rowIndexPtr()
const {
return m_rowind_colptr; }
114 const StorageIndex*
colToSup()
const {
return m_col_to_sup; }
120 const StorageIndex*
supToCol()
const {
return m_sup_to_col; }
128 template <
typename Dest>
130 template <
bool Conjugate,
typename Dest>
138 StorageIndex* m_nzval_colptr;
139 StorageIndex* m_rowind;
140 StorageIndex* m_rowind_colptr;
141 StorageIndex* m_col_to_sup;
142 StorageIndex* m_sup_to_col;
151template <
typename Scalar,
typename StorageIndex>
159 m_startidval(m_idval),
168 inline Scalar value()
const {
return m_matrix.valuePtr()[m_idval]; }
170 inline Scalar& valueRef() {
return const_cast<Scalar&
>(m_matrix.valuePtr()[m_idval]); }
172 inline Index index()
const {
return m_matrix.rowIndex()[m_idrow]; }
173 inline Index row()
const {
return index(); }
174 inline Index col()
const {
return m_outer; }
176 inline Index supIndex()
const {
return m_supno; }
178 inline operator bool()
const {
179 return ((m_idval < m_endidval) && (m_idval >= m_startidval) && (m_idrow < m_endidrow));
183 const MappedSuperNodalMatrix& m_matrix;
187 const Index m_startidval;
188 const Index m_endidval;
197template <
typename Scalar,
typename Index_>
198template <
typename Dest>
203 Index n = int(X.rows());
213 Index nrow = nsupr - nsupc;
217 for (
Index j = 0; j < nrhs; j++) {
222 X(irow, j) -= X(fsupc, j) * it.value();
233 typename Dest::RowsBlockXpr U = X.derived().
middleRows(fsupc, nsupc);
234 U = A.template triangularView<UnitLower>().solve(U);
238 work.topRows(nrow).noalias() = A * U;
241 for (
Index j = 0; j < nrhs; j++) {
242 Index iptr = istart + nsupc;
243 for (
Index i = 0; i < nrow; i++) {
245 X(irow, j) -= work(i, j);
246 work(i, j) = Scalar(0);
254template <
typename Scalar,
typename Index_>
255template <
bool Conjugate,
typename Dest>
256void MappedSuperNodalMatrix<Scalar, Index_>::solveTransposedInPlace(
MatrixBase<Dest>& X)
const {
258 Index n = int(X.rows());
260 const Scalar* Lval = valuePtr();
263 for (
Index k = nsuper(); k >= 0; k--) {
264 Index fsupc = supToCol()[k];
265 Index istart = rowIndexPtr()[fsupc];
266 Index nsupr = rowIndexPtr()[fsupc + 1] - istart;
267 Index nsupc = supToCol()[k + 1] - fsupc;
268 Index nrow = nsupr - nsupc;
272 for (
Index j = 0; j < nrhs; j++) {
273 InnerIterator it(*
this, fsupc);
277 X(fsupc, j) -= X(irow, j) * (Conjugate ?
conj(it.value()) : it.value());
282 Index luptr = colIndexPtr()[fsupc];
283 Index lda = colIndexPtr()[fsupc + 1] - luptr;
286 for (
Index j = 0; j < nrhs; j++) {
287 Index iptr = istart + nsupc;
288 for (
Index i = 0; i < nrow; i++) {
289 irow = rowIndex()[iptr];
290 work.topRows(nrow)(i, j) = X(irow, j);
296 Map<const Matrix<Scalar, Dynamic, Dynamic, ColMajor>, 0, OuterStride<> > A(&(Lval[luptr + nsupc]), nrow, nsupc,
298 typename Dest::RowsBlockXpr U = X.derived().
middleRows(fsupc, nsupc);
300 U = U - A.adjoint() * work.topRows(nrow);
302 U = U - A.transpose() * work.topRows(nrow);
305 new (&A) Map<
const Matrix<Scalar, Dynamic, Dynamic, ColMajor>, 0, OuterStride<> >(&(Lval[luptr]), nsupc, nsupc,
308 U = A.adjoint().template triangularView<UnitUpper>().solve(U);
310 U = A.transpose().template triangularView<UnitUpper>().solve(U);
NRowsBlockXpr<... >::Type middleRows(Index startRow, NRowsType n)
Definition DenseBase.h:733
A matrix or vector expression mapping an existing array of data.
Definition Map.h:96
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
Convenience specialization of Stride to specify only an outer stride See class Map for some examples.
Definition Stride.h:104
constexpr const Scalar * data() const
Definition PlainObjectBase.h:247
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:567
InnerIterator class to iterate over nonzero values of the current column in the supernodal matrix L.
Definition SparseLU_SupernodalMatrix.h:152
StorageIndex * rowIndexPtr()
Definition SparseLU_SupernodalMatrix.h:105
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:57
StorageIndex * rowIndex()
Definition SparseLU_SupernodalMatrix.h:98
Index nsuper() const
Definition SparseLU_SupernodalMatrix.h:125
StorageIndex * colIndexPtr()
Definition SparseLU_SupernodalMatrix.h:91
StorageIndex * supToCol()
Definition SparseLU_SupernodalMatrix.h:118
void solveInPlace(MatrixBase< Dest > &X) const
Solve with the supernode triangular matrix.
Definition SparseLU_SupernodalMatrix.h:199
Index rows() const
Definition SparseLU_SupernodalMatrix.h:73
StorageIndex * colToSup()
Definition SparseLU_SupernodalMatrix.h:112
Index cols() const
Definition SparseLU_SupernodalMatrix.h:78
Scalar * valuePtr()
Definition SparseLU_SupernodalMatrix.h:85
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82