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;
40 typedef Matrix<StorageIndex, Dynamic, 1> IndexVector;
41 typedef Matrix<Scalar, Dynamic, 1> ScalarVector;
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();
73 Index rows()
const {
return m_row; }
78 Index cols()
const {
return m_col; }
85 Scalar* valuePtr() {
return m_nzval; }
87 const Scalar* valuePtr()
const {
return m_nzval; }
91 StorageIndex* colIndexPtr() {
return m_nzval_colptr; }
93 const StorageIndex* colIndexPtr()
const {
return m_nzval_colptr; }
98 StorageIndex* rowIndex() {
return m_rowind; }
100 const StorageIndex* rowIndex()
const {
return m_rowind; }
105 StorageIndex* rowIndexPtr() {
return m_rowind_colptr; }
107 const StorageIndex* rowIndexPtr()
const {
return m_rowind_colptr; }
112 StorageIndex* colToSup() {
return m_col_to_sup; }
114 const StorageIndex* colToSup()
const {
return m_col_to_sup; }
118 StorageIndex* supToCol() {
return m_sup_to_col; }
120 const StorageIndex* supToCol()
const {
return m_sup_to_col; }
125 Index nsuper()
const {
return m_nsuper; }
128 template <
typename Dest>
129 void solveInPlace(MatrixBase<Dest>& X)
const;
130 template <
bool Conjugate,
typename Dest>
131 void solveTransposedInPlace(MatrixBase<Dest>& X)
const;
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>
152class MappedSuperNodalMatrix<Scalar, StorageIndex>::InnerIterator {
154 InnerIterator(
const MappedSuperNodalMatrix& mat, Index outer)
157 m_supno(mat.colToSup()[outer]),
158 m_idval(mat.colIndexPtr()[outer]),
159 m_startidval(m_idval),
160 m_endidval(mat.colIndexPtr()[outer + 1]),
161 m_idrow(mat.rowIndexPtr()[mat.supToCol()[mat.colToSup()[outer]]]),
162 m_endidrow(mat.rowIndexPtr()[mat.supToCol()[mat.colToSup()[outer]] + 1]) {}
163 inline InnerIterator& operator++() {
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>
199void MappedSuperNodalMatrix<Scalar, Index_>::solveInPlace(MatrixBase<Dest>& X)
const {
203 Index n = int(X.rows());
204 Index nrhs =
Index(X.cols());
205 const Scalar* Lval = valuePtr();
206 Matrix<Scalar, Dynamic, Dest::ColsAtCompileTime, ColMajor> work(n, nrhs);
208 for (Index k = 0; k <= nsuper(); k++) {
209 Index fsupc = supToCol()[k];
210 Index istart = rowIndexPtr()[fsupc];
211 Index nsupr = rowIndexPtr()[fsupc + 1] - istart;
212 Index nsupc = supToCol()[k + 1] - fsupc;
213 Index nrow = nsupr - nsupc;
217 for (Index j = 0; j < nrhs; j++) {
218 InnerIterator it(*
this, fsupc);
222 X(irow, j) -= X(fsupc, j) * it.value();
227 Index luptr = colIndexPtr()[fsupc];
228 Index lda = colIndexPtr()[fsupc + 1] - luptr;
231 Map<const Matrix<Scalar, Dynamic, Dynamic, ColMajor>, 0, OuterStride<> > A(&(Lval[luptr]), nsupc, nsupc,
233 typename Dest::RowsBlockXpr U = X.derived().middleRows(fsupc, nsupc);
234 U = A.template triangularView<UnitLower>().solve(U);
236 new (&A) Map<
const Matrix<Scalar, Dynamic, Dynamic, ColMajor>, 0, OuterStride<> >(&(Lval[luptr + nsupc]), nrow,
237 nsupc, OuterStride<>(lda));
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++) {
244 irow = rowIndex()[iptr];
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());
259 Index nrhs =
Index(X.cols());
260 const Scalar* Lval = valuePtr();
261 Matrix<Scalar, Dynamic, Dest::ColsAtCompileTime, ColMajor> work(n, nrhs);
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);
Namespace containing all symbols from the Eigen library.
Definition Core:137
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:83