10#ifndef EIGEN_SPARSE_REF_H
11#define EIGEN_SPARSE_REF_H
21template<
typename Derived>
class SparseRefBase;
23template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int _Options,
typename _Str
ideType>
24struct traits<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
25 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
27 typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType;
30 Flags = traits<PlainObjectType>::Flags | CompressedAccessBit | NestByRefBit
33 template<
typename Derived>
struct match {
35 StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime || ((PlainObjectType::Flags&RowMajorBit)==(Derived::Flags&RowMajorBit)),
36 MatchAtCompileTime = (Derived::Flags&CompressedAccessBit) && StorageOrderMatch
38 typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
43template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int _Options,
typename _Str
ideType>
44struct traits<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
45 :
public traits<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
48 Flags = (traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >::Flags |
CompressedAccessBit | NestByRefBit) & ~LvalueBit
52template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int _Options,
typename _Str
ideType>
53struct traits<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
54 :
public traits<SparseVector<MatScalar,MatOptions,MatIndex> >
56 typedef SparseVector<MatScalar,MatOptions,MatIndex> PlainObjectType;
62 template<
typename Derived>
struct match {
66 typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
71template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int _Options,
typename _Str
ideType>
72struct traits<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
73 :
public traits<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
76 Flags = (traits<SparseVector<MatScalar,MatOptions,MatIndex> >::Flags |
CompressedAccessBit | NestByRefBit) & ~LvalueBit
80template<
typename Derived>
81struct traits<SparseRefBase<Derived> > :
public traits<Derived> {};
83template<
typename Derived>
class SparseRefBase
84 :
public SparseMapBase<Derived>
88 typedef SparseMapBase<Derived> Base;
89 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseRefBase)
92 : Base(RowsAtCompileTime==
Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==
Dynamic?0:ColsAtCompileTime, 0, 0, 0, 0, 0)
97 template<
typename Expression>
98 void construct(Expression& expr)
100 if(expr.outerIndexPtr()==0)
101 ::new (
static_cast<Base*
>(
this)) Base(expr.size(), expr.nonZeros(), expr.innerIndexPtr(), expr.valuePtr());
103 ::new (static_cast<Base*>(this)) Base(expr.rows(), expr.cols(), expr.nonZeros(), expr.outerIndexPtr(), expr.innerIndexPtr(), expr.valuePtr(), expr.innerNonZeroPtr());
121#ifndef EIGEN_PARSED_BY_DOXYGEN
122template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
123class Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType >
124 :
public internal::SparseRefBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType > >
126template<typename SparseMatrixType, int Options>
127class
Ref<SparseMatrixType, Options>
128 :
public SparseMapBase<Derived,WriteAccessors>
132 typedef internal::traits<Ref> Traits;
133 template<
int OtherOptions>
135 template<
int OtherOptions>
139 typedef internal::SparseRefBase<Ref> Base;
140 EIGEN_SPARSE_PUBLIC_INTERFACE(
Ref)
143 #ifndef EIGEN_PARSED_BY_DOXYGEN
144 template<
int OtherOptions>
149 Base::construct(expr.
derived());
152 template<
int OtherOptions>
157 Base::construct(expr.derived());
160 template<
typename Derived>
164 template<
typename Derived>
168 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
169 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
171 Base::construct(expr.const_cast_derived());
176template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
177class Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
178 :
public internal::SparseRefBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
180 typedef SparseMatrix<MatScalar,MatOptions,MatIndex> TPlainObjectType;
181 typedef internal::traits<Ref> Traits;
184 typedef internal::SparseRefBase<Ref> Base;
185 EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
187 template<
typename Derived>
188 inline Ref(
const SparseMatrixBase<Derived>& expr) : m_hasCopy(false)
190 construct(expr.derived(),
typename Traits::template match<Derived>::type());
193 inline Ref(
const Ref& other) : Base(other), m_hasCopy(false) {
197 template<
typename OtherRef>
198 inline Ref(
const RefBase<OtherRef>& other) : m_hasCopy(false) {
199 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
204 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(&m_storage);
205 obj->~TPlainObjectType();
211 template<
typename Expression>
212 void construct(
const Expression& expr,internal::true_type)
214 if((Options &
int(StandardCompressedFormat)) && (!expr.isCompressed()))
216 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(&m_storage);
217 ::new (obj) TPlainObjectType(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 =
reinterpret_cast<TPlainObjectType*
>(&m_storage);
231 ::new (obj) TPlainObjectType(expr);
233 Base::construct(*obj);
237 typename internal::aligned_storage<
sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage;
252#ifndef EIGEN_PARSED_BY_DOXYGEN
253template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
254class Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType >
255 :
public internal::SparseRefBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType > >
257template<typename SparseVectorType>
258class
Ref<SparseVectorType>
259 :
public SparseMapBase<Derived,WriteAccessors>
263 typedef internal::traits<Ref> Traits;
264 template<
int OtherOptions>
268 typedef internal::SparseRefBase<Ref> Base;
269 EIGEN_SPARSE_PUBLIC_INTERFACE(
Ref)
271 #ifndef EIGEN_PARSED_BY_DOXYGEN
272 template<
int OtherOptions>
276 Base::construct(expr.
derived());
279 template<
typename Derived>
283 template<
typename Derived>
287 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
288 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
289 Base::construct(expr.const_cast_derived());
294template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
295class Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType>
296 :
public internal::SparseRefBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
298 typedef SparseVector<MatScalar,MatOptions,MatIndex> TPlainObjectType;
299 typedef internal::traits<Ref> Traits;
302 typedef internal::SparseRefBase<Ref> Base;
303 EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
305 template<
typename Derived>
306 inline Ref(
const SparseMatrixBase<Derived>& expr) : m_hasCopy(false)
308 construct(expr.derived(),
typename Traits::template match<Derived>::type());
311 inline Ref(
const Ref& other) : Base(other), m_hasCopy(false) {
315 template<
typename OtherRef>
316 inline Ref(
const RefBase<OtherRef>& other) : m_hasCopy(false) {
317 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
322 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(&m_storage);
323 obj->~TPlainObjectType();
329 template<
typename Expression>
330 void construct(
const Expression& expr,internal::true_type)
332 Base::construct(expr);
335 template<
typename Expression>
336 void construct(
const Expression& expr, internal::false_type)
338 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(&m_storage);
339 ::new (obj) TPlainObjectType(expr);
341 Base::construct(*obj);
345 typename internal::aligned_storage<
sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage;
353template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
354struct evaluator<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
355 : evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
357 typedef evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
358 typedef Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
359 evaluator() : Base() {}
360 explicit evaluator(
const XprType &mat) : Base(mat) {}
363template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
364struct evaluator<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
365 : evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
367 typedef evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
368 typedef Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
369 evaluator() : Base() {}
370 explicit evaluator(
const XprType &mat) : Base(mat) {}
373template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
374struct evaluator<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
375 : evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
377 typedef evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
378 typedef Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
379 evaluator() : Base() {}
380 explicit evaluator(
const XprType &mat) : Base(mat) {}
383template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
384struct evaluator<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
385 : evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
387 typedef evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
388 typedef Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
389 evaluator() : Base() {}
390 explicit evaluator(
const XprType &mat) : Base(mat) {}
Sparse matrix.
Definition: MappedSparseMatrix.h:34
Ref(SparseCompressedBase< Derived > &expr)
Definition: SparseRef.h:165
Ref(SparseCompressedBase< Derived > &expr)
Definition: SparseRef.h:284
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:283
Common base class for sparse [compressed]-{row|column}-storage format.
Definition: SparseCompressedBase.h:38
bool isCompressed() const
Definition: SparseCompressedBase.h:107
A versatible sparse matrix representation.
Definition: SparseMatrix.h:98
bool isCompressed() const
Definition: SparseCompressedBase.h:107
a sparse vector class
Definition: SparseVector.h:66
const unsigned int CompressedAccessBit
Definition: Constants.h:191
Namespace containing all symbols from the Eigen library.
Definition: Core:141
@ StandardCompressedFormat
Definition: SparseRef.h:16
const int Dynamic
Definition: Constants.h:22
Derived & derived()
Definition: EigenBase.h:46