13 #include "./InternalHeaderCheck.h"
19 template<
typename PlainObjectType_,
int Options_,
typename Str
ideType_>
20 struct traits<Ref<PlainObjectType_, Options_, StrideType_> >
21 :
public traits<Map<PlainObjectType_, Options_, StrideType_> >
23 typedef PlainObjectType_ PlainObjectType;
24 typedef StrideType_ StrideType;
27 Flags = traits<Map<PlainObjectType_, Options_, StrideType_> >::Flags | NestByRefBit,
28 Alignment = traits<Map<PlainObjectType_, Options_, StrideType_> >::Alignment
31 template<
typename Derived>
struct match {
33 IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime,
34 HasDirectAccess = internal::has_direct_access<Derived>::ret,
35 StorageOrderMatch = IsVectorAtCompileTime || ((PlainObjectType::Flags&
RowMajorBit)==(Derived::Flags&
RowMajorBit)),
36 InnerStrideMatch =
int(StrideType::InnerStrideAtCompileTime)==int(
Dynamic)
37 || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
38 || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
39 OuterStrideMatch = IsVectorAtCompileTime
40 ||
int(StrideType::OuterStrideAtCompileTime)==int(
Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
46 DerivedAlignment = int(evaluator<Derived>::Alignment),
47 AlignmentMatch = (int(traits<PlainObjectType>::Alignment)==int(
Unaligned)) || (DerivedAlignment >=
int(Alignment)),
48 ScalarTypeMatch = internal::is_same<typename PlainObjectType::Scalar, typename Derived::Scalar>::value,
49 MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch && ScalarTypeMatch
51 typedef std::conditional_t<MatchAtCompileTime,internal::true_type,internal::false_type> type;
56 template<
typename Derived>
57 struct traits<RefBase<Derived> > :
public traits<Derived> {};
61 template<
typename Derived>
class RefBase
62 :
public MapBase<Derived>
64 typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType;
65 typedef typename internal::traits<Derived>::StrideType StrideType;
69 typedef MapBase<Derived> Base;
70 EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
72 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index innerStride()
const
74 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
77 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index outerStride()
const
79 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
80 : IsVectorAtCompileTime ? this->size()
85 EIGEN_DEVICE_FUNC RefBase()
86 : Base(0,RowsAtCompileTime==
Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==
Dynamic?0:ColsAtCompileTime),
88 m_stride(StrideType::OuterStrideAtCompileTime==
Dynamic?0:StrideType::OuterStrideAtCompileTime,
89 StrideType::InnerStrideAtCompileTime==
Dynamic?0:StrideType::InnerStrideAtCompileTime)
92 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase)
96 typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase;
99 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
Index resolveInnerStride(
Index inner) {
100 return inner == 0 ? 1 : inner;
104 static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
Index resolveOuterStride(
Index inner,
Index outer,
Index rows,
Index cols,
bool isVectorAtCompileTime,
bool isRowMajor) {
105 return outer == 0 ? isVectorAtCompileTime ? inner * rows * cols : isRowMajor ? inner * cols : inner * rows : outer;
110 template<
typename Expression>
111 EIGEN_DEVICE_FUNC
bool construct(Expression& expr)
116 EIGEN_PREDICATE_SAME_MATRIX_SIZE(PlainObjectType, Expression)
118 || ( PlainObjectType::IsVectorAtCompileTime
121 ||
int(PlainObjectType::RowsAtCompileTime)==
int(Expression::ColsAtCompileTime))
124 ||
int(PlainObjectType::ColsAtCompileTime)==
int(Expression::RowsAtCompileTime)))),
125 YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES
129 Index rows = expr.rows();
130 Index cols = expr.cols();
131 if(PlainObjectType::RowsAtCompileTime==1)
133 eigen_assert(expr.rows()==1 || expr.cols()==1);
137 else if(PlainObjectType::ColsAtCompileTime==1)
139 eigen_assert(expr.rows()==1 || expr.cols()==1);
145 (PlainObjectType::RowsAtCompileTime ==
Dynamic) || (PlainObjectType::RowsAtCompileTime == rows));
147 (PlainObjectType::ColsAtCompileTime ==
Dynamic) || (PlainObjectType::ColsAtCompileTime == cols));
151 const bool transpose = PlainObjectType::IsVectorAtCompileTime && (rows != expr.rows());
153 const bool row_major = ((PlainObjectType::Flags)&
RowMajorBit) != 0;
154 const bool expr_row_major = (Expression::Flags&
RowMajorBit) != 0;
155 const bool storage_differs = (row_major != expr_row_major);
157 const bool swap_stride = (transpose != storage_differs);
160 const Index expr_inner_actual = resolveInnerStride(expr.innerStride());
161 const Index expr_outer_actual = resolveOuterStride(expr_inner_actual,
165 Expression::IsVectorAtCompileTime != 0,
170 const bool row_vector = (rows == 1);
171 const bool col_vector = (cols == 1);
172 const Index inner_stride =
173 ( (!row_major && row_vector) || (row_major && col_vector) ) ?
174 ( StrideType::InnerStrideAtCompileTime > 0 ?
Index(StrideType::InnerStrideAtCompileTime) : 1)
175 : swap_stride ? expr_outer_actual : expr_inner_actual;
179 const Index outer_stride =
180 ( (!row_major && col_vector) || (row_major && row_vector) ) ?
181 ( StrideType::OuterStrideAtCompileTime > 0 ?
Index(StrideType::OuterStrideAtCompileTime) : rows * cols * inner_stride)
182 : swap_stride ? expr_inner_actual : expr_outer_actual;
185 const bool inner_valid = (StrideType::InnerStrideAtCompileTime ==
Dynamic)
186 || (resolveInnerStride(
Index(StrideType::InnerStrideAtCompileTime)) == inner_stride);
191 const bool outer_valid = (StrideType::OuterStrideAtCompileTime ==
Dynamic)
192 || (resolveOuterStride(
194 Index(StrideType::OuterStrideAtCompileTime),
195 rows, cols, PlainObjectType::IsVectorAtCompileTime != 0,
202 internal::construct_at<Base>(
this, expr.data(), rows, cols);
203 internal::construct_at(&m_stride,
204 (StrideType::OuterStrideAtCompileTime == 0) ? 0 : outer_stride,
205 (StrideType::InnerStrideAtCompileTime == 0) ? 0 : inner_stride );
283 template<
typename PlainObjectType,
int Options,
typename Str
ideType>
class Ref
284 :
public RefBase<Ref<PlainObjectType, Options, StrideType> >
287 typedef internal::traits<Ref> Traits;
288 template<
typename Derived>
290 std::enable_if_t<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>* = 0);
293 typedef RefBase<Ref> Base;
294 EIGEN_DENSE_PUBLIC_INTERFACE(
Ref)
297 #ifndef EIGEN_PARSED_BY_DOXYGEN
298 template<
typename Derived>
300 std::enable_if_t<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>* = 0)
302 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
304 const bool success = Base::construct(expr.derived());
305 EIGEN_UNUSED_VARIABLE(success)
306 eigen_assert(success);
308 template<
typename Derived>
310 std::enable_if_t<
bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>* = 0)
313 template<
typename Derived>
317 EIGEN_STATIC_ASSERT(
bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
318 EIGEN_STATIC_ASSERT(
bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
319 EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
321 const bool success = Base::construct(expr.const_cast_derived());
322 EIGEN_UNUSED_VARIABLE(success)
323 eigen_assert(success);
326 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Ref)
331 template<
typename TPlainObjectType,
int Options,
typename Str
ideType>
class Ref<const TPlainObjectType, Options, StrideType>
332 :
public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
334 typedef internal::traits<Ref> Traits;
337 typedef RefBase<Ref> Base;
338 EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
340 template<
typename Derived>
341 EIGEN_DEVICE_FUNC
inline Ref(
const DenseBase<Derived>& expr,
342 std::enable_if_t<
bool(Traits::template match<Derived>::ScalarTypeMatch),Derived>* = 0)
347 construct(expr.derived(),
typename Traits::template match<Derived>::type());
350 EIGEN_DEVICE_FUNC
inline Ref(
const Ref& other) : Base(other) {
354 template<
typename OtherRef>
355 EIGEN_DEVICE_FUNC
inline Ref(
const RefBase<OtherRef>& other) {
356 construct(other.derived(),
typename Traits::template match<OtherRef>::type());
361 template<
typename Expression>
362 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr,internal::true_type)
365 if (!Base::construct(expr)) {
366 construct(expr, internal::false_type());
370 template<
typename Expression>
371 EIGEN_DEVICE_FUNC
void construct(
const Expression& expr, internal::false_type)
373 internal::call_assignment_no_alias(m_object,expr,internal::assign_op<Scalar,Scalar>());
374 Base::construct(m_object);
378 TPlainObjectType m_object;
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:42
Dense storage base class for matrices and arrays.
Definition: PlainObjectBase.h:102
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:285
Ref(DenseBase< Derived > &expr)
Definition: Ref.h:314
@ Unaligned
Definition: Constants.h:235
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24