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_internal_assert(index >= 0 && index < size());
142 return internal::evaluator<Derived>(derived()).coeff(index);
155 EIGEN_STRONG_INLINE CoeffReturnType
158 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
159 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
160 eigen_assert(index >= 0 && index < size());
175 EIGEN_STRONG_INLINE CoeffReturnType
178 eigen_assert(index >= 0 && index < size());
185 EIGEN_STRONG_INLINE CoeffReturnType
186 x()
const {
return (*
this)[0]; }
191 EIGEN_STRONG_INLINE CoeffReturnType
192 y()
const {
return (*
this)[1]; }
197 EIGEN_STRONG_INLINE CoeffReturnType
198 z()
const {
return (*
this)[2]; }
203 EIGEN_STRONG_INLINE CoeffReturnType
204 w()
const {
return (*
this)[3]; }
216 template<
int LoadMode>
217 EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col)
const
219 typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
220 eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
221 return internal::evaluator<Derived>(derived()).
template packet<LoadMode,DefaultPacketType>(row,col);
226 template<
int LoadMode>
227 EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner)
const
229 return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
230 colIndexByOuterInner(outer, inner));
243 template<
int LoadMode>
244 EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const
246 typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
247 eigen_internal_assert(index >= 0 && index < size());
248 return internal::evaluator<Derived>(derived()).
template packet<LoadMode,DefaultPacketType>(index);
258 void coeffRefByOuterInner();
260 void writePacketByOuterInner();
262 void copyCoeffByOuterInner();
264 void copyPacketByOuterInner();
283 template<
typename Derived>
284 class DenseCoeffsBase<Derived,
WriteAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors>
290 typedef typename internal::traits<Derived>::StorageKind StorageKind;
291 typedef typename internal::traits<Derived>::Scalar Scalar;
292 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
300 using Base::rowIndexByOuterInner;
301 using Base::colIndexByOuterInner;
302 using Base::operator[];
303 using Base::operator();
326 eigen_internal_assert(row >= 0 && row < rows()
327 && col >= 0 && col < cols());
328 return internal::evaluator<Derived>(derived()).coeffRef(row,col);
332 EIGEN_STRONG_INLINE Scalar&
333 coeffRefByOuterInner(Index outer, Index inner)
335 return coeffRef(rowIndexByOuterInner(outer, inner),
336 colIndexByOuterInner(outer, inner));
345 EIGEN_STRONG_INLINE Scalar&
348 eigen_assert(row >= 0 && row < rows()
349 && col >= 0 && col < cols());
350 return coeffRef(row, col);
370 EIGEN_STRONG_INLINE Scalar&
373 eigen_internal_assert(index >= 0 && index < size());
374 return internal::evaluator<Derived>(derived()).coeffRef(index);
385 EIGEN_STRONG_INLINE Scalar&
388 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
389 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
390 eigen_assert(index >= 0 && index < size());
391 return coeffRef(index);
404 EIGEN_STRONG_INLINE Scalar&
407 eigen_assert(index >= 0 && index < size());
408 return coeffRef(index);
414 EIGEN_STRONG_INLINE Scalar&
415 x() {
return (*
this)[0]; }
420 EIGEN_STRONG_INLINE Scalar&
421 y() {
return (*
this)[1]; }
426 EIGEN_STRONG_INLINE Scalar&
427 z() {
return (*
this)[2]; }
432 EIGEN_STRONG_INLINE Scalar&
433 w() {
return (*
this)[3]; }
447 template<
typename Derived>
448 class DenseCoeffsBase<Derived,
DirectAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors>
453 typedef typename internal::traits<Derived>::Scalar Scalar;
468 return derived().innerStride();
479 return derived().outerStride();
483 inline Index stride()
const
485 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
495 return Derived::IsRowMajor ? outerStride() : innerStride();
505 return Derived::IsRowMajor ? innerStride() : outerStride();
520 template<
typename Derived>
522 :
public DenseCoeffsBase<Derived, WriteAccessors>
527 typedef typename internal::traits<Derived>::Scalar Scalar;
542 return derived().innerStride();
553 return derived().outerStride();
557 inline Index stride()
const
559 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
569 return Derived::IsRowMajor ? outerStride() : innerStride();
579 return Derived::IsRowMajor ? innerStride() : outerStride();
585 template<
int Alignment,
typename Derived,
bool JustReturnZero>
586 struct first_aligned_impl
588 static inline Index run(
const Derived&)
592 template<
int Alignment,
typename Derived>
593 struct first_aligned_impl<Alignment, Derived, false>
595 static inline Index run(
const Derived& m)
597 return internal::first_aligned<Alignment>(&m.const_cast_derived().coeffRef(0,0), m.size());
608 template<
int Alignment,
typename Derived>
609 static inline Index first_aligned(
const DenseBase<Derived>& m)
611 enum { ReturnZero = (int(evaluator<Derived>::Alignment) >= Alignment) || !(Derived::Flags &
DirectAccessBit) };
612 return first_aligned_impl<Alignment, Derived, ReturnZero>::run(m.derived());
615 template<
typename Derived>
616 static inline Index first_default_aligned(
const DenseBase<Derived>& m)
618 typedef typename Derived::Scalar Scalar;
619 typedef typename packet_traits<Scalar>::type DefaultPacketType;
620 return first_aligned<unpacket_traits<DefaultPacketType>::alignment>(m);
623 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
624 struct inner_stride_at_compile_time
626 enum { ret = traits<Derived>::InnerStrideAtCompileTime };
629 template<
typename Derived>
630 struct inner_stride_at_compile_time<Derived, false>
635 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
636 struct outer_stride_at_compile_time
638 enum { ret = traits<Derived>::OuterStrideAtCompileTime };
641 template<
typename Derived>
642 struct outer_stride_at_compile_time<Derived, false>
651 #endif // EIGEN_DENSECOEFFSBASE_H
Scalar & operator()(Index row, Index col)
Definition: DenseCoeffsBase.h:346
CoeffReturnType coeff(Index row, Index col) const
Definition: DenseCoeffsBase.h:96
Definition: Constants.h:360
CoeffReturnType coeff(Index index) const
Definition: DenseCoeffsBase.h:139
const unsigned int DirectAccessBit
Definition: Constants.h:141
Scalar & coeffRef(Index index)
Definition: DenseCoeffsBase.h:371
const unsigned int LvalueBit
Definition: Constants.h:130
Scalar & operator()(Index index)
Definition: DenseCoeffsBase.h:405
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:107
Scalar & y()
Definition: DenseCoeffsBase.h:421
CoeffReturnType w() const
Definition: DenseCoeffsBase.h:204
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
const unsigned int RowMajorBit
Definition: Constants.h:53
Index rowStride() const
Definition: DenseCoeffsBase.h:567
CoeffReturnType z() const
Definition: DenseCoeffsBase.h:198
Scalar & operator[](Index index)
Definition: DenseCoeffsBase.h:386
CoeffReturnType operator()(Index row, Index col) const
Definition: DenseCoeffsBase.h:115
Definition: EigenBase.h:28
Scalar & z()
Definition: DenseCoeffsBase.h:427
Definition: Constants.h:358
Index outerStride() const
Definition: DenseCoeffsBase.h:477
Index outerStride() const
Definition: DenseCoeffsBase.h:551
Index colStride() const
Definition: DenseCoeffsBase.h:503
Definition: Constants.h:362
Scalar & x()
Definition: DenseCoeffsBase.h:415
Index innerStride() const
Definition: DenseCoeffsBase.h:540
Definition: Constants.h:364
Definition: Eigen_Colamd.h:54
CoeffReturnType operator()(Index index) const
Definition: DenseCoeffsBase.h:176
Index rowStride() const
Definition: DenseCoeffsBase.h:493
CoeffReturnType x() const
Definition: DenseCoeffsBase.h:186
Scalar & w()
Definition: DenseCoeffsBase.h:433
Base class providing read-only coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:34
Index innerStride() const
Definition: DenseCoeffsBase.h:466
CoeffReturnType y() const
Definition: DenseCoeffsBase.h:192
Base class providing read/write coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:284
Scalar & coeffRef(Index row, Index col)
Definition: DenseCoeffsBase.h:324
CoeffReturnType operator[](Index index) const
Definition: DenseCoeffsBase.h:156
Index colStride() const
Definition: DenseCoeffsBase.h:577