17template<
typename _PlainObjectType,
int _Options,
typename _Str
ideType>
18struct traits<Ref<_PlainObjectType, _Options, _StrideType> >
19 :
public traits<Map<_PlainObjectType, _Options, _StrideType> >
21 typedef _PlainObjectType PlainObjectType;
22 typedef _StrideType StrideType;
25 Flags = traits<Map<_PlainObjectType, _Options, _StrideType> >::Flags | NestByRefBit,
26 Alignment = traits<Map<_PlainObjectType, _Options, _StrideType> >::Alignment
29 template<
typename Derived>
struct match {
31 IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime,
32 HasDirectAccess = internal::has_direct_access<Derived>::ret,
33 StorageOrderMatch = IsVectorAtCompileTime || ((PlainObjectType::Flags&
RowMajorBit)==(Derived::Flags&RowMajorBit)),
34 InnerStrideMatch =
int(StrideType::InnerStrideAtCompileTime)==int(Dynamic)
35 || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
36 || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
37 OuterStrideMatch = IsVectorAtCompileTime
38 ||
int(StrideType::OuterStrideAtCompileTime)==int(Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
44 DerivedAlignment = int(evaluator<Derived>::Alignment),
45 AlignmentMatch = (int(traits<PlainObjectType>::Alignment)==int(Unaligned)) || (DerivedAlignment >=
int(Alignment)),
46 ScalarTypeMatch = internal::is_same<typename PlainObjectType::Scalar, typename Derived::Scalar>::value,
47 MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch && ScalarTypeMatch
49 typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
54template<
typename Derived>
55struct traits<RefBase<Derived> > :
public traits<Derived> {};
59template<
typename Derived>
class RefBase
60 :
public MapBase<Derived>
62 typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType;
63 typedef typename internal::traits<Derived>::StrideType StrideType;
67 typedef MapBase<Derived> Base;
68 EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
70 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index innerStride()
const
72 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
75 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index outerStride()
const
77 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
78 : IsVectorAtCompileTime ? this->size()
83 EIGEN_DEVICE_FUNC RefBase()
84 : Base(0,RowsAtCompileTime==
Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==
Dynamic?0:ColsAtCompileTime),
86 m_stride(StrideType::OuterStrideAtCompileTime==
Dynamic?0:StrideType::OuterStrideAtCompileTime,
87 StrideType::InnerStrideAtCompileTime==
Dynamic?0:StrideType::InnerStrideAtCompileTime)
90 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase)
94 typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase;
97 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
Index resolveInnerStride(
Index inner) {
98 return inner == 0 ? 1 : inner;
102 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
Index resolveOuterStride(
Index inner,
Index outer,
Index rows,
Index cols,
bool isVectorAtCompileTime,
bool isRowMajor) {
103 return outer == 0 ? isVectorAtCompileTime ? inner * rows * cols : isRowMajor ? inner * cols : inner * rows : outer;
108 template<
typename Expression>
109 EIGEN_DEVICE_FUNC
bool construct(Expression& expr)
114 EIGEN_PREDICATE_SAME_MATRIX_SIZE(PlainObjectType, Expression)
116 || ( PlainObjectType::IsVectorAtCompileTime
119 ||
int(PlainObjectType::RowsAtCompileTime)==
int(Expression::ColsAtCompileTime))
122 ||
int(PlainObjectType::ColsAtCompileTime)==
int(Expression::RowsAtCompileTime)))),
123 YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES
127 Index rows = expr.rows();
128 Index cols = expr.cols();
129 if(PlainObjectType::RowsAtCompileTime==1)
131 eigen_assert(expr.rows()==1 || expr.cols()==1);
135 else if(PlainObjectType::ColsAtCompileTime==1)
137 eigen_assert(expr.rows()==1 || expr.cols()==1);
143 (PlainObjectType::RowsAtCompileTime ==
Dynamic) || (PlainObjectType::RowsAtCompileTime == rows));
145 (PlainObjectType::ColsAtCompileTime ==
Dynamic) || (PlainObjectType::ColsAtCompileTime == cols));
149 const bool transpose = PlainObjectType::IsVectorAtCompileTime && (rows != expr.rows());
151 const bool row_major = ((PlainObjectType::Flags)&
RowMajorBit) != 0;
152 const bool expr_row_major = (Expression::Flags&
RowMajorBit) != 0;
153 const bool storage_differs = (row_major != expr_row_major);
155 const bool swap_stride = (transpose != storage_differs);
158 const Index expr_inner_actual = resolveInnerStride(expr.innerStride());
159 const Index expr_outer_actual = resolveOuterStride(expr_inner_actual,
163 Expression::IsVectorAtCompileTime != 0,
168 const bool row_vector = (rows == 1);
169 const bool col_vector = (cols == 1);
170 const Index inner_stride =
171 ( (!row_major && row_vector) || (row_major && col_vector) ) ?
172 ( StrideType::InnerStrideAtCompileTime > 0 ?
Index(StrideType::InnerStrideAtCompileTime) : 1)
173 : swap_stride ? expr_outer_actual : expr_inner_actual;
177 const Index outer_stride =
178 ( (!row_major && col_vector) || (row_major && row_vector) ) ?
179 ( StrideType::OuterStrideAtCompileTime > 0 ?
Index(StrideType::OuterStrideAtCompileTime) : rows * cols * inner_stride)
180 : swap_stride ? expr_inner_actual : expr_outer_actual;
183 const bool inner_valid = (StrideType::InnerStrideAtCompileTime ==
Dynamic)
184 || (resolveInnerStride(
Index(StrideType::InnerStrideAtCompileTime)) == inner_stride);
189 const bool outer_valid = (StrideType::OuterStrideAtCompileTime ==
Dynamic)
190 || (resolveOuterStride(
192 Index(StrideType::OuterStrideAtCompileTime),
193 rows, cols, PlainObjectType::IsVectorAtCompileTime != 0,
200 ::new (
static_cast<Base*
>(
this)) Base(expr.data(), rows, cols);
201 ::new (&m_stride) StrideBase(
202 (StrideType::OuterStrideAtCompileTime == 0) ? 0 : outer_stride,
203 (StrideType::InnerStrideAtCompileTime == 0) ? 0 : inner_stride );
281template<typename PlainObjectType,
int Options, typename StrideType> class
Ref
282 : public RefBase<
Ref<PlainObjectType, Options, StrideType> >
285 typedef internal::traits<Ref> Traits;
286 template<
typename Derived>
288 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0);
291 typedef RefBase<Ref> Base;
292 EIGEN_DENSE_PUBLIC_INTERFACE(
Ref)
295 #ifndef EIGEN_PARSED_BY_DOXYGEN
296 template<
typename Derived>
298 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
300 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
302 const bool success = Base::construct(expr.derived());
303 EIGEN_UNUSED_VARIABLE(success)
304 eigen_assert(success);
306 template<
typename Derived>
308 typename internal::enable_if<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
311 template<
typename Derived>
315 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
316 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
317 EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
319 const bool success = Base::construct(expr.const_cast_derived());
320 EIGEN_UNUSED_VARIABLE(success)
321 eigen_assert(success);
324 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Ref)
329template<
typename TPlainObjectType,
int Options,
typename Str
ideType>
class Ref<const TPlainObjectType, Options, StrideType>
330 :
public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
332 typedef internal::traits<Ref> Traits;
335 typedef RefBase<Ref> Base;
336 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
338 template<
typename Derived>
339 EIGEN_DEVICE_FUNC
inline Ref(
const DenseBase<Derived>& expr,
340 typename internal::enable_if<
bool(Traits::template match<Derived>::ScalarTypeMatch),Derived>::type* = 0)
345 construct(expr.derived(),
typename Traits::template match<Derived>::type());
348 EIGEN_DEVICE_FUNC
inline Ref(
const Ref& other) : Base(other) {
352 template<
typename OtherRef>
353 EIGEN_DEVICE_FUNC
inline Ref(
const RefBase<OtherRef>& other) {
354 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
359 template<
typename Expression>
360 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr,internal::true_type)
363 if (!Base::construct(expr)) {
364 construct(expr, internal::false_type());
368 template<
typename Expression>
369 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr, internal::false_type)
371 internal::call_assignment_no_alias(m_object,expr,internal::assign_op<Scalar,Scalar>());
372 Base::construct(m_object);
376 TPlainObjectType m_object;
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:47
Dense storage base class for matrices and arrays.
Definition: PlainObjectBase.h:100
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:283
Ref(DenseBase< Derived > &expr)
Definition: Ref.h:312
const unsigned int RowMajorBit
Definition: Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
const int Dynamic
Definition: Constants.h:22