10 #ifndef EIGEN_SPARSE_SELFADJOINTVIEW_H
11 #define EIGEN_SPARSE_SELFADJOINTVIEW_H
34 template <
typename MatrixType,
unsigned int Mode>
37 template <
int SrcMode,
int DstMode,
bool NonHermitian,
typename MatrixType,
int DestOrder>
41 const typename MatrixType::StorageIndex* perm = 0);
43 template <
int Mode,
bool NonHermitian,
typename MatrixType,
int DestOrder>
47 const typename MatrixType::StorageIndex* perm = 0);
51 template <
typename MatrixType,
unsigned int Mode_>
86 template <
typename OtherDerived>
98 template <
typename OtherDerived>
105 template <
typename OtherDerived>
111 template <
typename OtherDerived>
125 template <
typename DerivedU>
135 template <
typename SrcMatrixType,
int SrcMode>
149 template <
typename SrcMatrixType,
unsigned int SrcMode>
159 "SparseSelfadjointView::resize() does not actually allow to resize.");
167 template <
typename Dest>
175 template <
typename Derived>
176 template <
unsigned int UpLo>
182 template <
typename Derived>
183 template <
unsigned int UpLo>
193 template <
typename MatrixType,
unsigned int Mode>
194 template <
typename DerivedU>
199 m_matrix =
tmp.template triangularView<Mode>();
201 m_matrix +=
alpha *
tmp.template triangularView<Mode>();
212 template <
typename MatrixType,
unsigned int Mode>
229 template <
typename DstXprType,
typename SrcXprType,
typename Functor>
234 template <
typename DestScalar,
int StorageOrder>
237 internal::permute_symm_to_fullsymm<SrcXprType::Mode, false>(src.matrix(), dst);
242 template <
typename DestScalar,
int StorageOrder,
typename AssignFunc>
244 const AssignFunc&
func) {
250 template <
typename DestScalar,
int StorageOrder>
258 template <
typename DestScalar,
int StorageOrder>
275 template <
int Mode,
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
277 const AlphaType&
alpha) {
283 typedef typename LhsEval::InnerIterator
LhsIterator;
289 ((Mode &
Lower) && LhsIsRowMajor),
290 ProcessSecondHalf = !ProcessFirstHalf
293 SparseLhsTypeNested lhs_nested(lhs);
294 LhsEval lhsEval(lhs_nested);
297 for (
Index k = 0;
k < rhs.cols(); ++
k) {
298 for (
Index j = 0;
j < lhs.outerSize(); ++
j) {
301 if (ProcessSecondHalf) {
302 while (
i &&
i.index() <
j) ++
i;
303 if (
i &&
i.index() ==
j) {
313 for (; (ProcessFirstHalf ?
i &&
i.index() <
j :
i); ++
i) {
314 LhsScalar lhs_ij =
i.value();
316 res_j += lhs_ij * rhs.coeff(
i.index(),
k);
322 if (ProcessFirstHalf &&
i && (
i.index() ==
j))
res.coeffRef(
j,
k) +=
alpha *
i.value() * rhs.coeff(
j,
k);
327 template <
typename LhsView,
typename Rhs,
int ProductType>
330 generic_product_impl<LhsView, Rhs, SparseSelfAdjointShape, DenseShape, ProductType> > {
331 template <
typename Dest>
333 typedef typename LhsView::MatrixTypeNested_
Lhs;
336 LhsNested lhsNested(lhsView.matrix());
337 RhsNested rhsNested(rhs);
339 internal::sparse_selfadjoint_time_dense_product<LhsView::Mode>(lhsNested, rhsNested, dst,
alpha);
343 template <
typename Lhs,
typename RhsView,
int ProductType>
346 generic_product_impl<Lhs, RhsView, DenseShape, SparseSelfAdjointShape, ProductType> > {
347 template <
typename Dest>
349 typedef typename RhsView::MatrixTypeNested_
Rhs;
352 LhsNested lhsNested(lhs);
353 RhsNested rhsNested(rhsView.matrix());
357 internal::sparse_selfadjoint_time_dense_product<RhsView::TransposeMode>(rhsNested.transpose(),
358 lhsNested.transpose(), dstT,
alpha);
365 template <
typename LhsView,
typename Rhs,
int ProductTag>
367 :
public evaluator<typename Product<typename Rhs::PlainObject, Rhs, DefaultProduct>::PlainObject> {
373 internal::construct_at<Base>(
this, m_result);
383 template <
typename Lhs,
typename RhsView,
int ProductTag>
385 :
public evaluator<typename Product<Lhs, typename Lhs::PlainObject, DefaultProduct>::PlainObject> {
391 ::new (
static_cast<Base*
>(
this))
Base(m_result);
393 m_result, xpr.
lhs(), m_rhs);
408 template <
int Mode,
bool NonHermitian,
typename MatrixType,
int DestOrder>
412 const typename MatrixType::StorageIndex* perm) {
413 typedef typename MatrixType::StorageIndex StorageIndex;
420 MatEval matEval(
mat);
422 enum { StorageOrderMatch =
int(Dest::IsRowMajor) ==
int(MatrixType::IsRowMajor) };
431 for (MatIterator it(matEval,
j); it; ++it) {
437 count[StorageOrderMatch ? jp : ip]++;
446 Index nnz = count.sum();
449 dest.resizeNonZeros(nnz);
450 dest.outerIndexPtr()[0] = 0;
451 for (
Index j = 0;
j <
size; ++
j) dest.outerIndexPtr()[
j + 1] = dest.outerIndexPtr()[
j] + count[
j];
452 for (
Index j = 0;
j <
size; ++
j) count[
j] = dest.outerIndexPtr()[
j];
455 for (StorageIndex
j = 0;
j <
size; ++
j) {
456 for (MatIterator it(matEval,
j); it; ++it) {
457 StorageIndex
i = internal::convert_index<StorageIndex>(it.index());
461 StorageIndex jp = perm ? perm[
j] :
j;
462 StorageIndex ip = perm ? perm[
i] :
i;
465 Index k = count[StorageOrderMatch ? jp : ip]++;
466 dest.innerIndexPtr()[
k] = StorageOrderMatch ? ip : jp;
467 dest.valuePtr()[
k] = it.value();
470 dest.innerIndexPtr()[
k] = ip;
471 dest.valuePtr()[
k] = it.value();
473 if (!StorageOrderMatch)
std::swap(ip, jp);
475 dest.innerIndexPtr()[
k] = ip;
476 dest.valuePtr()[
k] = it.value();
478 dest.innerIndexPtr()[
k] = jp;
479 dest.valuePtr()[
k] = (NonHermitian ? it.value() :
numext::conj(it.value()));
485 template <
int SrcMode_,
int DstMode_,
bool NonHermitian,
typename MatrixType,
int DstOrder>
488 const typename MatrixType::StorageIndex* perm) {
489 typedef typename MatrixType::StorageIndex StorageIndex;
498 StorageOrderMatch =
int(SrcOrder) ==
int(DstOrder),
503 MatEval matEval(
mat);
509 for (StorageIndex
j = 0;
j <
size; ++
j) {
510 StorageIndex jp = perm ? perm[
j] :
j;
511 for (MatIterator it(matEval,
j); it; ++it) {
512 StorageIndex
i = it.index();
513 if ((
int(SrcMode) ==
int(
Lower) &&
i <
j) || (
int(SrcMode) ==
int(
Upper) &&
i >
j))
continue;
515 StorageIndex ip = perm ? perm[
i] :
i;
524 for (StorageIndex
j = 0;
j <
size; ++
j) {
525 for (MatIterator it(matEval,
j); it; ++it) {
526 StorageIndex
i = it.index();
529 StorageIndex jp = perm ? perm[
j] :
j;
530 StorageIndex ip = perm ? perm[
i] :
i;
535 if (!StorageOrderMatch)
std::swap(ip, jp);
536 if (((
int(DstMode) ==
int(
Lower) && ip < jp) || (
int(DstMode) ==
int(
Upper) && ip > jp)))
550 template <
typename MatrixType,
int Mode>
555 template <
typename MatrixType,
int Mode>
588 template <
typename DstXprType,
typename MatrixType,
int Mode,
typename Scalar>
592 typedef typename DstXprType::StorageIndex
DstIndex;
593 template <
int Options>
598 internal::permute_symm_to_fullsymm<Mode, false>(src.
matrix(),
tmp, src.
perm().
indices().data());
602 template <
typename DestType,
unsigned int DestMode>
605 internal::permute_symm_to_symm<Mode, DestMode, false>(src.
matrix(), dst.
matrix(), src.
perm().
indices().data());
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
Macro to explicitly define the default copy constructor. This is necessary, because the implicit defi...
Definition: Macros.h:1119
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
Definition: Macros.h:922
#define eigen_assert(x)
Definition: Macros.h:910
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
const IndicesType & indices() const
Definition: PermutationMatrix.h:334
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:202
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const LhsNestedCleaned & lhs() const
Definition: Product.h:230
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const RhsNestedCleaned & rhs() const
Definition: Product.h:231
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:30
const Derived & derived() const
Definition: SparseMatrixBase.h:144
ConstSelfAdjointViewReturnType< UpLo >::Type selfadjointView() const
const AdjointReturnType adjoint() const
Definition: SparseMatrixBase.h:360
const Scalar * valuePtr() const
Definition: SparseMatrix.h:171
void resize(Index rows, Index cols)
Definition: SparseMatrix.h:734
Index rows() const
Definition: SparseMatrix.h:159
void resizeNonZeros(Index size)
Definition: SparseMatrix.h:754
const StorageIndex * outerIndexPtr() const
Definition: SparseMatrix.h:189
const StorageIndex * innerIndexPtr() const
Definition: SparseMatrix.h:180
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition: SparseSelfAdjointView.h:52
std::remove_reference_t< MatrixTypeNested > & matrix()
Definition: SparseSelfAdjointView.h:77
Product< SparseSelfAdjointView, OtherDerived > operator*(const SparseMatrixBase< OtherDerived > &rhs) const
Definition: SparseSelfAdjointView.h:87
SparseSelfAdjointView & operator=(const SparseSelfAdjointView &src)
Definition: SparseSelfAdjointView.h:141
Product< SparseSelfAdjointView, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
Definition: SparseSelfAdjointView.h:106
MatrixType::Scalar Scalar
Definition: SparseSelfAdjointView.h:62
const MatrixTypeNested_ & matrix() const
Definition: SparseSelfAdjointView.h:76
SparseSelfAdjointView & rankUpdate(const SparseMatrixBase< DerivedU > &u, const Scalar &alpha=Scalar(1))
friend Product< OtherDerived, SparseSelfAdjointView > operator*(const SparseMatrixBase< OtherDerived > &lhs, const SparseSelfAdjointView &rhs)
Definition: SparseSelfAdjointView.h:99
SparseSelfAdjointView & operator=(const SparseSelfAdjointView< SrcMatrixType, SrcMode > &src)
Definition: SparseSelfAdjointView.h:150
internal::ref_selector< MatrixType >::non_const_type MatrixTypeNested
Definition: SparseSelfAdjointView.h:65
void evalTo(Dest &) const
Index cols() const
Definition: SparseSelfAdjointView.h:73
friend Product< OtherDerived, SparseSelfAdjointView > operator*(const MatrixBase< OtherDerived > &lhs, const SparseSelfAdjointView &rhs)
Definition: SparseSelfAdjointView.h:112
MatrixTypeNested m_matrix
Definition: SparseSelfAdjointView.h:163
SparseSelfAdjointView & operator=(const SparseSymmetricPermutationProduct< SrcMatrixType, SrcMode > &permutedMatrix)
Definition: SparseSelfAdjointView.h:136
Index rows() const
Definition: SparseSelfAdjointView.h:72
SparseSelfAdjointView(MatrixType &matrix)
Definition: SparseSelfAdjointView.h:68
Matrix< StorageIndex, Dynamic, 1 > VectorI
Definition: SparseSelfAdjointView.h:64
SparseSymmetricPermutationProduct< MatrixTypeNested_, Mode > twistedBy(const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
Definition: SparseSelfAdjointView.h:130
EigenBase< SparseSelfAdjointView > Base
Definition: SparseSelfAdjointView.h:61
internal::remove_all_t< MatrixTypeNested > MatrixTypeNested_
Definition: SparseSelfAdjointView.h:66
void resize(Index rows, Index cols)
Definition: SparseSelfAdjointView.h:155
@ Mode
Definition: SparseSelfAdjointView.h:55
@ RowsAtCompileTime
Definition: SparseSelfAdjointView.h:57
@ TransposeMode
Definition: SparseSelfAdjointView.h:56
@ ColsAtCompileTime
Definition: SparseSelfAdjointView.h:58
MatrixType::StorageIndex StorageIndex
Definition: SparseSelfAdjointView.h:63
Definition: SparseSelfAdjointView.h:556
MatrixType::Nested MatrixTypeNested
Definition: SparseSelfAdjointView.h:570
MatrixType::StorageIndex StorageIndex
Definition: SparseSelfAdjointView.h:559
SparseSymmetricPermutationProduct(const MatrixType &mat, const Perm &perm)
Definition: SparseSelfAdjointView.h:573
const Perm & perm() const
Definition: SparseSelfAdjointView.h:579
MatrixType::Scalar Scalar
Definition: SparseSelfAdjointView.h:558
const NestedExpression & matrix() const
Definition: SparseSelfAdjointView.h:578
internal::remove_all_t< MatrixTypeNested > NestedExpression
Definition: SparseSelfAdjointView.h:571
PermutationMatrix< Dynamic, Dynamic, StorageIndex > Perm
Definition: SparseSelfAdjointView.h:566
MatrixTypeNested m_matrix
Definition: SparseSelfAdjointView.h:582
Index cols() const
Definition: SparseSelfAdjointView.h:576
@ RowsAtCompileTime
Definition: SparseSelfAdjointView.h:561
@ ColsAtCompileTime
Definition: SparseSelfAdjointView.h:562
Matrix< StorageIndex, Dynamic, 1 > VectorI
Definition: SparseSelfAdjointView.h:569
Index rows() const
Definition: SparseSelfAdjointView.h:575
const Perm & m_perm
Definition: SparseSelfAdjointView.h:583
Expression of the transpose of a matrix.
Definition: Transpose.h:56
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
@ DefaultProduct
Definition: Constants.h:503
@ Lower
Definition: Constants.h:211
@ Upper
Definition: Constants.h:213
@ ColMajor
Definition: Constants.h:318
@ RowMajor
Definition: Constants.h:320
const unsigned int RowMajorBit
Definition: Constants.h:70
RealScalar alpha
Definition: level1_cplx_impl.h:151
EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:117
char char char int int * k
Definition: level2_impl.h:374
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
void sparse_selfadjoint_time_dense_product(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const AlphaType &alpha)
Definition: SparseSelfAdjointView.h:276
@ Lhs
Definition: TensorContractionMapper.h:20
@ Rhs
Definition: TensorContractionMapper.h:20
void permute_symm_to_fullsymm(const MatrixType &mat, SparseMatrix< typename MatrixType::Scalar, DestOrder, typename MatrixType::StorageIndex > &_dest, const typename MatrixType::StorageIndex *perm=0)
Definition: SparseSelfAdjointView.h:409
void permute_symm_to_symm(const MatrixType &mat, SparseMatrix< typename MatrixType::Scalar, DestOrder, typename MatrixType::StorageIndex > &_dest, const typename MatrixType::StorageIndex *perm=0)
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment_no_alias_no_transpose(Dst &dst, const Src &src, const Func &func)
Definition: AssignEvaluator.h:857
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
auto run(Kernel kernel, Args &&... args) -> decltype(kernel(args...))
Definition: gpu_test_helper.h:414
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
int c
Definition: calibrate.py:100
Definition: Eigen_Colamd.h:49
Type
Type of JSON value.
Definition: rapidjson.h:513
Definition: Constants.h:540
Definition: EigenBase.h:33
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:1043
Definition: Constants.h:570
Sparse2Sparse Kind
Definition: SparseSelfAdjointView.h:226
SparseSelfAdjoint2Sparse Kind
Definition: SparseSelfAdjointView.h:222
Definition: AssignEvaluator.h:760
static void run(SparseSelfAdjointView< DestType, DestMode > &dst, const SrcXprType &src, const internal::assign_op< Scalar, typename MatrixType::Scalar > &)
Definition: SparseSelfAdjointView.h:603
SparseSymmetricPermutationProduct< MatrixType, Mode > SrcXprType
Definition: SparseSelfAdjointView.h:591
static void run(SparseMatrix< Scalar, Options, DstIndex > &dst, const SrcXprType &src, const internal::assign_op< Scalar, typename MatrixType::Scalar > &)
Definition: SparseSelfAdjointView.h:594
DstXprType::StorageIndex DstIndex
Definition: SparseSelfAdjointView.h:592
static void run(SparseMatrix< DestScalar, StorageOrder, StorageIndex > &dst, const SrcXprType &src, const internal::add_assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > &)
Definition: SparseSelfAdjointView.h:251
DstXprType::StorageIndex StorageIndex
Definition: SparseSelfAdjointView.h:231
static void run(SparseMatrix< DestScalar, StorageOrder, StorageIndex > &dst, const SrcXprType &src, const AssignOpType &)
Definition: SparseSelfAdjointView.h:235
internal::assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > AssignOpType
Definition: SparseSelfAdjointView.h:232
static void run(SparseMatrix< DestScalar, StorageOrder, StorageIndex > &dst, const SrcXprType &src, const AssignFunc &func)
Definition: SparseSelfAdjointView.h:243
static void run(SparseMatrix< DestScalar, StorageOrder, StorageIndex > &dst, const SrcXprType &src, const internal::sub_assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > &)
Definition: SparseSelfAdjointView.h:259
Definition: AssignEvaluator.h:773
Definition: Constants.h:577
Definition: SparseAssign.h:60
Definition: SparseSelfAdjointView.h:218
Definition: SparseUtil.h:155
Template functor for scalar/packet assignment with addition.
Definition: AssignmentFunctors.h:52
Template functor for scalar/packet assignment.
Definition: AssignmentFunctors.h:25
storage_kind_to_evaluator_kind< typename MatrixType::StorageKind >::Kind Kind
Definition: SparseSelfAdjointView.h:214
SparseSelfAdjointShape Shape
Definition: SparseSelfAdjointView.h:215
Definition: CoreEvaluators.h:95
Definition: CoreEvaluators.h:104
static void scaleAndAddTo(Dest &dst, const LhsView &lhsView, const Rhs &rhs, const typename Dest::Scalar &alpha)
Definition: SparseSelfAdjointView.h:332
static void scaleAndAddTo(Dest &dst, const Lhs &lhs, const RhsView &rhsView, const typename Dest::Scalar &alpha)
Definition: SparseSelfAdjointView.h:348
Definition: ProductEvaluators.h:341
Definition: ProductEvaluators.h:78
std::conditional_t< Evaluate, PlainObject, typename ref_selector< T >::type > type
Definition: XprHelper.h:549
product_evaluator(const XprType &xpr)
Definition: SparseSelfAdjointView.h:372
XprType::PlainObject PlainObject
Definition: SparseSelfAdjointView.h:369
PlainObject m_result
Definition: SparseSelfAdjointView.h:380
evaluator< PlainObject > Base
Definition: SparseSelfAdjointView.h:370
Rhs::PlainObject m_lhs
Definition: SparseSelfAdjointView.h:379
Product< LhsView, Rhs, DefaultProduct > XprType
Definition: SparseSelfAdjointView.h:368
evaluator< PlainObject > Base
Definition: SparseSelfAdjointView.h:388
XprType::PlainObject PlainObject
Definition: SparseSelfAdjointView.h:387
Product< Lhs, RhsView, DefaultProduct > XprType
Definition: SparseSelfAdjointView.h:386
Lhs::PlainObject m_rhs
Definition: SparseSelfAdjointView.h:397
product_evaluator(const XprType &xpr)
Definition: SparseSelfAdjointView.h:390
PlainObject m_result
Definition: SparseSelfAdjointView.h:398
Definition: ForwardDeclarations.h:221
std::conditional_t< bool(traits< T >::Flags &NestByRefBit), T &, T > non_const_type
Definition: XprHelper.h:509
Template functor for scalar/packet assignment with subtraction.
Definition: AssignmentFunctors.h:73
Definition: ForwardDeclarations.h:21
Definition: NonLinearOptimization.cpp:97
Definition: benchGeometry.cpp:21
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2