10 #ifndef EIGEN_SPARSE_REF_H
11 #define EIGEN_SPARSE_REF_H
16 StandardCompressedFormat = 2
21 template<
typename Derived>
class SparseRefBase;
23 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int _Options,
typename _Str
ideType>
24 struct 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)),
38 typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
43 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int _Options,
typename _Str
ideType>
44 struct traits<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
45 :
public traits<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
52 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int _Options,
typename _Str
ideType>
53 struct 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;
71 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int _Options,
typename _Str
ideType>
72 struct traits<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
73 :
public traits<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> >
80 template<
typename Derived>
81 struct traits<SparseRefBase<Derived> > :
public traits<Derived> {};
83 template<
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());
122 template<typename MatScalar,
int MatOptions, typename MatIndex,
int Options, typename StrideType>
127 typedef internal::traits<Ref> Traits;
128 template<
int OtherOptions>
130 template<
int OtherOptions>
134 typedef internal::SparseRefBase<Ref> Base;
135 EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
138 #ifndef EIGEN_PARSED_BY_DOXYGEN
139 template<
int OtherOptions>
143 eigen_assert( ((Options &
int(StandardCompressedFormat))==0) || (expr.isCompressed()) );
144 Base::construct(expr.
derived());
147 template<
int OtherOptions>
151 eigen_assert( ((Options &
int(StandardCompressedFormat))==0) || (expr.isCompressed()) );
152 Base::construct(expr.derived());
155 template<
typename Derived>
156 inline Ref(
const SparseCompressedBase<Derived>& expr)
158 template<
typename Derived>
159 inline Ref(SparseCompressedBase<Derived>& expr)
162 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
163 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
164 eigen_assert( ((Options &
int(StandardCompressedFormat))==0) || (expr.isCompressed()) );
165 Base::construct(expr.const_cast_derived());
170 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
171 class Ref<const
SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
172 :
public internal::SparseRefBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
175 typedef internal::traits<Ref> Traits;
178 typedef internal::SparseRefBase<Ref> Base;
179 EIGEN_SPARSE_PUBLIC_INTERFACE(
Ref)
181 template<typename Derived>
184 construct(expr.derived(),
typename Traits::template match<Derived>::type());
187 inline Ref(
const Ref& other) : Base(other) {
191 template<
typename OtherRef>
192 inline Ref(
const RefBase<OtherRef>& other) {
193 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
198 template<
typename Expression>
199 void construct(
const Expression& expr,internal::true_type)
201 if((Options &
int(StandardCompressedFormat)) && (!expr.isCompressed()))
203 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(m_object_bytes);
204 ::new (obj) TPlainObjectType(expr);
205 Base::construct(*obj);
209 Base::construct(expr);
213 template<
typename Expression>
214 void construct(
const Expression& expr, internal::false_type)
216 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(m_object_bytes);
217 ::new (obj) TPlainObjectType(expr);
218 Base::construct(*obj);
222 char m_object_bytes[sizeof(TPlainObjectType)];
238 template<typename MatScalar,
int MatOptions, typename MatIndex,
int Options, typename StrideType>
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 Base::construct(expr.
derived());
259 template<
typename Derived>
260 inline Ref(
const SparseCompressedBase<Derived>& expr)
262 template<
typename Derived>
263 inline Ref(SparseCompressedBase<Derived>& expr)
266 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
267 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
268 Base::construct(expr.const_cast_derived());
273 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
274 class Ref<const
SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType>
275 :
public internal::SparseRefBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
278 typedef internal::traits<Ref> Traits;
281 typedef internal::SparseRefBase<Ref> Base;
282 EIGEN_SPARSE_PUBLIC_INTERFACE(
Ref)
284 template<typename Derived>
287 construct(expr.derived(),
typename Traits::template match<Derived>::type());
290 inline Ref(
const Ref& other) : Base(other) {
294 template<
typename OtherRef>
295 inline Ref(
const RefBase<OtherRef>& other) {
296 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
301 template<
typename Expression>
302 void construct(
const Expression& expr,internal::true_type)
304 Base::construct(expr);
307 template<
typename Expression>
308 void construct(
const Expression& expr, internal::false_type)
310 TPlainObjectType* obj =
reinterpret_cast<TPlainObjectType*
>(m_object_bytes);
311 ::new (obj) TPlainObjectType(expr);
312 Base::construct(*obj);
316 char m_object_bytes[sizeof(TPlainObjectType)];
323 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
324 struct evaluator<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
325 : evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
327 typedef evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
328 typedef Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
329 evaluator() : Base() {}
330 explicit evaluator(
const XprType &mat) : Base(mat) {}
333 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
334 struct evaluator<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
335 : evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
337 typedef evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
338 typedef Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
339 evaluator() : Base() {}
340 explicit evaluator(
const XprType &mat) : Base(mat) {}
343 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
344 struct evaluator<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
345 : evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
347 typedef evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
348 typedef Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
349 evaluator() : Base() {}
350 explicit evaluator(
const XprType &mat) : Base(mat) {}
353 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
354 struct evaluator<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
355 : evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
357 typedef evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
358 typedef Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
359 evaluator() : Base() {}
360 explicit evaluator(
const XprType &mat) : Base(mat) {}
367 #endif // EIGEN_SPARSE_REF_H
const unsigned int CompressedAccessBit
Definition: Constants.h:185
A versatible sparse matrix representation.
Definition: SparseMatrix.h:92
const unsigned int LvalueBit
Definition: Constants.h:138
Derived & derived()
Definition: EigenBase.h:44
const unsigned int RowMajorBit
Definition: Constants.h:61
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:278
a sparse vector class
Definition: SparseUtil.h:54
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:186
Definition: Eigen_Colamd.h:54
Sparse matrix.
Definition: MappedSparseMatrix.h:32