10 #ifndef EIGEN_DENSECOEFFSBASE_H
11 #define EIGEN_DENSECOEFFSBASE_H
16 template<
typename T>
struct add_const_on_value_type_if_arithmetic
18 typedef typename conditional<is_arithmetic<T>::value, T,
typename add_const_on_value_type<T>::type>::type type;
33 template<
typename Derived>
37 typedef typename internal::traits<Derived>::StorageKind StorageKind;
38 typedef typename internal::traits<Derived>::Scalar Scalar;
39 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
48 typedef typename internal::conditional<bool(internal::traits<Derived>::Flags&
LvalueBit),
50 typename internal::conditional<internal::is_arithmetic<Scalar>::value, Scalar,
const Scalar>::type
51 >::type CoeffReturnType;
53 typedef typename internal::add_const_on_value_type_if_arithmetic<
54 typename internal::packet_traits<Scalar>::type
55 >::type PacketReturnType;
64 EIGEN_STRONG_INLINE
Index rowIndexByOuterInner(
Index outer,
Index inner)
const
66 return int(Derived::RowsAtCompileTime) == 1 ? 0
67 : int(Derived::ColsAtCompileTime) == 1 ? inner
73 EIGEN_STRONG_INLINE
Index colIndexByOuterInner(
Index outer,
Index inner)
const
75 return int(Derived::ColsAtCompileTime) == 1 ? 0
76 : int(Derived::RowsAtCompileTime) == 1 ? inner
98 eigen_internal_assert(row >= 0 && row < rows()
99 && col >= 0 && col < cols());
100 return internal::evaluator<Derived>(derived()).coeff(row,col);
104 EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner)
const
106 return coeff(rowIndexByOuterInner(outer, inner),
107 colIndexByOuterInner(outer, inner));
117 eigen_assert(row >= 0 && row < rows()
118 && col >= 0 && col < cols());
119 return coeff(row, col);
138 EIGEN_STRONG_INLINE CoeffReturnType
141 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
142 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
143 eigen_internal_assert(index >= 0 && index < size());
144 return internal::evaluator<Derived>(derived()).coeff(index);
157 EIGEN_STRONG_INLINE CoeffReturnType
160 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
161 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
162 eigen_assert(index >= 0 && index < size());
177 EIGEN_STRONG_INLINE CoeffReturnType
180 eigen_assert(index >= 0 && index < size());
187 EIGEN_STRONG_INLINE CoeffReturnType
188 x()
const {
return (*
this)[0]; }
193 EIGEN_STRONG_INLINE CoeffReturnType
194 y()
const {
return (*
this)[1]; }
199 EIGEN_STRONG_INLINE CoeffReturnType
200 z()
const {
return (*
this)[2]; }
205 EIGEN_STRONG_INLINE CoeffReturnType
206 w()
const {
return (*
this)[3]; }
218 template<
int LoadMode>
219 EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col)
const
221 typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
222 eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
223 return internal::evaluator<Derived>(derived()).
template packet<LoadMode,DefaultPacketType>(row,col);
228 template<
int LoadMode>
229 EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner)
const
231 return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
232 colIndexByOuterInner(outer, inner));
245 template<
int LoadMode>
246 EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const
248 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
249 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
250 typedef typename
internal::packet_traits<Scalar>::type DefaultPacketType;
251 eigen_internal_assert(index >= 0 && index < size());
252 return
internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(index);
262 void coeffRefByOuterInner();
264 void writePacketByOuterInner();
266 void copyCoeffByOuterInner();
268 void copyPacketByOuterInner();
287 template<typename Derived>
294 typedef typename internal::traits<Derived>::StorageKind StorageKind;
295 typedef typename internal::traits<Derived>::Scalar Scalar;
296 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
304 using Base::rowIndexByOuterInner;
305 using Base::colIndexByOuterInner;
306 using Base::operator[];
307 using Base::operator();
330 eigen_internal_assert(row >= 0 && row < rows()
331 && col >= 0 && col < cols());
332 return internal::evaluator<Derived>(derived()).coeffRef(row,col);
336 EIGEN_STRONG_INLINE Scalar&
337 coeffRefByOuterInner(Index outer, Index inner)
339 return coeffRef(rowIndexByOuterInner(outer, inner),
340 colIndexByOuterInner(outer, inner));
349 EIGEN_STRONG_INLINE Scalar&
352 eigen_assert(row >= 0 && row < rows()
353 && col >= 0 && col < cols());
354 return coeffRef(row, col);
374 EIGEN_STRONG_INLINE Scalar&
377 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit,
378 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
379 eigen_internal_assert(index >= 0 && index < size());
380 return internal::evaluator<Derived>(derived()).coeffRef(index);
391 EIGEN_STRONG_INLINE Scalar&
394 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
395 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
396 eigen_assert(index >= 0 && index < size());
397 return coeffRef(index);
410 EIGEN_STRONG_INLINE Scalar&
413 eigen_assert(index >= 0 && index < size());
414 return coeffRef(index);
420 EIGEN_STRONG_INLINE Scalar&
421 x() {
return (*
this)[0]; }
426 EIGEN_STRONG_INLINE Scalar&
427 y() {
return (*
this)[1]; }
432 EIGEN_STRONG_INLINE Scalar&
433 z() {
return (*
this)[2]; }
438 EIGEN_STRONG_INLINE Scalar&
439 w() {
return (*
this)[3]; }
453 template<
typename Derived>
454 class DenseCoeffsBase<Derived,
DirectAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors>
459 typedef typename internal::traits<Derived>::Scalar Scalar;
474 return derived().innerStride();
485 return derived().outerStride();
489 inline Index stride()
const
491 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
501 return Derived::IsRowMajor ? outerStride() : innerStride();
511 return Derived::IsRowMajor ? innerStride() : outerStride();
526 template<
typename Derived>
528 :
public DenseCoeffsBase<Derived, WriteAccessors>
533 typedef typename internal::traits<Derived>::Scalar Scalar;
548 return derived().innerStride();
559 return derived().outerStride();
563 inline Index stride()
const
565 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
575 return Derived::IsRowMajor ? outerStride() : innerStride();
585 return Derived::IsRowMajor ? innerStride() : outerStride();
591 template<
int Alignment,
typename Derived,
bool JustReturnZero>
592 struct first_aligned_impl
594 static inline Index run(
const Derived&)
598 template<
int Alignment,
typename Derived>
599 struct first_aligned_impl<Alignment, Derived, false>
601 static inline Index run(
const Derived& m)
603 return internal::first_aligned<Alignment>(&m.const_cast_derived().coeffRef(0,0), m.size());
614 template<
int Alignment,
typename Derived>
615 static inline Index first_aligned(
const DenseBase<Derived>& m)
617 enum { ReturnZero = (int(evaluator<Derived>::Alignment) >= Alignment) || !(Derived::Flags &
DirectAccessBit) };
618 return first_aligned_impl<Alignment, Derived, ReturnZero>::run(m.derived());
621 template<
typename Derived>
622 static inline Index first_default_aligned(
const DenseBase<Derived>& m)
624 typedef typename Derived::Scalar Scalar;
625 typedef typename packet_traits<Scalar>::type DefaultPacketType;
626 return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment),Derived>(m);
629 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
630 struct inner_stride_at_compile_time
632 enum { ret = traits<Derived>::InnerStrideAtCompileTime };
635 template<
typename Derived>
636 struct inner_stride_at_compile_time<Derived, false>
641 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
642 struct outer_stride_at_compile_time
644 enum { ret = traits<Derived>::OuterStrideAtCompileTime };
647 template<
typename Derived>
648 struct outer_stride_at_compile_time<Derived, false>
657 #endif // EIGEN_DENSECOEFFSBASE_H
Scalar & operator()(Index row, Index col)
Definition: DenseCoeffsBase.h:350
CoeffReturnType coeff(Index row, Index col) const
Definition: DenseCoeffsBase.h:96
Definition: Constants.h:368
CoeffReturnType coeff(Index index) const
Definition: DenseCoeffsBase.h:139
const unsigned int DirectAccessBit
Definition: Constants.h:149
Scalar & coeffRef(Index index)
Definition: DenseCoeffsBase.h:375
const unsigned int LvalueBit
Definition: Constants.h:138
Scalar & operator()(Index index)
Definition: DenseCoeffsBase.h:411
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:107
Scalar & y()
Definition: DenseCoeffsBase.h:427
CoeffReturnType w() const
Definition: DenseCoeffsBase.h:206
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
const unsigned int RowMajorBit
Definition: Constants.h:61
Index rowStride() const
Definition: DenseCoeffsBase.h:573
CoeffReturnType z() const
Definition: DenseCoeffsBase.h:200
Scalar & operator[](Index index)
Definition: DenseCoeffsBase.h:392
CoeffReturnType operator()(Index row, Index col) const
Definition: DenseCoeffsBase.h:115
Definition: EigenBase.h:28
Scalar & z()
Definition: DenseCoeffsBase.h:433
Definition: Constants.h:366
Index outerStride() const
Definition: DenseCoeffsBase.h:483
Index outerStride() const
Definition: DenseCoeffsBase.h:557
Index colStride() const
Definition: DenseCoeffsBase.h:509
Definition: Constants.h:370
Scalar & x()
Definition: DenseCoeffsBase.h:421
Index innerStride() const
Definition: DenseCoeffsBase.h:546
Definition: Constants.h:372
Definition: Eigen_Colamd.h:54
CoeffReturnType operator()(Index index) const
Definition: DenseCoeffsBase.h:178
Index rowStride() const
Definition: DenseCoeffsBase.h:499
CoeffReturnType x() const
Definition: DenseCoeffsBase.h:188
Scalar & w()
Definition: DenseCoeffsBase.h:439
Base class providing read-only coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:34
Index innerStride() const
Definition: DenseCoeffsBase.h:472
CoeffReturnType y() const
Definition: DenseCoeffsBase.h:194
Base class providing read/write coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:288
Scalar & coeffRef(Index row, Index col)
Definition: DenseCoeffsBase.h:328
const unsigned int LinearAccessBit
Definition: Constants.h:124
CoeffReturnType operator[](Index index) const
Definition: DenseCoeffsBase.h:158
Index colStride() const
Definition: DenseCoeffsBase.h:583