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;
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> >
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> >
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)
190 construct(expr.derived(),
typename Traits::template match<Derived>::type());
193 inline Ref(
const Ref& other) : Base(other) {
197 template<
typename OtherRef>
198 inline Ref(
const RefBase<OtherRef>& other) {
199 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
204 template<
typename Expression>
205 void construct(
const Expression& expr,internal::true_type)
207 if((Options &
int(StandardCompressedFormat)) && (!expr.isCompressed()))
209 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(m_object_bytes);
210 ::new (obj) TPlainObjectType(expr);
211 Base::construct(*obj);
215 Base::construct(expr);
219 template<
typename Expression>
220 void construct(
const Expression& expr, internal::false_type)
222 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(m_object_bytes);
223 ::new (obj) TPlainObjectType(expr);
224 Base::construct(*obj);
228 char m_object_bytes[
sizeof(TPlainObjectType)];
242#ifndef EIGEN_PARSED_BY_DOXYGEN
243template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
244class Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType >
245 :
public internal::SparseRefBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType > >
247template<typename SparseVectorType>
248class
Ref<SparseVectorType>
249 :
public SparseMapBase<Derived,WriteAccessors>
253 typedef internal::traits<Ref> Traits;
254 template<
int OtherOptions>
258 typedef internal::SparseRefBase<Ref> Base;
259 EIGEN_SPARSE_PUBLIC_INTERFACE(
Ref)
261 #ifndef EIGEN_PARSED_BY_DOXYGEN
262 template<
int OtherOptions>
266 Base::construct(expr.
derived());
269 template<
typename Derived>
273 template<
typename Derived>
277 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
278 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
279 Base::construct(expr.const_cast_derived());
284template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
285class Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType>
286 :
public internal::SparseRefBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
288 typedef SparseVector<MatScalar,MatOptions,MatIndex> TPlainObjectType;
289 typedef internal::traits<Ref> Traits;
292 typedef internal::SparseRefBase<Ref> Base;
293 EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
295 template<
typename Derived>
296 inline Ref(
const SparseMatrixBase<Derived>& expr)
298 construct(expr.derived(),
typename Traits::template match<Derived>::type());
301 inline Ref(
const Ref& other) : Base(other) {
305 template<
typename OtherRef>
306 inline Ref(
const RefBase<OtherRef>& other) {
307 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
312 template<
typename Expression>
313 void construct(
const Expression& expr,internal::true_type)
315 Base::construct(expr);
318 template<
typename Expression>
319 void construct(
const Expression& expr, internal::false_type)
321 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(m_object_bytes);
322 ::new (obj) TPlainObjectType(expr);
323 Base::construct(*obj);
327 char m_object_bytes[
sizeof(TPlainObjectType)];
334template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
335struct evaluator<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
336 : evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
338 typedef evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
339 typedef Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
340 evaluator() : Base() {}
341 explicit evaluator(
const XprType &mat) : Base(mat) {}
344template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
345struct evaluator<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
346 : evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
348 typedef evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
349 typedef Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
350 evaluator() : Base() {}
351 explicit evaluator(
const XprType &mat) : Base(mat) {}
354template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
355struct evaluator<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
356 : evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
358 typedef evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
359 typedef Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
360 evaluator() : Base() {}
361 explicit evaluator(
const XprType &mat) : Base(mat) {}
364template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
365struct evaluator<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
366 : evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
368 typedef evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
369 typedef Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
370 evaluator() : Base() {}
371 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:274
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:192
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:94
bool isCompressed() const
Definition: SparseCompressedBase.h:107
a sparse vector class
Definition: SparseVector.h:66
const unsigned int LvalueBit
Definition: Constants.h:139
const unsigned int CompressedAccessBit
Definition: Constants.h:186
Namespace containing all symbols from the Eigen library.
Definition: Core:287
@ StandardCompressedFormat
Definition: SparseRef.h:16
const int Dynamic
Definition: Constants.h:21
Derived & derived()
Definition: EigenBase.h:44