10 #ifndef EIGEN_SPARSE_SELFADJOINTVIEW_H 11 #define EIGEN_SPARSE_SELFADJOINTVIEW_H 31 template<
typename MatrixType,
unsigned int Mode>
35 template<
int SrcMode,
int DstMode,
typename MatrixType,
int DestOrder>
38 template<
int Mode,
typename MatrixType,
int DestOrder>
44 :
public EigenBase<SparseSelfAdjointView<MatrixType,_Mode> >
56 typedef typename MatrixType::Scalar
Scalar;
64 eigen_assert(rows()==cols() &&
"SelfAdjointView is only for squared matrices");
67 inline Index rows()
const {
return m_matrix.rows(); }
68 inline Index cols()
const {
return m_matrix.cols(); }
71 const _MatrixTypeNested&
matrix()
const {
return m_matrix; }
79 template<
typename OtherDerived>
91 template<
typename OtherDerived>
friend 99 template<
typename OtherDerived>
107 template<
typename OtherDerived>
friend 122 template<
typename DerivedU>
132 template<
typename SrcMatrixType,
int SrcMode>
145 template<
typename SrcMatrixType,
unsigned int SrcMode>
156 eigen_assert(rows == this->rows() && cols == this->cols()
157 &&
"SparseSelfadjointView::resize() does not actually allow to resize.");
166 template<
typename Dest>
void evalTo(Dest &)
const;
173 template<
typename Derived>
174 template<
unsigned int UpLo>
180 template<
typename Derived>
181 template<
unsigned int UpLo>
191 template<
typename MatrixType,
unsigned int Mode>
192 template<
typename DerivedU>
198 m_matrix = tmp.template triangularView<Mode>();
200 m_matrix += alpha * tmp.template triangularView<Mode>();
210 template<
typename MatrixType,
unsigned int Mode>
222 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
228 template<
typename DestScalar,
int StorageOrder>
231 internal::permute_symm_to_fullsymm<SrcXprType::Mode>(src.matrix(), dst);
235 template<
typename DestScalar,
int StorageOrder,
typename AssignFunc>
239 run(tmp, src, AssignOpType());
243 template<
typename DestScalar,
int StorageOrder>
248 run(tmp, src, AssignOpType());
252 template<
typename DestScalar,
int StorageOrder>
257 run(tmp, src, AssignOpType());
261 template<
typename DestScalar>
266 internal::permute_symm_to_fullsymm<SrcXprType::Mode>(src.matrix(), tmp);
279 template<
int Mode,
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
287 typedef typename LhsEval::InnerIterator LhsIterator;
288 typedef typename SparseLhsType::Scalar LhsScalar;
294 || ( (Mode&
Upper) && !LhsIsRowMajor)
295 || ( (Mode&
Lower) && LhsIsRowMajor),
296 ProcessSecondHalf = !ProcessFirstHalf
299 SparseLhsTypeNested lhs_nested(lhs);
300 LhsEval lhsEval(lhs_nested);
303 for (
Index k=0; k<rhs.cols(); ++k)
305 for (
Index j=0; j<lhs.outerSize(); ++j)
307 LhsIterator i(lhsEval,j);
309 if (ProcessSecondHalf)
311 while (i && i.index()<j) ++i;
312 if(i && i.index()==j)
314 res(j,k) += alpha * i.value() * rhs(j,k);
322 typename DenseResType::Scalar res_j(0);
323 for(; (ProcessFirstHalf ? i && i.index() < j : i) ; ++i)
325 LhsScalar lhs_ij = i.value();
327 res_j += lhs_ij * rhs(i.index(),k);
330 res(j,k) += alpha * res_j;
333 if (ProcessFirstHalf && i && (i.index()==j))
334 res(j,k) += alpha * i.value() * rhs(j,k);
340 template<
typename LhsView,
typename Rhs,
int ProductType>
342 :
generic_product_impl_base<LhsView, Rhs, generic_product_impl<LhsView, Rhs, SparseSelfAdjointShape, DenseShape, ProductType> >
344 template<
typename Dest>
345 static void scaleAndAddTo(Dest& dst,
const LhsView& lhsView,
const Rhs& rhs,
const typename Dest::Scalar& alpha)
347 typedef typename LhsView::_MatrixTypeNested
Lhs;
350 LhsNested lhsNested(lhsView.matrix());
351 RhsNested rhsNested(rhs);
353 internal::sparse_selfadjoint_time_dense_product<LhsView::Mode>(lhsNested, rhsNested, dst, alpha);
357 template<
typename Lhs,
typename RhsView,
int ProductType>
359 :
generic_product_impl_base<Lhs, RhsView, generic_product_impl<Lhs, RhsView, DenseShape, SparseSelfAdjointShape, ProductType> >
361 template<
typename Dest>
362 static void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const RhsView& rhsView,
const typename Dest::Scalar& alpha)
364 typedef typename RhsView::_MatrixTypeNested
Rhs;
367 LhsNested lhsNested(lhs);
368 RhsNested rhsNested(rhsView.matrix());
372 internal::sparse_selfadjoint_time_dense_product<RhsView::TransposeMode>(rhsNested.transpose(), lhsNested.transpose(), dstT, alpha);
379 template<
typename LhsView,
typename Rhs,
int ProductTag>
381 :
public evaluator<typename Product<typename Rhs::PlainObject, Rhs, DefaultProduct>::PlainObject>
388 : m_lhs(xpr.lhs()), m_result(xpr.rows(), xpr.cols())
390 ::new (static_cast<Base*>(
this)) Base(m_result);
399 template<
typename Lhs,
typename RhsView,
int ProductTag>
401 :
public evaluator<typename Product<Lhs, typename Lhs::PlainObject, DefaultProduct>::PlainObject>
408 : m_rhs(xpr.rhs()), m_result(xpr.rows(), xpr.cols())
410 ::new (static_cast<Base*>(
this)) Base(m_result);
426 template<
int Mode,
typename MatrixType,
int DestOrder>
429 typedef typename MatrixType::StorageIndex StorageIndex;
430 typedef typename MatrixType::Scalar Scalar;
436 MatEval matEval(mat);
439 StorageOrderMatch = int(Dest::IsRowMajor) == int(MatrixType::IsRowMajor)
446 dest.resize(size,size);
449 Index jp = perm ? perm[j] : j;
450 for(MatIterator it(matEval,j); it; ++it)
452 Index i = it.index();
455 Index ip = perm ? perm[i] : i;
457 count[StorageOrderMatch ? jp : ip]++;
460 else if(( Mode==
Lower && r>c) || ( Mode==
Upper && r<c))
467 Index nnz = count.sum();
470 dest.resizeNonZeros(nnz);
471 dest.outerIndexPtr()[0] = 0;
473 dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
475 count[j] = dest.outerIndexPtr()[j];
478 for(StorageIndex j = 0; j<
size; ++j)
480 for(MatIterator it(matEval,j); it; ++it)
482 StorageIndex i = internal::convert_index<StorageIndex>(it.index());
486 StorageIndex jp = perm ? perm[j] : j;
487 StorageIndex ip = perm ? perm[i] : i;
491 Index k = count[StorageOrderMatch ? jp : ip]++;
492 dest.innerIndexPtr()[k] = StorageOrderMatch ? ip : jp;
493 dest.valuePtr()[k] = it.value();
497 Index k = count[ip]++;
498 dest.innerIndexPtr()[k] = ip;
499 dest.valuePtr()[k] = it.value();
501 else if(( (Mode&
Lower)==Lower && r>c) || ( (Mode&
Upper)==Upper && r<c))
503 if(!StorageOrderMatch)
505 Index k = count[jp]++;
506 dest.innerIndexPtr()[k] = ip;
507 dest.valuePtr()[k] = it.value();
509 dest.innerIndexPtr()[k] = jp;
516 template<
int _SrcMode,
int _DstMode,
typename MatrixType,
int DstOrder>
519 typedef typename MatrixType::StorageIndex StorageIndex;
520 typedef typename MatrixType::Scalar Scalar;
528 StorageOrderMatch = int(SrcOrder) == int(DstOrder),
533 MatEval matEval(mat);
538 dest.resize(size,size);
539 for(StorageIndex j = 0; j<
size; ++j)
541 StorageIndex jp = perm ? perm[j] : j;
542 for(MatIterator it(matEval,j); it; ++it)
544 StorageIndex i = it.index();
545 if((
int(SrcMode)==
int(
Lower) && i<j) || (
int(SrcMode)==
int(
Upper) && i>j))
548 StorageIndex ip = perm ? perm[i] : i;
549 count[int(DstMode)==int(
Lower) ? (std::min)(ip,jp) : (
std::max)(ip,jp)]++;
552 dest.outerIndexPtr()[0] = 0;
554 dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
555 dest.resizeNonZeros(dest.outerIndexPtr()[
size]);
557 count[j] = dest.outerIndexPtr()[j];
559 for(StorageIndex j = 0; j<
size; ++j)
562 for(MatIterator it(matEval,j); it; ++it)
564 StorageIndex i = it.index();
565 if((
int(SrcMode)==
int(
Lower) && i<j) || (
int(SrcMode)==
int(
Upper) && i>j))
568 StorageIndex jp = perm ? perm[j] : j;
569 StorageIndex ip = perm? perm[i] : i;
572 dest.innerIndexPtr()[k] = int(DstMode)==int(
Lower) ? (
std::max)(ip,jp) : (std::min)(ip,jp);
575 if( ((
int(DstMode)==
int(
Lower) && ip<jp) || (
int(DstMode)==
int(
Upper) && ip>jp)))
578 dest.valuePtr()[k] = it.value();
589 template<
typename MatrixType,
int Mode>
595 template<
typename MatrixType,
int Mode>
597 :
public EigenBase<SparseSymmetricPermutationProduct<MatrixType,Mode> >
600 typedef typename MatrixType::Scalar
Scalar;
614 : m_matrix(mat), m_perm(perm)
620 const NestedExpression&
matrix()
const {
return m_matrix; }
621 const Perm&
perm()
const {
return m_perm; }
631 template<
typename DstXprType,
typename MatrixType,
int Mode,
typename Scalar>
635 typedef typename DstXprType::StorageIndex
DstIndex;
636 template<
int Options>
641 internal::permute_symm_to_fullsymm<Mode>(src.
matrix(),tmp,src.
perm().
indices().data());
645 template<
typename DestType,
unsigned int DestMode>
656 #endif // EIGEN_SPARSE_SELFADJOINTVIEW_H ConstSelfAdjointViewReturnType< UpLo >::Type selfadjointView() const
Product< SparseSelfAdjointView, OtherDerived > operator*(const SparseMatrixBase< OtherDerived > &rhs) const
EigenBase< SparseSelfAdjointView > Base
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
XprType::PlainObject PlainObject
const AdjointReturnType adjoint() const
Expression of the product of two arbitrary matrices or vectors.
product_evaluator(const XprType &xpr)
SparseSelfAdjointView(MatrixType &matrix)
const Perm & perm() const
A versatible sparse matrix representation.
PermutationMatrix< Dynamic, Dynamic, StorageIndex > Perm
static void run(SparseMatrix< DestScalar, StorageOrder, StorageIndex > &dst, const SrcXprType &src, const AssignFunc &func)
Expression of the transpose of a matrix.
friend Product< OtherDerived, SparseSelfAdjointView > operator*(const SparseMatrixBase< OtherDerived > &lhs, const SparseSelfAdjointView &rhs)
friend Product< OtherDerived, SparseSelfAdjointView > operator*(const MatrixBase< OtherDerived > &lhs, const SparseSelfAdjointView &rhs)
product_evaluator(const XprType &xpr)
static void run(SparseSelfAdjointView< DestType, DestMode > &dst, const SrcXprType &src, const internal::assign_op< Scalar, typename MatrixType::Scalar > &)
SparseSymmetricPermutationProduct(const MatrixType &mat, const Perm &perm)
internal::remove_reference< MatrixTypeNested >::type & matrix()
MatrixTypeNested m_matrix
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Matrix< StorageIndex, Dynamic, 1 > VectorI
void sparse_selfadjoint_time_dense_product(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const AlphaType &alpha)
internal::remove_all< MatrixTypeNested >::type _MatrixTypeNested
static void scaleAndAddTo(Dest &dst, const Lhs &lhs, const RhsView &rhsView, const typename Dest::Scalar &alpha)
Eigen::Index Index
The interface type of indices.
static void scaleAndAddTo(Dest &dst, const LhsView &lhsView, const Rhs &rhs, const typename Dest::Scalar &alpha)
const unsigned int RowMajorBit
EIGEN_DEVICE_FUNC const LhsNestedCleaned & lhs() const
XprType::PlainObject PlainObject
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
SparseSelfAdjointView & operator=(const SparseSelfAdjointView &src)
Base class of any sparse matrices or sparse expressions.
Product< SparseSelfAdjointView, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
storage_kind_to_evaluator_kind< typename MatrixType::StorageKind >::Kind Kind
static void run(SparseMatrix< Scalar, Options, DstIndex > &dst, const SrcXprType &src, const internal::assign_op< Scalar, typename MatrixType::Scalar > &)
SparseSelfAdjointView & operator=(const SparseSymmetricPermutationProduct< SrcMatrixType, SrcMode > &permutedMatrix)
evaluator< PlainObject > Base
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
SparseSelfAdjoint2Sparse Kind
SparseSelfAdjointShape Shape
A sparse matrix class designed for matrix assembly purpose.
void permute_symm_to_symm(const MatrixType &mat, SparseMatrix< typename MatrixType::Scalar, DestOrder, typename MatrixType::StorageIndex > &_dest, const typename MatrixType::StorageIndex *perm=0)
Product< Lhs, RhsView, DefaultProduct > XprType
internal::ref_selector< MatrixType >::non_const_type MatrixTypeNested
DstXprType::StorageIndex DstIndex
MatrixType::StorageIndex StorageIndex
void permute_symm_to_fullsymm(const MatrixType &mat, SparseMatrix< typename MatrixType::Scalar, DestOrder, typename MatrixType::StorageIndex > &_dest, const typename MatrixType::StorageIndex *perm=0)
static void run(SparseMatrix< DestScalar, StorageOrder, StorageIndex > &dst, const SrcXprType &src, const AssignOpType &)
MatrixType::Scalar Scalar
static void run(SparseMatrix< DestScalar, StorageOrder, StorageIndex > &dst, const SrcXprType &src, const internal::add_assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > &)
SparseSelfAdjointView & rankUpdate(const SparseMatrixBase< DerivedU > &u, const Scalar &alpha=Scalar(1))
MatrixType::StorageIndex StorageIndex
static void run(DynamicSparseMatrix< DestScalar, ColMajor, StorageIndex > &dst, const SrcXprType &src, const AssignOpType &)
static void run(SparseMatrix< DestScalar, StorageOrder, StorageIndex > &dst, const SrcXprType &src, const internal::sub_assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > &)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment_no_alias_no_transpose(Dst &dst, const Src &src, const Func &func)
const Derived & derived() const
evaluator< PlainObject > Base
const IndicesType & indices() const
const _MatrixTypeNested & matrix() const
Matrix< StorageIndex, Dynamic, 1 > VectorI
internal::assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > AssignOpType
SparseSelfAdjointView & operator=(const SparseSelfAdjointView< SrcMatrixType, SrcMode > &src)
SparseSymmetricPermutationProduct< MatrixType, Mode > SrcXprType
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
MatrixType::Nested MatrixTypeNested
DstXprType::StorageIndex StorageIndex
internal::remove_all< MatrixTypeNested >::type NestedExpression
SparseSymmetricPermutationProduct< _MatrixTypeNested, Mode > twistedBy(const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
void run(Expr &expr, Dev &dev)
const NestedExpression & matrix() const
MatrixType::Scalar Scalar
EIGEN_DEVICE_FUNC const RhsNestedCleaned & rhs() const
MatrixTypeNested m_matrix
Base class for all dense matrices, vectors, and expressions.
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Product< LhsView, Rhs, DefaultProduct > XprType
void resize(Index rows, Index cols)
#define EIGEN_ONLY_USED_FOR_DEBUG(x)