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> >
55 typedef typename MatrixType::Scalar Scalar;
56 typedef typename MatrixType::StorageIndex StorageIndex;
58 typedef typename MatrixType::Nested MatrixTypeNested;
63 eigen_assert(rows()==cols() &&
"SelfAdjointView is only for squared matrices");
66 inline Index rows()
const {
return m_matrix.rows(); }
67 inline Index cols()
const {
return m_matrix.cols(); }
78 template<
typename OtherDerived>
90 template<
typename OtherDerived>
friend
98 template<
typename OtherDerived>
106 template<
typename OtherDerived>
friend
121 template<
typename DerivedU>
131 template<
typename SrcMatrixType,
int SrcMode>
134 internal::call_assignment_no_alias_no_transpose(*
this,
permutedMatrix);
138 SparseSelfAdjointView& operator=(
const SparseSelfAdjointView& src)
140 PermutationMatrix<Dynamic,Dynamic,StorageIndex> pnull;
141 return *
this = src.twistedBy(pnull);
144 template<
typename SrcMatrixType,
unsigned int SrcMode>
145 SparseSelfAdjointView& operator=(
const SparseSelfAdjointView<SrcMatrixType,SrcMode>& src)
147 PermutationMatrix<Dynamic,Dynamic,StorageIndex> pnull;
148 return *
this = src.twistedBy(pnull);
153 EIGEN_ONLY_USED_FOR_DEBUG(rows);
154 EIGEN_ONLY_USED_FOR_DEBUG(cols);
155 eigen_assert(rows == this->rows() && cols == this->cols()
156 &&
"SparseSelfadjointView::resize() does not actually allow to resize.");
161 typename MatrixType::Nested m_matrix;
165 template<
typename Dest>
void evalTo(Dest &)
const;
172template<
typename Derived>
173template<
unsigned int UpLo>
174typename SparseMatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type SparseMatrixBase<Derived>::selfadjointView()
const
176 return SparseSelfAdjointView<const Derived, UpLo>(derived());
179template<
typename Derived>
180template<
unsigned int UpLo>
181typename SparseMatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type SparseMatrixBase<Derived>::selfadjointView()
183 return SparseSelfAdjointView<Derived, UpLo>(derived());
190template<
typename MatrixType,
unsigned int Mode>
191template<
typename DerivedU>
192SparseSelfAdjointView<MatrixType,Mode>&
193SparseSelfAdjointView<MatrixType,Mode>::rankUpdate(
const SparseMatrixBase<DerivedU>& u,
const Scalar& alpha)
197 m_matrix.const_cast_derived() = tmp.template triangularView<Mode>();
199 m_matrix.const_cast_derived() += alpha * tmp.template triangularView<Mode>();
209template<
typename MatrixType,
unsigned int Mode>
215 static const int AssumeAliasing = 0;
223template<
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Scalar>
226 typedef typename DstXprType::StorageIndex StorageIndex;
227 template<
typename DestScalar,
int StorageOrder>
230 internal::permute_symm_to_fullsymm<SrcXprType::Mode>(
src.matrix(),
dst);
233 template<
typename DestScalar>
238 internal::permute_symm_to_fullsymm<SrcXprType::Mode>(
src.matrix(), tmp);
251template<
int Mode,
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
254 EIGEN_ONLY_USED_FOR_DEBUG(alpha);
256 eigen_assert(alpha==
AlphaType(1) &&
"alpha != 1 is not implemented yet, sorry");
259 typedef typename evaluator<SparseLhsType>::InnerIterator LhsIterator;
260 typedef typename SparseLhsType::Scalar LhsScalar;
271 LhsEval lhsEval(lhs);
273 for (Index j=0; j<lhs.outerSize(); ++j)
275 LhsIterator i(lhsEval,j);
276 if (ProcessSecondHalf)
278 while (i && i.index()<j) ++i;
279 if(i && i.index()==j)
281 res.row(j) += i.value() * rhs.row(j);
285 for(; (ProcessFirstHalf ? i && i.index() < j : i) ; ++i)
287 Index a = LhsIsRowMajor ? j : i.index();
288 Index b = LhsIsRowMajor ? i.index() : j;
289 LhsScalar v = i.value();
290 res.row(a) += (v) * rhs.row(b);
291 res.row(b) += numext::conj(v) * rhs.row(a);
293 if (ProcessFirstHalf && i && (i.index()==j))
294 res.row(j) += i.value() * rhs.row(j);
299template<
typename LhsView,
typename Rhs,
int ProductType>
302 template<
typename Dest>
305 typedef typename LhsView::_MatrixTypeNested Lhs;
312 internal::sparse_selfadjoint_time_dense_product<LhsView::Mode>(
lhsNested,
rhsNested,
dst,
typename Dest::Scalar(1));
316template<
typename Lhs,
typename RhsView,
int ProductType>
319 template<
typename Dest>
322 typedef typename RhsView::_MatrixTypeNested Rhs;
331 internal::sparse_selfadjoint_time_dense_product<RhsView::Mode>(
rhsNested.transpose(),
lhsNested.transpose(),
dstT,
typename Dest::Scalar(1));
338template<
typename LhsView,
typename Rhs,
int ProductTag>
340 :
public evaluator<typename Product<typename Rhs::PlainObject, Rhs, DefaultProduct>::PlainObject>
343 typedef typename XprType::PlainObject PlainObject;
347 : m_lhs(
xpr.lhs()), m_result(
xpr.rows(),
xpr.cols())
349 ::new (
static_cast<Base*
>(
this))
Base(m_result);
354 typename Rhs::PlainObject m_lhs;
355 PlainObject m_result;
358template<
typename Lhs,
typename RhsView,
int ProductTag>
360 :
public evaluator<typename Product<Lhs, typename Lhs::PlainObject, DefaultProduct>::PlainObject>
363 typedef typename XprType::PlainObject PlainObject;
367 : m_rhs(
xpr.rhs()), m_result(
xpr.rows(),
xpr.cols())
369 ::new (
static_cast<Base*
>(
this))
Base(m_result);
374 typename Lhs::PlainObject m_rhs;
375 PlainObject m_result;
385template<
int Mode,
typename MatrixType,
int DestOrder>
388 typedef typename MatrixType::StorageIndex StorageIndex;
389 typedef typename MatrixType::Scalar Scalar;
395 StorageOrderMatch = int(Dest::IsRowMajor) == int(MatrixType::IsRowMajor)
398 Index size = mat.rows();
402 dest.resize(size,size);
403 for(Index j = 0; j<size; ++j)
405 Index jp = perm ? perm[j] : j;
406 for(
typename MatrixType::InnerIterator it(mat,j); it; ++it)
408 Index i = it.index();
411 Index ip = perm ? perm[i] : i;
413 count[StorageOrderMatch ? jp : ip]++;
416 else if(( Mode==
Lower && r>c) || ( Mode==
Upper && r<c))
423 Index nnz = count.sum();
426 dest.resizeNonZeros(nnz);
427 dest.outerIndexPtr()[0] = 0;
428 for(Index j=0; j<size; ++j)
429 dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
430 for(Index j=0; j<size; ++j)
431 count[j] = dest.outerIndexPtr()[j];
434 for(StorageIndex j = 0; j<size; ++j)
436 for(
typename MatrixType::InnerIterator it(mat,j); it; ++it)
438 StorageIndex i = internal::convert_index<StorageIndex>(it.index());
442 StorageIndex jp = perm ? perm[j] : j;
443 StorageIndex ip = perm ? perm[i] : i;
447 Index k = count[StorageOrderMatch ? jp : ip]++;
448 dest.innerIndexPtr()[k] = StorageOrderMatch ? ip : jp;
449 dest.valuePtr()[k] = it.value();
453 Index k = count[ip]++;
454 dest.innerIndexPtr()[k] = ip;
455 dest.valuePtr()[k] = it.value();
459 if(!StorageOrderMatch)
461 Index k = count[jp]++;
462 dest.innerIndexPtr()[k] = ip;
463 dest.valuePtr()[k] = it.value();
465 dest.innerIndexPtr()[k] = jp;
466 dest.valuePtr()[k] = numext::conj(it.value());
472template<
int _SrcMode,
int _DstMode,
typename MatrixType,
int DstOrder>
473void permute_symm_to_symm(
const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DstOrder,typename MatrixType::StorageIndex>& _dest,
const typename MatrixType::StorageIndex* perm)
475 typedef typename MatrixType::StorageIndex StorageIndex;
476 typedef typename MatrixType::Scalar Scalar;
477 SparseMatrix<Scalar,DstOrder,StorageIndex>& dest(_dest.derived());
481 StorageOrderMatch = int(SrcOrder) == int(DstOrder),
486 Index size = mat.rows();
489 dest.resize(size,size);
490 for(StorageIndex j = 0; j<size; ++j)
492 StorageIndex jp = perm ? perm[j] : j;
493 for(
typename MatrixType::InnerIterator it(mat,j); it; ++it)
495 StorageIndex i = it.index();
496 if((
int(SrcMode)==
int(
Lower) && i<j) || (
int(SrcMode)==
int(
Upper) && i>j))
499 StorageIndex ip = perm ? perm[i] : i;
500 count[int(DstMode)==int(
Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++;
503 dest.outerIndexPtr()[0] = 0;
504 for(Index j=0; j<size; ++j)
505 dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j];
506 dest.resizeNonZeros(dest.outerIndexPtr()[size]);
507 for(Index j=0; j<size; ++j)
508 count[j] = dest.outerIndexPtr()[j];
510 for(StorageIndex j = 0; j<size; ++j)
513 for(
typename MatrixType::InnerIterator it(mat,j); it; ++it)
515 StorageIndex i = it.index();
516 if((
int(SrcMode)==int(
Lower) && i<j) || (
int(SrcMode)==int(
Upper) && i>j))
519 StorageIndex jp = perm ? perm[j] : j;
520 StorageIndex ip = perm? perm[i] : i;
522 Index k = count[int(DstMode)==int(
Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++;
523 dest.innerIndexPtr()[k] = int(DstMode)==int(
Lower) ? (std::max)(ip,jp) : (std::min)(ip,jp);
526 if( ((
int(DstMode)==
int(
Lower) && ip<jp) || (
int(DstMode)==
int(
Upper) && ip>jp)))
527 dest.valuePtr()[k] = numext::conj(it.value());
529 dest.valuePtr()[k] = it.value();
540template<
typename MatrixType,
int Mode>
546template<
typename MatrixType,
int Mode>
548 :
public EigenBase<SparseSymmetricPermutationProduct<MatrixType,Mode> >
551 typedef typename MatrixType::Scalar Scalar;
552 typedef typename MatrixType::StorageIndex StorageIndex;
561 typedef typename MatrixType::Nested MatrixTypeNested;
565 : m_matrix(
mat), m_perm(perm)
568 inline Index rows()
const {
return m_matrix.rows(); }
569 inline Index cols()
const {
return m_matrix.cols(); }
572 const Perm& perm()
const {
return m_perm; }
575 MatrixTypeNested m_matrix;
582template<
typename DstXprType,
typename MatrixType,
int Mode,
typename Scalar>
586 typedef typename DstXprType::StorageIndex DstIndex;
587 template<
int Options>
592 internal::permute_symm_to_fullsymm<Mode>(
src.matrix(),tmp,
src.perm().indices().data());
596 template<
typename DestType,
unsigned int DestMode>
599 internal::permute_symm_to_symm<Mode,DestMode>(
src.matrix(),
dst.matrix(),
src.perm().indices().data());
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:111
Pseudo expression representing a solving operation.
Definition Solve.h:63
A versatible sparse matrix representation.
Definition SparseMatrix.h:94
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:108
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:100
Product< SparseSelfAdjointView, OtherDerived > operator*(const SparseMatrixBase< OtherDerived > &rhs) const
Definition SparseSelfAdjointView.h:80
friend Product< OtherDerived, SparseSelfAdjointView > operator*(const SparseMatrixBase< OtherDerived > &lhs, const SparseSelfAdjointView &rhs)
Definition SparseSelfAdjointView.h:92
SparseSymmetricPermutationProduct< _MatrixTypeNested, Mode > twistedBy(const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
Definition SparseSelfAdjointView.h:126
Definition SparseSelfAdjointView.h:549
@ Lower
View matrix as a lower triangular matrix.
Definition Constants.h:204
@ Upper
View matrix as an upper triangular matrix.
Definition Constants.h:206
@ ColMajor
Storage order is column major (see TopicStorageOrders).
Definition Constants.h:320
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition Constants.h:322
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61
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:511
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition EigenBase.h:29
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:37
Definition Constants.h:520
Definition AssignEvaluator.h:677
Definition AssignEvaluator.h:684
Definition Constants.h:525
Definition SparseAssign.h:61
Definition SparseSelfAdjointView.h:218
Definition SparseUtil.h:138
Definition AssignmentFunctors.h:21
Definition CoreEvaluators.h:75
Definition CoreEvaluators.h:82
Definition ProductEvaluators.h:81
Definition ForwardDeclarations.h:165
Definition ForwardDeclarations.h:17
Definition inference.c:32