10#ifndef EIGEN_SPARSE_SELFADJOINTVIEW_H
11#define EIGEN_SPARSE_SELFADJOINTVIEW_H
31template<
typename MatrixType,
unsigned int Mode>
35template<
int SrcMode,
int DstMode,
typename MatrixType,
int DestOrder>
38template<
int Mode,
typename MatrixType,
int DestOrder>
44 :
public EigenBase<SparseSelfAdjointView<MatrixType,_Mode> >
56 typedef typename MatrixType::Scalar Scalar;
57 typedef typename MatrixType::StorageIndex StorageIndex;
60 typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
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>
135 internal::call_assignment_no_alias_no_transpose(*
this,
permutedMatrix);
139 SparseSelfAdjointView& operator=(
const SparseSelfAdjointView& src)
141 PermutationMatrix<Dynamic,Dynamic,StorageIndex> pnull;
142 return *
this = src.twistedBy(pnull);
146 EIGEN_DEFAULT_COPY_CONSTRUCTOR(SparseSelfAdjointView)
148 template<
typename SrcMatrixType,
unsigned int SrcMode>
149 SparseSelfAdjointView& operator=(
const SparseSelfAdjointView<SrcMatrixType,SrcMode>& src)
151 PermutationMatrix<Dynamic,Dynamic,StorageIndex> pnull;
152 return *
this = src.twistedBy(pnull);
157 EIGEN_ONLY_USED_FOR_DEBUG(rows);
158 EIGEN_ONLY_USED_FOR_DEBUG(cols);
159 eigen_assert(rows == this->rows() && cols == this->cols()
160 &&
"SparseSelfadjointView::resize() does not actually allow to resize.");
165 MatrixTypeNested m_matrix;
169 template<
typename Dest>
void evalTo(Dest &)
const;
176template<
typename Derived>
177template<
unsigned int UpLo>
178typename SparseMatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type SparseMatrixBase<Derived>::selfadjointView()
const
180 return SparseSelfAdjointView<const Derived, UpLo>(derived());
183template<
typename Derived>
184template<
unsigned int UpLo>
185typename SparseMatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type SparseMatrixBase<Derived>::selfadjointView()
187 return SparseSelfAdjointView<Derived, UpLo>(derived());
194template<
typename MatrixType,
unsigned int Mode>
195template<
typename DerivedU>
196SparseSelfAdjointView<MatrixType,Mode>&
197SparseSelfAdjointView<MatrixType,Mode>::rankUpdate(
const SparseMatrixBase<DerivedU>& u,
const Scalar& alpha)
201 m_matrix = tmp.template triangularView<Mode>();
203 m_matrix += alpha * tmp.template triangularView<Mode>();
213template<
typename MatrixType,
unsigned int Mode>
225template<
typename DstXprType,
typename SrcXprType,
typename Functor>
228 typedef typename DstXprType::StorageIndex StorageIndex;
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>
243 call_assignment_no_alias_no_transpose(
dst, tmp, func);
246 template<
typename DestScalar,
int StorageOrder>
255 template<
typename DestScalar,
int StorageOrder>
264 template<
typename DestScalar>
269 internal::permute_symm_to_fullsymm<SrcXprType::Mode>(
src.matrix(), tmp);
282template<
int Mode,
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
285 EIGEN_ONLY_USED_FOR_DEBUG(alpha);
290 typedef typename LhsEval::InnerIterator LhsIterator;
291 typedef typename SparseLhsType::Scalar LhsScalar;
302 SparseLhsTypeNested lhs_nested(lhs);
303 LhsEval lhsEval(lhs_nested);
306 for (
Index k=0; k<rhs.cols(); ++k)
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);
323 typename ScalarBinaryOpTraits<AlphaType, typename DenseRhsType::Scalar>::ReturnType rhs_j(alpha*rhs(j,k));
325 typename DenseResType::Scalar res_j(0);
326 for(; (ProcessFirstHalf ? i && i.index() < j : i) ; ++i)
328 LhsScalar lhs_ij = i.value();
329 if(!LhsIsRowMajor) lhs_ij = numext::conj(lhs_ij);
330 res_j += lhs_ij * rhs.coeff(i.index(),k);
331 res(i.index(),k) += numext::conj(lhs_ij) * rhs_j;
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);
343template<
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>
348 static void scaleAndAddTo(
Dest&
dst,
const LhsView&
lhsView,
const Rhs& rhs,
const typename Dest::Scalar& alpha)
350 typedef typename LhsView::_MatrixTypeNested Lhs;
360template<
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>
365 static void scaleAndAddTo(
Dest&
dst,
const Lhs& lhs,
const RhsView&
rhsView,
const typename Dest::Scalar& alpha)
367 typedef typename RhsView::_MatrixTypeNested Rhs;
382template<
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);
398 typename Rhs::PlainObject m_lhs;
402template<
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);
418 typename Lhs::PlainObject m_rhs;
429template<
int Mode,
typename MatrixType,
int DestOrder>
432 typedef typename MatrixType::StorageIndex StorageIndex;
433 typedef typename MatrixType::Scalar Scalar;
437 typedef typename evaluator<MatrixType>::InnerIterator
MatIterator;
442 StorageOrderMatch = int(Dest::IsRowMajor) == int(MatrixType::IsRowMajor)
445 Index size = mat.rows();
449 dest.resize(size,size);
450 for(
Index j = 0; j<size; ++j)
452 Index jp = perm ? perm[j] : j;
453 for(MatIterator it(matEval,j); it; ++it)
455 Index i = it.index();
458 Index ip = perm ? perm[i] : i;
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;
475 for(
Index j=0; j<size; ++j)
476 dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
477 for(
Index j=0; j<size; ++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();
506 if(!StorageOrderMatch)
508 Index k = count[jp]++;
509 dest.innerIndexPtr()[k] = ip;
510 dest.valuePtr()[k] = it.value();
512 dest.innerIndexPtr()[k] = jp;
513 dest.valuePtr()[k] = numext::conj(it.value());
519template<
int _SrcMode,
int _DstMode,
typename MatrixType,
int DstOrder>
520void permute_symm_to_symm(
const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DstOrder,typename MatrixType::StorageIndex>& _dest,
const typename MatrixType::StorageIndex* perm)
522 typedef typename MatrixType::StorageIndex StorageIndex;
523 typedef typename MatrixType::Scalar Scalar;
524 SparseMatrix<Scalar,DstOrder,StorageIndex>& dest(_dest.derived());
526 typedef evaluator<MatrixType> MatEval;
527 typedef typename evaluator<MatrixType>::InnerIterator MatIterator;
531 StorageOrderMatch = int(SrcOrder) == int(DstOrder),
536 MatEval matEval(mat);
538 Index size = mat.rows();
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;
552 count[int(DstMode)==int(
Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++;
555 dest.outerIndexPtr()[0] = 0;
556 for(
Index j=0; j<size; ++j)
557 dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
558 dest.resizeNonZeros(dest.outerIndexPtr()[size]);
559 for(
Index j=0; j<size; ++j)
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;
574 Index k = count[int(DstMode)==int(
Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++;
575 dest.innerIndexPtr()[k] = int(DstMode)==int(
Lower) ? (std::max)(ip,jp) : (std::min)(ip,jp);
578 if( ((
int(DstMode)==
int(
Lower) && ip<jp) || (
int(DstMode)==
int(
Upper) && ip>jp)))
579 dest.valuePtr()[k] = numext::conj(it.value());
581 dest.valuePtr()[k] = it.value();
592template<
typename MatrixType,
int Mode>
598template<
typename MatrixType,
int Mode>
600 :
public EigenBase<SparseSymmetricPermutationProduct<MatrixType,Mode> >
603 typedef typename MatrixType::Scalar Scalar;
604 typedef typename MatrixType::StorageIndex StorageIndex;
613 typedef typename MatrixType::Nested MatrixTypeNested;
614 typedef typename internal::remove_all<MatrixTypeNested>::type NestedExpression;
617 : m_matrix(
mat), m_perm(perm)
620 inline Index rows()
const {
return m_matrix.rows(); }
621 inline Index cols()
const {
return m_matrix.cols(); }
623 const NestedExpression& matrix()
const {
return m_matrix; }
624 const Perm& perm()
const {
return m_perm; }
627 MatrixTypeNested m_matrix;
634template<
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>
651 internal::permute_symm_to_symm<Mode,DestMode>(
src.matrix(),
dst.matrix(),
src.perm().indices().data());
EIGEN_DEVICE_FUNC void resize(Index newSize)
Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods...
Definition DenseBase.h:246
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerSize() const
Definition DenseBase.h:223
EIGEN_DEVICE_FUNC Derived & setZero()
Sets all coefficients in this expression to zero.
Definition CwiseNullaryOp.h:546
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Definition Transpose.h:182
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const
Definition Transpose.h:221
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:75
A versatible sparse matrix representation.
Definition SparseMatrix.h:98
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition SparseSelfAdjointView.h:45
friend Product< OtherDerived, SparseSelfAdjointView > operator*(const MatrixBase< OtherDerived > &lhs, const SparseSelfAdjointView &rhs)
Efficient dense vector/matrix times sparse self-adjoint matrix product.
Definition SparseSelfAdjointView.h:109
SparseSelfAdjointView & rankUpdate(const SparseMatrixBase< DerivedU > &u, const Scalar &alpha=Scalar(1))
Perform a symmetric rank K update of the selfadjoint matrix *this: where u is a vector or matrix.
Product< SparseSelfAdjointView, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
Efficient sparse self-adjoint matrix times dense vector/matrix product.
Definition SparseSelfAdjointView.h:101
Product< SparseSelfAdjointView, OtherDerived > operator*(const SparseMatrixBase< OtherDerived > &rhs) const
Definition SparseSelfAdjointView.h:81
friend Product< OtherDerived, SparseSelfAdjointView > operator*(const SparseMatrixBase< OtherDerived > &lhs, const SparseSelfAdjointView &rhs)
Definition SparseSelfAdjointView.h:93
SparseSymmetricPermutationProduct< _MatrixTypeNested, Mode > twistedBy(const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
Definition SparseSelfAdjointView.h:127
Definition SparseSelfAdjointView.h:601
@ Lower
View matrix as a lower triangular matrix.
Definition Constants.h:209
@ Upper
View matrix as an upper triangular matrix.
Definition Constants.h:211
@ ColMajor
Storage order is column major (see TopicStorageOrders).
Definition Constants.h:319
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition Constants.h:321
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.hpp:24418
Definition Constants.h:528
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition EigenBase.h:30
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:39
Definition Constants.h:537
Definition AssignEvaluator.h:817
Definition AssignEvaluator.h:824
Definition Constants.h:542
Definition SparseAssign.h:61
Definition SparseSelfAdjointView.h:220
Definition SparseUtil.h:138
Definition AssignmentFunctors.h:46
Definition AssignmentFunctors.h:21
Definition CoreEvaluators.h:80
Definition CoreEvaluators.h:91
Definition ProductEvaluators.h:344
Definition ProductEvaluators.h:86
Definition ForwardDeclarations.h:164
Definition AssignmentFunctors.h:67
Definition ForwardDeclarations.h:17
Definition inference.c:32