11 #ifndef EIGEN_SPARSELU_SUPERNODAL_MATRIX_H
12 #define EIGEN_SPARSELU_SUPERNODAL_MATRIX_H
34 template <
typename Scalar_,
typename StorageIndex_>
35 class MappedSuperNodalMatrix
38 typedef Scalar_ Scalar;
39 typedef StorageIndex_ StorageIndex;
40 typedef Matrix<StorageIndex,Dynamic,1> IndexVector;
41 typedef Matrix<Scalar,Dynamic,1> ScalarVector;
43 MappedSuperNodalMatrix()
47 MappedSuperNodalMatrix(
Index m,
Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind,
48 IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col )
50 setInfos(
m,
n, nzval, nzval_colptr, rowind, rowind_colptr, col_to_sup, sup_to_col);
53 ~MappedSuperNodalMatrix()
63 void setInfos(
Index m,
Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind,
64 IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col )
68 m_nzval = nzval.data();
69 m_nzval_colptr = nzval_colptr.data();
70 m_rowind = rowind.data();
71 m_rowind_colptr = rowind_colptr.data();
72 m_nsuper = col_to_sup(
n);
73 m_col_to_sup = col_to_sup.data();
74 m_sup_to_col = sup_to_col.data();
92 Scalar* valuePtr() {
return m_nzval; }
94 const Scalar* valuePtr()
const
101 StorageIndex* colIndexPtr()
103 return m_nzval_colptr;
106 const StorageIndex* colIndexPtr()
const
108 return m_nzval_colptr;
114 StorageIndex* rowIndex() {
return m_rowind; }
116 const StorageIndex* rowIndex()
const
124 StorageIndex* rowIndexPtr() {
return m_rowind_colptr; }
126 const StorageIndex* rowIndexPtr()
const
128 return m_rowind_colptr;
134 StorageIndex* colToSup() {
return m_col_to_sup; }
136 const StorageIndex* colToSup()
const
143 StorageIndex* supToCol() {
return m_sup_to_col; }
145 const StorageIndex* supToCol()
const
159 template<
typename Dest>
160 void solveInPlace( MatrixBase<Dest>&
X)
const;
161 template<
bool Conjugate,
typename Dest>
162 void solveTransposedInPlace( MatrixBase<Dest>&
X)
const;
173 StorageIndex* m_nzval_colptr;
174 StorageIndex* m_rowind;
175 StorageIndex* m_rowind_colptr;
176 StorageIndex* m_col_to_sup;
177 StorageIndex* m_sup_to_col;
186 template<
typename Scalar,
typename StorageIndex>
187 class MappedSuperNodalMatrix<Scalar,StorageIndex>::InnerIterator
190 InnerIterator(
const MappedSuperNodalMatrix&
mat,
Index outer)
193 m_supno(
mat.colToSup()[outer]),
194 m_idval(
mat.colIndexPtr()[outer]),
195 m_startidval(m_idval),
196 m_endidval(
mat.colIndexPtr()[outer+1]),
197 m_idrow(
mat.rowIndexPtr()[
mat.supToCol()[
mat.colToSup()[outer]]]),
198 m_endidrow(
mat.rowIndexPtr()[
mat.supToCol()[
mat.colToSup()[outer]]+1])
206 inline Scalar value()
const {
return m_matrix.valuePtr()[m_idval]; }
208 inline Scalar& valueRef() {
return const_cast<Scalar&
>(m_matrix.valuePtr()[m_idval]); }
210 inline Index index()
const {
return m_matrix.rowIndex()[m_idrow]; }
211 inline Index row()
const {
return index(); }
212 inline Index col()
const {
return m_outer; }
214 inline Index supIndex()
const {
return m_supno; }
216 inline operator bool()
const
218 return ( (m_idval < m_endidval) && (m_idval >= m_startidval)
219 && (m_idrow < m_endidrow) );
223 const MappedSuperNodalMatrix& m_matrix;
227 const Index m_startidval;
228 const Index m_endidval;
237 template<
typename Scalar,
typename Index_>
238 template<
typename Dest>
239 void MappedSuperNodalMatrix<Scalar,Index_>::solveInPlace( MatrixBase<Dest>&
X)
const
246 const Scalar * Lval = valuePtr();
247 Matrix<Scalar,Dynamic,Dest::ColsAtCompileTime, ColMajor> work(
n, nrhs);
249 for (
Index k = 0; k <= nsuper(); k ++)
251 Index fsupc = supToCol()[k];
252 Index istart = rowIndexPtr()[fsupc];
253 Index nsupr = rowIndexPtr()[fsupc+1] - istart;
254 Index nsupc = supToCol()[k+1] - fsupc;
255 Index nrow = nsupr - nsupc;
262 InnerIterator it(*
this, fsupc);
267 X(irow,
j) -=
X(fsupc,
j) * it.value();
274 Index luptr = colIndexPtr()[fsupc];
275 Index lda = colIndexPtr()[fsupc+1] - luptr;
278 Map<const Matrix<Scalar,Dynamic,Dynamic, ColMajor>, 0, OuterStride<> >
A( &(Lval[luptr]), nsupc, nsupc, OuterStride<>(lda) );
279 typename Dest::RowsBlockXpr U =
X.derived().middleRows(fsupc, nsupc);
280 U =
A.template triangularView<UnitLower>().solve(U);
282 new (&
A) Map<
const Matrix<Scalar,Dynamic,Dynamic, ColMajor>, 0, OuterStride<> > ( &(Lval[luptr+nsupc]), nrow, nsupc, OuterStride<>(lda) );
283 work.topRows(nrow).noalias() =
A * U;
288 Index iptr = istart + nsupc;
291 irow = rowIndex()[iptr];
292 X(irow,
j) -= work(
i,
j);
293 work(
i,
j) = Scalar(0);
301 template<
typename Scalar,
typename Index_>
302 template<
bool Conjugate,
typename Dest>
303 void MappedSuperNodalMatrix<Scalar,Index_>::solveTransposedInPlace( MatrixBase<Dest>&
X)
const
308 const Scalar * Lval = valuePtr();
309 Matrix<Scalar,Dynamic,Dest::ColsAtCompileTime, ColMajor> work(
n, nrhs);
311 for (
Index k = nsuper(); k >= 0; k--)
313 Index fsupc = supToCol()[k];
314 Index istart = rowIndexPtr()[fsupc];
315 Index nsupr = rowIndexPtr()[fsupc+1] - istart;
316 Index nsupc = supToCol()[k+1] - fsupc;
317 Index nrow = nsupr - nsupc;
324 InnerIterator it(*
this, fsupc);
329 X(fsupc,
j) -=
X(irow,
j) * (Conjugate?
conj(it.value()):it.value());
336 Index luptr = colIndexPtr()[fsupc];
337 Index lda = colIndexPtr()[fsupc+1] - luptr;
342 Index iptr = istart + nsupc;
345 irow = rowIndex()[iptr];
346 work.topRows(nrow)(
i,
j)=
X(irow,
j);
352 Map<const Matrix<Scalar,Dynamic,Dynamic, ColMajor>, 0, OuterStride<> >
A( &(Lval[luptr+nsupc]), nrow, nsupc, OuterStride<>(lda) );
353 typename Dest::RowsBlockXpr U =
X.derived().middleRows(fsupc, nsupc);
355 U = U -
A.adjoint() * work.topRows(nrow);
357 U = U -
A.transpose() * work.topRows(nrow);
360 new (&
A) Map<
const Matrix<Scalar,Dynamic,Dynamic, ColMajor>, 0, OuterStride<> > ( &(Lval[luptr]), nsupc, nsupc, OuterStride<>(lda) );
362 U =
A.adjoint().template triangularView<UnitUpper>().solve(U);
364 U =
A.transpose().template triangularView<UnitUpper>().solve(U);
RowXpr row(Index i)
This is the const version of row(). */.
ColXpr col(Index i)
This is the const version of col().
bfloat16 operator++(bfloat16 &a)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)