10#ifndef EIGEN_SPARSE_REF_H
11#define EIGEN_SPARSE_REF_H
14#include "./InternalHeaderCheck.h"
25template <
typename Derived>
28template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options_,
typename Str
ideType_>
29struct traits<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>>
30 :
public traits<SparseMatrix<MatScalar, MatOptions, MatIndex>> {
31 typedef SparseMatrix<MatScalar, MatOptions, MatIndex> PlainObjectType;
32 enum { Options = Options_, Flags = traits<PlainObjectType>::Flags | CompressedAccessBit | NestByRefBit };
34 template <
typename Derived>
37 StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime ||
38 ((PlainObjectType::Flags & RowMajorBit) == (Derived::Flags & RowMajorBit)),
39 MatchAtCompileTime = (Derived::Flags & CompressedAccessBit) && StorageOrderMatch
41 typedef std::conditional_t<MatchAtCompileTime, internal::true_type, internal::false_type> type;
45template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options_,
typename Str
ideType_>
46struct traits<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>>
47 :
public traits<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>> {
50 (traits<SparseMatrix<MatScalar, MatOptions, MatIndex>>::Flags |
CompressedAccessBit | NestByRefBit) & ~LvalueBit
54template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options_,
typename Str
ideType_>
55struct traits<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>>
56 :
public traits<SparseVector<MatScalar, MatOptions, MatIndex>> {
57 typedef SparseVector<MatScalar, MatOptions, MatIndex> PlainObjectType;
58 enum { Options = Options_, Flags = traits<PlainObjectType>::Flags |
CompressedAccessBit | NestByRefBit };
60 template <
typename Derived>
62 enum { MatchAtCompileTime = (Derived::Flags &
CompressedAccessBit) && Derived::IsVectorAtCompileTime };
63 typedef std::conditional_t<MatchAtCompileTime, internal::true_type, internal::false_type> type;
67template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options_,
typename Str
ideType_>
68struct traits<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>>
69 :
public traits<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>> {
72 (traits<SparseVector<MatScalar, MatOptions, MatIndex>>::Flags |
CompressedAccessBit | NestByRefBit) & ~LvalueBit
76template <
typename Derived>
77struct traits<SparseRefBase<Derived>> :
public traits<Derived> {};
79template <
typename Derived>
80class SparseRefBase :
public SparseMapBase<Derived> {
82 typedef SparseMapBase<Derived> Base;
83 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseRefBase)
86 : Base(RowsAtCompileTime ==
Dynamic ? 0 : RowsAtCompileTime, ColsAtCompileTime ==
Dynamic ? 0 : ColsAtCompileTime,
90 template <
typename Expression>
91 void construct(Expression& expr) {
92 if (expr.outerIndexPtr() == 0)
93 internal::construct_at<Base>(
this, expr.size(), expr.nonZeros(), expr.innerIndexPtr(), expr.valuePtr());
95 internal::construct_at<Base>(
this, expr.rows(), expr.cols(), expr.nonZeros(), expr.outerIndexPtr(),
96 expr.innerIndexPtr(), expr.valuePtr(), expr.innerNonZeroPtr());
113#ifndef EIGEN_PARSED_BY_DOXYGEN
114template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
115class Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>
116 :
public internal::SparseRefBase<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
118template <typename SparseMatrixType, int Options>
119class
Ref<SparseMatrixType, Options>
120 :
public SparseMapBase<Derived, WriteAccessors>
124 typedef internal::traits<Ref> Traits;
125 template <
int OtherOptions>
127 template <
int OtherOptions>
131 typedef internal::SparseRefBase<Ref> Base;
132 EIGEN_SPARSE_PUBLIC_INTERFACE(
Ref)
134#ifndef EIGEN_PARSED_BY_DOXYGEN
135 template <
int OtherOptions>
139 STORAGE_LAYOUT_DOES_NOT_MATCH);
141 Base::construct(expr.
derived());
144 template <
int OtherOptions>
148 STORAGE_LAYOUT_DOES_NOT_MATCH);
150 Base::construct(expr.
derived());
153 template <
typename Derived>
157 template <
typename Derived>
161 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
162 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
164 Base::construct(expr.const_cast_derived());
169template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
170class Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>
171 :
public internal::SparseRefBase<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>> {
172 typedef SparseMatrix<MatScalar, MatOptions, MatIndex> TPlainObjectType;
173 typedef internal::traits<Ref> Traits;
176 typedef internal::SparseRefBase<Ref> Base;
177 EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
179 template <
typename Derived>
180 inline Ref(
const SparseMatrixBase<Derived>& expr) : m_hasCopy(false) {
181 construct(expr.derived(),
typename Traits::template match<Derived>::type());
184 inline Ref(
const Ref& other) : Base(other), m_hasCopy(false) {
188 template <
typename OtherRef>
189 inline Ref(
const RefBase<OtherRef>& other) : m_hasCopy(false) {
190 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
195 internal::destroy_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage));
200 template <
typename Expression>
201 void construct(
const Expression& expr, internal::true_type) {
203 TPlainObjectType* obj = internal::construct_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage), expr);
205 Base::construct(*obj);
207 Base::construct(expr);
211 template <
typename Expression>
212 void construct(
const Expression& expr, internal::false_type) {
213 TPlainObjectType* obj = internal::construct_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage), expr);
215 Base::construct(*obj);
219 typename internal::aligned_storage<
sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage;
233#ifndef EIGEN_PARSED_BY_DOXYGEN
234template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
235class Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>
236 :
public internal::SparseRefBase<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
238template <typename SparseVectorType>
239class
Ref<SparseVectorType> :
public SparseMapBase<Derived, WriteAccessors>
243 typedef internal::traits<Ref> Traits;
244 template <
int OtherOptions>
248 typedef internal::SparseRefBase<Ref> Base;
249 EIGEN_SPARSE_PUBLIC_INTERFACE(
Ref)
251#ifndef EIGEN_PARSED_BY_DOXYGEN
252 template <
int OtherOptions>
256 STORAGE_LAYOUT_DOES_NOT_MATCH);
257 Base::construct(expr.
derived());
260 template <
typename Derived>
264 template <
typename Derived>
268 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
269 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
270 Base::construct(expr.const_cast_derived());
275template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
276class Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>
277 :
public internal::SparseRefBase<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>> {
278 typedef SparseVector<MatScalar, MatOptions, MatIndex> TPlainObjectType;
279 typedef internal::traits<Ref> Traits;
282 typedef internal::SparseRefBase<Ref> Base;
283 EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
285 template <
typename Derived>
286 inline Ref(
const SparseMatrixBase<Derived>& expr) : m_hasCopy(false) {
287 construct(expr.derived(),
typename Traits::template match<Derived>::type());
290 inline Ref(
const Ref& other) : Base(other), m_hasCopy(false) {
294 template <
typename OtherRef>
295 inline Ref(
const RefBase<OtherRef>& other) : m_hasCopy(false) {
296 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
301 internal::destroy_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage));
306 template <
typename Expression>
307 void construct(
const Expression& expr, internal::true_type) {
308 Base::construct(expr);
311 template <
typename Expression>
312 void construct(
const Expression& expr, internal::false_type) {
313 TPlainObjectType* obj = internal::construct_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage), expr);
315 Base::construct(*obj);
319 typename internal::aligned_storage<
sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage;
328template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
329struct evaluator<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
330 : evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> {
331 typedef evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> Base;
332 typedef Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType> XprType;
333 evaluator() : Base() {}
334 explicit evaluator(
const XprType& mat) : Base(mat) {}
337template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
338struct evaluator<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
339 : evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> {
340 typedef evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>>
342 typedef Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType> XprType;
343 evaluator() : Base() {}
344 explicit evaluator(
const XprType& mat) : Base(mat) {}
347template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
348struct evaluator<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
349 : evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> {
350 typedef evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> Base;
351 typedef Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType> XprType;
352 evaluator() : Base() {}
353 explicit evaluator(
const XprType& mat) : Base(mat) {}
356template <
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
357struct evaluator<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
358 : evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> {
359 typedef evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>>
361 typedef Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType> XprType;
362 evaluator() : Base() {}
363 explicit evaluator(
const XprType& mat) : Base(mat) {}
A matrix or vector expression mapping an existing array of data.
Definition Map.h:96
Ref(SparseCompressedBase< Derived > &expr)
Definition SparseRef.h:158
Ref(SparseCompressedBase< Derived > &expr)
Definition SparseRef.h:265
A matrix or vector expression mapping an existing expression.
Definition Ref.h:264
Common base class for sparse [compressed]-{row|column}-storage format.
Definition SparseCompressedBase.h:43
bool isCompressed() const
Definition SparseCompressedBase.h:114
A versatible sparse matrix representation.
Definition SparseUtil.h:47
bool isCompressed() const
Definition SparseCompressedBase.h:114
a sparse vector class
Definition SparseVector.h:62
const unsigned int CompressedAccessBit
Definition Constants.h:195
Namespace containing all symbols from the Eigen library.
Definition Core:137
@ StandardCompressedFormat
Definition SparseRef.h:19
const int Dynamic
Definition Constants.h:25
Derived & derived()
Definition EigenBase.h:49