10 #ifndef EIGEN_SPARSE_SELFADJOINTVIEW_H 11 #define EIGEN_SPARSE_SELFADJOINTVIEW_H 29 template<
typename Lhs,
typename Rhs,
int UpLo>
32 template<
typename Lhs,
typename Rhs,
int UpLo>
37 template<
typename MatrixType,
unsigned int UpLo>
41 template<
int SrcUpLo,
int DstUpLo,
typename MatrixType,
int DestOrder>
44 template<
int UpLo,
typename MatrixType,
int DestOrder>
50 :
public EigenBase<SparseSelfAdjointView<MatrixType,UpLo> >
54 typedef typename MatrixType::Scalar
Scalar;
55 typedef typename MatrixType::Index
Index;
62 eigen_assert(rows()==cols() &&
"SelfAdjointView is only for squared matrices");
65 inline Index
rows()
const {
return m_matrix.rows(); }
66 inline Index
cols()
const {
return m_matrix.cols(); }
69 const _MatrixTypeNested&
matrix()
const {
return m_matrix; }
70 _MatrixTypeNested&
matrix() {
return m_matrix.const_cast_derived(); }
77 template<
typename OtherDerived>
89 template<
typename OtherDerived>
friend 97 template<
typename OtherDerived>
105 template<
typename OtherDerived>
friend 120 template<
typename DerivedU>
126 internal::permute_symm_to_fullsymm<UpLo>(m_matrix, _dest);
133 internal::permute_symm_to_fullsymm<UpLo>(m_matrix, tmp);
143 template<
typename SrcMatrixType,
int SrcUpLo>
146 permutedMatrix.
evalTo(*
this);
157 template<
typename SrcMatrixType,
unsigned int SrcUpLo>
179 template<
typename Derived>
180 template<
unsigned int UpLo>
186 template<
typename Derived>
187 template<
unsigned int UpLo>
197 template<
typename MatrixType,
unsigned int UpLo>
198 template<
typename DerivedU>
204 m_matrix.const_cast_derived() = tmp.template triangularView<UpLo>();
216 template<
typename Lhs,
typename Rhs,
int UpLo>
218 :
traits<ProductBase<SparseSelfAdjointTimeDenseProduct<Lhs,Rhs,UpLo>, Lhs, Rhs> >
224 template<
typename Lhs,
typename Rhs,
int UpLo>
226 :
public ProductBase<SparseSelfAdjointTimeDenseProduct<Lhs,Rhs,UpLo>, Lhs, Rhs>
240 typedef typename _Lhs::InnerIterator LhsInnerIterator;
245 || ( (UpLo&
Upper) && !LhsIsRowMajor)
246 || ( (UpLo&
Lower) && LhsIsRowMajor),
247 ProcessSecondHalf = !ProcessFirstHalf
249 for (
Index j=0; j<m_lhs.outerSize(); ++j)
251 LhsInnerIterator i(m_lhs,j);
252 if (ProcessSecondHalf)
254 while (i && i.index()<j) ++i;
255 if(i && i.index()==j)
257 dest.row(j) += i.value() * m_rhs.row(j);
261 for(; (ProcessFirstHalf ? i && i.index() < j : i) ; ++i)
263 Index a = LhsIsRowMajor ? j : i.index();
264 Index b = LhsIsRowMajor ? i.index() : j;
265 typename Lhs::Scalar
v = i.value();
266 dest.row(a) += (
v) * m_rhs.row(b);
269 if (ProcessFirstHalf && i && (i.index()==j))
270 dest.row(j) += i.value() * m_rhs.row(j);
279 template<
typename Lhs,
typename Rhs,
int UpLo>
281 :
traits<ProductBase<DenseTimeSparseSelfAdjointProduct<Lhs,Rhs,UpLo>, Lhs, Rhs> >
285 template<
typename Lhs,
typename Rhs,
int UpLo>
287 :
public ProductBase<DenseTimeSparseSelfAdjointProduct<Lhs,Rhs,UpLo>, Lhs, Rhs>
309 template<
typename MatrixType,
int UpLo>
313 template<
int UpLo,
typename MatrixType,
int DestOrder>
316 typedef typename MatrixType::Index Index;
317 typedef typename MatrixType::Scalar Scalar;
323 StorageOrderMatch = int(Dest::IsRowMajor) == int(MatrixType::IsRowMajor)
326 Index size = mat.
rows();
330 dest.resize(size,size);
331 for(Index j = 0; j<size; ++j)
333 Index jp = perm ? perm[j] : j;
334 for(
typename MatrixType::InnerIterator it(mat,j); it; ++it)
336 Index i = it.index();
339 Index ip = perm ? perm[i] : i;
341 count[StorageOrderMatch ? jp : ip]++;
344 else if(( UpLo==
Lower && r>c) || ( UpLo==
Upper && r<c))
351 Index nnz = count.sum();
354 dest.resizeNonZeros(nnz);
355 dest.outerIndexPtr()[0] = 0;
356 for(Index j=0; j<size; ++j)
357 dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
358 for(Index j=0; j<size; ++j)
359 count[j] = dest.outerIndexPtr()[j];
362 for(Index j = 0; j<size; ++j)
364 for(
typename MatrixType::InnerIterator it(mat,j); it; ++it)
366 Index i = it.index();
370 Index jp = perm ? perm[j] : j;
371 Index ip = perm ? perm[i] : i;
375 Index k = count[StorageOrderMatch ? jp : ip]++;
376 dest.innerIndexPtr()[k] = StorageOrderMatch ? ip : jp;
377 dest.valuePtr()[k] = it.value();
381 Index k = count[ip]++;
382 dest.innerIndexPtr()[k] = ip;
383 dest.valuePtr()[k] = it.value();
385 else if(( (UpLo&
Lower)==Lower && r>c) || ( (UpLo&
Upper)==Upper && r<c))
387 if(!StorageOrderMatch)
389 Index k = count[jp]++;
390 dest.innerIndexPtr()[k] = ip;
391 dest.valuePtr()[k] = it.value();
393 dest.innerIndexPtr()[k] = jp;
400 template<
int _SrcUpLo,
int _DstUpLo,
typename MatrixType,
int DstOrder>
403 typedef typename MatrixType::Index Index;
404 typedef typename MatrixType::Scalar Scalar;
409 StorageOrderMatch = int(SrcOrder) == int(DstOrder),
414 Index size = mat.rows();
417 dest.resize(size,size);
418 for(Index j = 0; j<size; ++j)
420 Index jp = perm ? perm[j] : j;
421 for(
typename MatrixType::InnerIterator it(mat,j); it; ++it)
423 Index i = it.index();
424 if((
int(SrcUpLo)==
int(
Lower) && i<j) || (
int(SrcUpLo)==
int(
Upper) && i>j))
427 Index ip = perm ? perm[i] : i;
428 count[int(DstUpLo)==int(
Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++;
431 dest.outerIndexPtr()[0] = 0;
432 for(Index j=0; j<size; ++j)
433 dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
434 dest.resizeNonZeros(dest.outerIndexPtr()[size]);
435 for(Index j=0; j<size; ++j)
436 count[j] = dest.outerIndexPtr()[j];
438 for(Index j = 0; j<size; ++j)
441 for(
typename MatrixType::InnerIterator it(mat,j); it; ++it)
443 Index i = it.index();
444 if((
int(SrcUpLo)==
int(
Lower) && i<j) || (
int(SrcUpLo)==
int(
Upper) && i>j))
447 Index jp = perm ? perm[j] : j;
448 Index ip = perm? perm[i] : i;
450 Index k = count[int(DstUpLo)==int(
Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++;
451 dest.innerIndexPtr()[k] = int(DstUpLo)==int(
Lower) ? (std::max)(ip,jp) : (std::min)(ip,jp);
453 if(!StorageOrderMatch) std::swap(ip,jp);
454 if( ((
int(DstUpLo)==
int(
Lower) && ip<jp) || (
int(DstUpLo)==
int(
Upper) && ip>jp)))
457 dest.valuePtr()[k] = it.value();
464 template<
typename MatrixType,
int UpLo>
466 :
public EigenBase<SparseSymmetricPermutationProduct<MatrixType,UpLo> >
469 typedef typename MatrixType::Scalar
Scalar;
470 typedef typename MatrixType::Index
Index;
479 : m_matrix(mat), m_perm(perm)
482 inline Index
rows()
const {
return m_matrix.rows(); }
483 inline Index
cols()
const {
return m_matrix.cols(); }
485 template<
typename DestScalar,
int Options,
typename DstIndex>
490 internal::permute_symm_to_fullsymm<UpLo>(m_matrix,tmp,m_perm.indices().
data());
496 internal::permute_symm_to_symm<UpLo,DestUpLo>(m_matrix,dest.
matrix(),m_perm.indices().data());
507 #endif // EIGEN_SPARSE_SELFADJOINTVIEW_H
const _MatrixTypeNested & matrix() const
void scaleAndAddTo(Dest &, const Scalar &) const
#define EIGEN_PRODUCT_PUBLIC_INTERFACE(Derived)
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
const AdjointReturnType adjoint() const
internal::traits< Derived >::Scalar Scalar
MatrixTypeNested m_matrix
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
A versatible sparse matrix representation.
const SparseSelfAdjointView< Derived, UpLo > selfadjointView() const
void permute_symm_to_symm(const MatrixType &mat, SparseMatrix< typename MatrixType::Scalar, DestOrder, typename MatrixType::Index > &_dest, const typename MatrixType::Index *perm=0)
internal::traits< Derived >::Index Index
The type of indices.
SparseSelfAdjointView(const MatrixType &matrix)
internal::remove_all< MatrixTypeNested >::type _MatrixTypeNested
PermutationMatrix< Dynamic, Dynamic, Index > Perm
Matrix< Index, Dynamic, 1 > VectorI
iterative scaling algorithm to equilibrate rows and column norms in matrices
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
void scaleAndAddTo(Dest &dest, const Scalar &alpha) const
const unsigned int RowMajorBit
Matrix< Index, Dynamic, 1 > VectorI
SparseSelfAdjointTimeDenseProduct< MatrixType, OtherDerived, UpLo > operator*(const MatrixBase< OtherDerived > &rhs) const
EIGEN_STRONG_INLINE Index rows() const
MatrixType::Nested MatrixTypeNested
friend DenseTimeSparseSelfAdjointProduct< OtherDerived, MatrixType, UpLo > operator*(const MatrixBase< OtherDerived > &lhs, const SparseSelfAdjointView &rhs)
Base class of any sparse matrices or sparse expressions.
MatrixType::Nested m_matrix
SparseSymmetricPermutationProduct(const MatrixType &mat, const Perm &perm)
SparseSparseProduct< typename OtherDerived::PlainObject, OtherDerived > operator*(const SparseMatrixBase< OtherDerived > &rhs) const
SparseSelfAdjointView & operator=(const SparseSymmetricPermutationProduct< SrcMatrixType, SrcUpLo > &permutedMatrix)
SparseSelfAdjointView & rankUpdate(const SparseMatrixBase< DerivedU > &u, const Scalar &alpha=Scalar(1))
MatrixType::Scalar Scalar
A sparse matrix class designed for matrix assembly purpose.
SparseSelfAdjointView & operator=(const SparseSelfAdjointView< SrcMatrixType, SrcUpLo > &src)
_MatrixTypeNested & matrix()
SparseSymmetricPermutationProduct< _MatrixTypeNested, UpLo > twistedBy(const PermutationMatrix< Dynamic, Dynamic, Index > &perm) const
void rhs(const real_t *x, real_t *f)
SparseSelfAdjointView & operator=(const SparseSelfAdjointView &src)
friend SparseSparseProduct< OtherDerived, typename OtherDerived::PlainObject > operator*(const SparseMatrixBase< OtherDerived > &lhs, const SparseSelfAdjointView &rhs)
const Derived & derived() const
MatrixType::Nested MatrixTypeNested
void evalTo(SparseSelfAdjointView< DestType, DestUpLo > &dest) const
MatrixType::Scalar Scalar
void evalTo(SparseMatrix< DestScalar, StorageOrder, Index > &_dest) const
internal::remove_all< MatrixTypeNested >::type _MatrixTypeNested
void evalTo(DynamicSparseMatrix< DestScalar, ColMajor, Index > &_dest) const
Base class for all dense matrices, vectors, and expressions.
void permute_symm_to_fullsymm(const MatrixType &mat, SparseMatrix< typename MatrixType::Scalar, DestOrder, typename MatrixType::Index > &_dest, const typename MatrixType::Index *perm=0)
SparseMatrix< _Scalar, _Options, _Index > & const_cast_derived() const
void evalTo(SparseMatrix< DestScalar, Options, DstIndex > &_dest) const