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> >
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>
148 template<
typename SrcMatrixType,
unsigned int SrcMode>
160 &&
"SparseSelfadjointView::resize() does not actually allow to resize.");
169 template<
typename Dest>
void evalTo(Dest &)
const;
176 template<
typename Derived>
177 template<
unsigned int UpLo>
183 template<
typename Derived>
184 template<
unsigned int UpLo>
194 template<
typename MatrixType,
unsigned int Mode>
195 template<
typename DerivedU>
201 m_matrix = tmp.template triangularView<Mode>();
203 m_matrix += alpha * tmp.template triangularView<Mode>();
213 template<
typename MatrixType,
unsigned int Mode>
225 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
231 template<
typename DestScalar,
int StorageOrder>
234 internal::permute_symm_to_fullsymm<SrcXprType::Mode>(src.matrix(), dst);
238 template<
typename DestScalar,
int StorageOrder,
typename AssignFunc>
242 run(tmp, src, AssignOpType());
246 template<
typename DestScalar,
int StorageOrder>
251 run(tmp, src, AssignOpType());
255 template<
typename DestScalar,
int StorageOrder>
260 run(tmp, src, AssignOpType());
264 template<
typename DestScalar>
269 internal::permute_symm_to_fullsymm<SrcXprType::Mode>(src.matrix(), tmp);
282 template<
int Mode,
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
290 typedef typename LhsEval::InnerIterator LhsIterator;
297 || ( (Mode&
Upper) && !LhsIsRowMajor)
298 || ( (Mode&
Lower) && LhsIsRowMajor),
299 ProcessSecondHalf = !ProcessFirstHalf
302 SparseLhsTypeNested lhs_nested(lhs);
303 LhsEval lhsEval(lhs_nested);
306 for (
Index k=0; k<rhs.cols(); ++k)
308 for (
Index j=0;
j<lhs.outerSize(); ++
j)
310 LhsIterator
i(lhsEval,
j);
312 if (ProcessSecondHalf)
314 while (i && i.index()<
j) ++i;
315 if(i && i.index()==
j)
317 res.coeffRef(
j,k) += alpha * i.value() * rhs.coeff(
j,k);
326 for(; (ProcessFirstHalf ? i && i.index() <
j :
i) ; ++
i)
328 LhsScalar lhs_ij = i.value();
330 res_j += lhs_ij * rhs.coeff(i.index(),k);
333 res.coeffRef(
j,k) += alpha * res_j;
336 if (ProcessFirstHalf && i && (i.index()==
j))
337 res.coeffRef(
j,k) += alpha * i.value() * rhs.coeff(
j,k);
343 template<
typename LhsView,
typename Rhs,
int ProductType>
345 :
generic_product_impl_base<LhsView, Rhs, generic_product_impl<LhsView, Rhs, SparseSelfAdjointShape, DenseShape, ProductType> >
347 template<
typename Dest>
350 typedef typename LhsView::_MatrixTypeNested
Lhs;
353 LhsNested lhsNested(lhsView.matrix());
354 RhsNested rhsNested(rhs);
356 internal::sparse_selfadjoint_time_dense_product<LhsView::Mode>(lhsNested, rhsNested, dst,
alpha);
360 template<
typename Lhs,
typename RhsView,
int ProductType>
362 :
generic_product_impl_base<Lhs, RhsView, generic_product_impl<Lhs, RhsView, DenseShape, SparseSelfAdjointShape, ProductType> >
364 template<
typename Dest>
367 typedef typename RhsView::_MatrixTypeNested
Rhs;
370 LhsNested lhsNested(lhs);
371 RhsNested rhsNested(rhsView.matrix());
375 internal::sparse_selfadjoint_time_dense_product<RhsView::TransposeMode>(rhsNested.transpose(), lhsNested.transpose(), dstT,
alpha);
382 template<
typename LhsView,
typename Rhs,
int ProductTag>
384 :
public evaluator<typename Product<typename Rhs::PlainObject, Rhs, DefaultProduct>::PlainObject>
391 : m_lhs(xpr.lhs()), m_result(xpr.
rows(), xpr.
cols())
393 ::new (static_cast<Base*>(
this)) Base(m_result);
402 template<
typename Lhs,
typename RhsView,
int ProductTag>
404 :
public evaluator<typename Product<Lhs, typename Lhs::PlainObject, DefaultProduct>::PlainObject>
411 : m_rhs(xpr.rhs()), m_result(xpr.
rows(), xpr.
cols())
413 ::new (static_cast<Base*>(
this)) Base(m_result);
429 template<
int Mode,
typename MatrixType,
int DestOrder>
432 typedef typename MatrixType::StorageIndex StorageIndex;
439 MatEval matEval(mat);
442 StorageOrderMatch =
int(Dest::IsRowMajor) ==
int(MatrixType::IsRowMajor)
449 dest.resize(size,size);
453 for(MatIterator it(matEval,
j); it; ++it)
460 count[StorageOrderMatch ? jp : ip]++;
463 else if(( Mode==
Lower && r>c) || ( Mode==
Upper && r<c))
470 Index nnz = count.sum();
473 dest.resizeNonZeros(nnz);
474 dest.outerIndexPtr()[0] = 0;
476 dest.outerIndexPtr()[
j+1] = dest.outerIndexPtr()[
j] + count[
j];
478 count[
j] = dest.outerIndexPtr()[
j];
481 for(StorageIndex
j = 0;
j<
size; ++
j)
483 for(MatIterator it(matEval,
j); it; ++it)
485 StorageIndex
i = internal::convert_index<StorageIndex>(it.index());
489 StorageIndex jp = perm ? perm[
j] :
j;
490 StorageIndex ip = perm ? perm[
i] :
i;
494 Index k = count[StorageOrderMatch ? jp : ip]++;
495 dest.innerIndexPtr()[k] = StorageOrderMatch ? ip : jp;
496 dest.valuePtr()[k] = it.value();
500 Index k = count[ip]++;
501 dest.innerIndexPtr()[k] = ip;
502 dest.valuePtr()[k] = it.value();
504 else if(( (Mode&
Lower)==Lower && r>c) || ( (Mode&
Upper)==Upper && r<c))
506 if(!StorageOrderMatch)
508 Index k = count[jp]++;
509 dest.innerIndexPtr()[k] = ip;
510 dest.valuePtr()[k] = it.value();
512 dest.innerIndexPtr()[k] = jp;
519 template<
int _SrcMode,
int _DstMode,
typename MatrixType,
int DstOrder>
522 typedef typename MatrixType::StorageIndex StorageIndex;
531 StorageOrderMatch =
int(SrcOrder) ==
int(DstOrder),
536 MatEval matEval(mat);
541 dest.resize(size,size);
542 for(StorageIndex
j = 0;
j<
size; ++
j)
544 StorageIndex jp = perm ? perm[
j] :
j;
545 for(MatIterator it(matEval,
j); it; ++it)
547 StorageIndex
i = it.index();
548 if((
int(SrcMode)==
int(
Lower) && i<
j) || (
int(SrcMode)==
int(
Upper) && i>
j))
551 StorageIndex ip = perm ? perm[
i] :
i;
555 dest.outerIndexPtr()[0] = 0;
557 dest.outerIndexPtr()[
j+1] = dest.outerIndexPtr()[
j] + count[
j];
558 dest.resizeNonZeros(dest.outerIndexPtr()[
size]);
560 count[
j] = dest.outerIndexPtr()[
j];
562 for(StorageIndex
j = 0;
j<
size; ++
j)
565 for(MatIterator it(matEval,
j); it; ++it)
567 StorageIndex
i = it.index();
568 if((
int(SrcMode)==
int(
Lower) && i<
j) || (
int(SrcMode)==
int(
Upper) && i>
j))
571 StorageIndex jp = perm ? perm[
j] :
j;
572 StorageIndex ip = perm? perm[
i] :
i;
578 if( ((
int(DstMode)==
int(
Lower) && ip<jp) || (
int(DstMode)==
int(
Upper) && ip>jp)))
581 dest.valuePtr()[k] = it.value();
592 template<
typename MatrixType,
int Mode>
598 template<
typename MatrixType,
int Mode>
600 :
public EigenBase<SparseSymmetricPermutationProduct<MatrixType,Mode> >
617 : m_matrix(mat), m_perm(perm)
623 const NestedExpression&
matrix()
const {
return m_matrix; }
624 const Perm&
perm()
const {
return m_perm; }
634 template<
typename DstXprType,
typename MatrixType,
int Mode,
typename Scalar>
638 typedef typename DstXprType::StorageIndex
DstIndex;
639 template<
int Options>
644 internal::permute_symm_to_fullsymm<Mode>(src.
matrix(),tmp,src.
perm().
indices().data());
648 template<
typename DestType,
unsigned int DestMode>
659 #endif // EIGEN_SPARSE_SELFADJOINTVIEW_H
EigenBase< SparseSelfAdjointView > Base
XprType::PlainObject PlainObject
Product< SparseSelfAdjointView, OtherDerived > operator*(const SparseMatrixBase< OtherDerived > &rhs) const
Expression of the product of two arbitrary matrices or vectors.
product_evaluator(const XprType &xpr)
SparseSelfAdjointView(MatrixType &matrix)
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()
Namespace containing all symbols from the Eigen library.
MatrixTypeNested m_matrix
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)
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
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
AnnoyingScalar conj(const AnnoyingScalar &x)
XprType::PlainObject PlainObject
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
const NestedExpression & matrix() const
SparseSelfAdjointView & operator=(const SparseSelfAdjointView &src)
Base class of any sparse matrices or sparse expressions.
storage_kind_to_evaluator_kind< typename MatrixType::StorageKind >::Kind Kind
const _MatrixTypeNested & matrix() const
static void run(SparseMatrix< Scalar, Options, DstIndex > &dst, const SrcXprType &src, const internal::assign_op< Scalar, typename MatrixType::Scalar > &)
const IndicesType & indices() const
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
idx_t idx_t idx_t idx_t idx_t * perm
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)
const AdjointReturnType adjoint() const
Product< Lhs, RhsView, DefaultProduct > XprType
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)
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
EIGEN_CONSTEXPR Index size(const T &x)
Product< SparseSelfAdjointView, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
static void run(SparseMatrix< DestScalar, StorageOrder, StorageIndex > &dst, const SrcXprType &src, const internal::add_assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > &)
ConstSelfAdjointViewReturnType< UpLo >::Type selfadjointView() const
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 > &)
const Perm & perm() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment_no_alias_no_transpose(Dst &dst, const Src &src, const Func &func)
evaluator< PlainObject > Base
SparseSymmetricPermutationProduct< _MatrixTypeNested, Mode > twistedBy(const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
Matrix< StorageIndex, Dynamic, 1 > VectorI
internal::assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > AssignOpType
const Derived & derived() const
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
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const LhsNestedCleaned & lhs() const
Generic expression where a coefficient-wise unary operator is applied to an expression.
internal::remove_all< MatrixTypeNested >::type NestedExpression
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const RhsNestedCleaned & rhs() const
MatrixType::Scalar Scalar
MatrixTypeNested m_matrix
Base class for all dense matrices, vectors, and expressions.
Product< LhsView, Rhs, DefaultProduct > XprType
void resize(Index rows, Index cols)
#define EIGEN_ONLY_USED_FOR_DEBUG(x)