10 #ifndef EIGEN_SPARSE_REF_H
11 #define EIGEN_SPARSE_REF_H
13 #include "./InternalHeaderCheck.h"
23 template<
typename Derived>
class SparseRefBase;
25 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options_,
typename Str
ideType_>
26 struct traits<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options_, StrideType_> >
27 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
29 typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType;
35 template<
typename Derived>
struct match {
37 StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime || ((PlainObjectType::Flags&
RowMajorBit)==(Derived::Flags&
RowMajorBit)),
40 typedef std::conditional_t<MatchAtCompileTime,internal::true_type,internal::false_type> type;
45 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options_,
typename Str
ideType_>
46 struct traits<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options_, StrideType_> >
47 :
public traits<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options_, StrideType_> >
54 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options_,
typename Str
ideType_>
55 struct traits<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options_, StrideType_> >
56 :
public traits<SparseVector<MatScalar,MatOptions,MatIndex> >
58 typedef SparseVector<MatScalar,MatOptions,MatIndex> PlainObjectType;
64 template<
typename Derived>
struct match {
68 typedef std::conditional_t<MatchAtCompileTime,internal::true_type,internal::false_type> type;
73 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options_,
typename Str
ideType_>
74 struct traits<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options_, StrideType_> >
75 :
public traits<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options_, StrideType_> >
82 template<
typename Derived>
83 struct traits<SparseRefBase<Derived> > :
public traits<Derived> {};
85 template<
typename Derived>
class SparseRefBase
86 :
public SparseMapBase<Derived>
90 typedef SparseMapBase<Derived> Base;
91 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseRefBase)
94 : Base(RowsAtCompileTime==
Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==
Dynamic?0:ColsAtCompileTime, 0, 0, 0, 0, 0)
99 template<
typename Expression>
100 void construct(Expression& expr)
102 if(expr.outerIndexPtr()==0)
103 internal::construct_at<Base>(
this, expr.size(), expr.nonZeros(), expr.innerIndexPtr(), expr.valuePtr());
105 internal::construct_at<Base>(
this, expr.rows(), expr.cols(), expr.nonZeros(), expr.outerIndexPtr(), expr.innerIndexPtr(), expr.valuePtr(), expr.innerNonZeroPtr());
123 #ifndef EIGEN_PARSED_BY_DOXYGEN
124 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
125 class Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType >
126 :
public internal::SparseRefBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType > >
128 template<typename SparseMatrixType, int Options>
129 class
Ref<SparseMatrixType, Options>
130 :
public SparseMapBase<Derived,WriteAccessors>
134 typedef internal::traits<Ref> Traits;
135 template<
int OtherOptions>
137 template<
int OtherOptions>
141 typedef internal::SparseRefBase<Ref>
Base;
142 EIGEN_SPARSE_PUBLIC_INTERFACE(
Ref)
145 #ifndef EIGEN_PARSED_BY_DOXYGEN
146 template<
int OtherOptions>
151 Base::construct(expr.
derived());
154 template<
int OtherOptions>
159 Base::construct(expr.
derived());
162 template<
typename Derived>
166 template<
typename Derived>
170 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
171 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
173 Base::construct(expr.const_cast_derived());
178 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
179 class Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
180 :
public internal::SparseRefBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
182 typedef SparseMatrix<MatScalar,MatOptions,MatIndex> TPlainObjectType;
183 typedef internal::traits<Ref> Traits;
186 typedef internal::SparseRefBase<Ref> Base;
187 EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
189 template<
typename Derived>
190 inline Ref(
const SparseMatrixBase<Derived>& expr) : m_hasCopy(false)
192 construct(expr.derived(),
typename Traits::template match<Derived>::type());
195 inline Ref(
const Ref& other) : Base(other), m_hasCopy(false) {
199 template<
typename OtherRef>
200 inline Ref(
const RefBase<OtherRef>& other) : m_hasCopy(false) {
201 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
206 internal::destroy_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage));
212 template<
typename Expression>
213 void construct(
const Expression& expr,internal::true_type)
217 TPlainObjectType* obj = internal::construct_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage), expr);
219 Base::construct(*obj);
223 Base::construct(expr);
227 template<
typename Expression>
228 void construct(
const Expression& expr, internal::false_type)
230 TPlainObjectType* obj = internal::construct_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage), expr);
232 Base::construct(*obj);
236 typename internal::aligned_storage<
sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage;
251 #ifndef EIGEN_PARSED_BY_DOXYGEN
252 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
253 class Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType >
254 :
public internal::SparseRefBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType > >
256 template<typename SparseVectorType>
257 class
Ref<SparseVectorType>
258 :
public SparseMapBase<Derived,WriteAccessors>
262 typedef internal::traits<Ref> Traits;
263 template<
int OtherOptions>
267 typedef internal::SparseRefBase<Ref>
Base;
268 EIGEN_SPARSE_PUBLIC_INTERFACE(
Ref)
270 #ifndef EIGEN_PARSED_BY_DOXYGEN
271 template<
int OtherOptions>
275 Base::construct(expr.
derived());
278 template<
typename Derived>
282 template<
typename Derived>
286 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
287 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
288 Base::construct(expr.const_cast_derived());
293 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
294 class Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType>
295 :
public internal::SparseRefBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
297 typedef SparseVector<MatScalar,MatOptions,MatIndex> TPlainObjectType;
298 typedef internal::traits<Ref> Traits;
301 typedef internal::SparseRefBase<Ref> Base;
302 EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
304 template<
typename Derived>
305 inline Ref(
const SparseMatrixBase<Derived>& expr) : m_hasCopy(false)
307 construct(expr.derived(),
typename Traits::template match<Derived>::type());
310 inline Ref(
const Ref& other) : Base(other), m_hasCopy(false) {
314 template<
typename OtherRef>
315 inline Ref(
const RefBase<OtherRef>& other) : m_hasCopy(false) {
316 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
321 internal::destroy_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage));
327 template<
typename Expression>
328 void construct(
const Expression& expr,internal::true_type)
330 Base::construct(expr);
333 template<
typename Expression>
334 void construct(
const Expression& expr, internal::false_type)
336 TPlainObjectType* obj = internal::construct_at(
reinterpret_cast<TPlainObjectType*
>(&m_storage), expr);
338 Base::construct(*obj);
342 typename internal::aligned_storage<
sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage;
350 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
351 struct evaluator<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
352 : evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
354 typedef evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
355 typedef Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
356 evaluator() : Base() {}
357 explicit evaluator(
const XprType &mat) : Base(mat) {}
360 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
361 struct evaluator<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
362 : evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
364 typedef evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
365 typedef Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
366 evaluator() : Base() {}
367 explicit evaluator(
const XprType &mat) : Base(mat) {}
370 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
371 struct evaluator<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
372 : evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
374 typedef evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
375 typedef Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
376 evaluator() : Base() {}
377 explicit evaluator(
const XprType &mat) : Base(mat) {}
380 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
381 struct evaluator<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
382 : evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
384 typedef evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
385 typedef Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
386 evaluator() : Base() {}
387 explicit evaluator(
const XprType &mat) : Base(mat) {}
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:98
Ref(SparseCompressedBase< Derived > &expr)
Definition: SparseRef.h:167
Ref(SparseCompressedBase< Derived > &expr)
Definition: SparseRef.h:283
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:285
Common base class for sparse [compressed]-{row|column}-storage format.
Definition: SparseCompressedBase.h:40
bool isCompressed() const
Definition: SparseCompressedBase.h:109
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:30
A versatible sparse matrix representation.
Definition: SparseMatrix.h:100
bool isCompressed() const
Definition: SparseCompressedBase.h:109
a sparse vector class
Definition: SparseVector.h:68
const unsigned int LvalueBit
Definition: Constants.h:146
const unsigned int RowMajorBit
Definition: Constants.h:68
const unsigned int CompressedAccessBit
Definition: Constants.h:193
Namespace containing all symbols from the Eigen library.
Definition: Core:139
@ StandardCompressedFormat
Definition: SparseRef.h:18
const int Dynamic
Definition: Constants.h:24
Derived & derived()
Definition: EigenBase.h:48