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;
34 template<
typename Derived>
38 typedef typename internal::traits<Derived>::StorageKind StorageKind;
39 typedef typename internal::traits<Derived>::Scalar Scalar;
40 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
49 typedef typename internal::conditional<bool(internal::traits<Derived>::Flags&
LvalueBit),
51 typename internal::conditional<internal::is_arithmetic<Scalar>::value, Scalar,
const Scalar>::type
52 >::type CoeffReturnType;
54 typedef typename internal::add_const_on_value_type_if_arithmetic<
55 typename internal::packet_traits<Scalar>::type
56 >::type PacketReturnType;
65 EIGEN_STRONG_INLINE
Index rowIndexByOuterInner(
Index outer,
Index inner)
const
67 return int(Derived::RowsAtCompileTime) == 1 ? 0
68 : int(Derived::ColsAtCompileTime) == 1 ? inner
74 EIGEN_STRONG_INLINE
Index colIndexByOuterInner(
Index outer,
Index inner)
const
76 return int(Derived::ColsAtCompileTime) == 1 ? 0
77 : int(Derived::RowsAtCompileTime) == 1 ? inner
99 eigen_internal_assert(row >= 0 && row < rows()
100 && col >= 0 && col < cols());
101 return internal::evaluator<Derived>(derived()).coeff(row,col);
105 EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(
Index outer,
Index inner)
const
107 return coeff(rowIndexByOuterInner(outer, inner),
108 colIndexByOuterInner(outer, inner));
118 eigen_assert(row >= 0 && row < rows()
119 && col >= 0 && col < cols());
120 return coeff(row, col);
139 EIGEN_STRONG_INLINE CoeffReturnType
142 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
143 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
144 eigen_internal_assert(index >= 0 && index < size());
145 return internal::evaluator<Derived>(derived()).coeff(index);
158 EIGEN_STRONG_INLINE CoeffReturnType
161 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
162 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
163 eigen_assert(index >= 0 && index < size());
178 EIGEN_STRONG_INLINE CoeffReturnType
181 eigen_assert(index >= 0 && index < size());
188 EIGEN_STRONG_INLINE CoeffReturnType
189 x()
const {
return (*
this)[0]; }
194 EIGEN_STRONG_INLINE CoeffReturnType
197 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
204 EIGEN_STRONG_INLINE CoeffReturnType
207 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
214 EIGEN_STRONG_INLINE CoeffReturnType
217 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
231 template<
int LoadMode>
232 EIGEN_STRONG_INLINE PacketReturnType packet(
Index row,
Index col)
const
234 typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
235 eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
236 return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(row,col);
241 template<
int LoadMode>
242 EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(
Index outer,
Index inner)
const
244 return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
245 colIndexByOuterInner(outer, inner));
258 template<
int LoadMode>
259 EIGEN_STRONG_INLINE PacketReturnType packet(
Index index)
const
261 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
262 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
263 typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
264 eigen_internal_assert(index >= 0 && index < size());
265 return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(index);
275 void coeffRefByOuterInner();
277 void writePacketByOuterInner();
279 void copyCoeffByOuterInner();
281 void copyPacketByOuterInner();
301 template<
typename Derived>
302 class DenseCoeffsBase<Derived,
WriteAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors>
308 typedef typename internal::traits<Derived>::StorageKind StorageKind;
309 typedef typename internal::traits<Derived>::Scalar Scalar;
310 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
318 using Base::rowIndexByOuterInner;
319 using Base::colIndexByOuterInner;
320 using Base::operator[];
321 using Base::operator();
344 eigen_internal_assert(row >= 0 && row < rows()
345 && col >= 0 && col < cols());
346 return internal::evaluator<Derived>(derived()).coeffRef(row,col);
350 EIGEN_STRONG_INLINE Scalar&
351 coeffRefByOuterInner(
Index outer,
Index inner)
353 return coeffRef(rowIndexByOuterInner(outer, inner),
354 colIndexByOuterInner(outer, inner));
363 EIGEN_STRONG_INLINE Scalar&
366 eigen_assert(row >= 0 && row < rows()
367 && col >= 0 && col < cols());
368 return coeffRef(row, col);
388 EIGEN_STRONG_INLINE Scalar&
391 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
392 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
393 eigen_internal_assert(index >= 0 && index < size());
394 return internal::evaluator<Derived>(derived()).coeffRef(index);
405 EIGEN_STRONG_INLINE Scalar&
408 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
409 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
410 eigen_assert(index >= 0 && index < size());
411 return coeffRef(index);
424 EIGEN_STRONG_INLINE Scalar&
427 eigen_assert(index >= 0 && index < size());
428 return coeffRef(index);
434 EIGEN_STRONG_INLINE Scalar&
435 x() {
return (*
this)[0]; }
440 EIGEN_STRONG_INLINE Scalar&
443 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
450 EIGEN_STRONG_INLINE Scalar&
453 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
460 EIGEN_STRONG_INLINE Scalar&
463 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
480 template<
typename Derived>
481 class DenseCoeffsBase<Derived,
DirectAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors>
486 typedef typename internal::traits<Derived>::Scalar Scalar;
501 return derived().innerStride();
512 return derived().outerStride();
516 inline Index stride()
const
518 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
528 return Derived::IsRowMajor ? outerStride() : innerStride();
538 return Derived::IsRowMajor ? innerStride() : outerStride();
554 template<
typename Derived>
556 :
public DenseCoeffsBase<Derived, WriteAccessors>
561 typedef typename internal::traits<Derived>::Scalar Scalar;
576 return derived().innerStride();
587 return derived().outerStride();
591 inline Index stride()
const
593 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
603 return Derived::IsRowMajor ? outerStride() : innerStride();
613 return Derived::IsRowMajor ? innerStride() : outerStride();
619 template<
int Alignment,
typename Derived,
bool JustReturnZero>
620 struct first_aligned_impl
622 static inline Index run(
const Derived&)
626 template<
int Alignment,
typename Derived>
627 struct first_aligned_impl<Alignment, Derived, false>
629 static inline Index run(
const Derived& m)
631 return internal::first_aligned<Alignment>(m.data(), m.size());
642 template<
int Alignment,
typename Derived>
643 static inline Index first_aligned(
const DenseBase<Derived>& m)
645 enum { ReturnZero = (int(evaluator<Derived>::Alignment) >= Alignment) || !(Derived::Flags &
DirectAccessBit) };
646 return first_aligned_impl<Alignment, Derived, ReturnZero>::run(m.derived());
649 template<
typename Derived>
650 static inline Index first_default_aligned(
const DenseBase<Derived>& m)
652 typedef typename Derived::Scalar Scalar;
653 typedef typename packet_traits<Scalar>::type DefaultPacketType;
654 return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment),Derived>(m);
657 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
658 struct inner_stride_at_compile_time
660 enum { ret = traits<Derived>::InnerStrideAtCompileTime };
663 template<
typename Derived>
664 struct inner_stride_at_compile_time<Derived, false>
669 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
670 struct outer_stride_at_compile_time
672 enum { ret = traits<Derived>::OuterStrideAtCompileTime };
675 template<
typename Derived>
676 struct outer_stride_at_compile_time<Derived, false>
Index innerStride() const
Definition: DenseCoeffsBase.h:499
Index rowStride() const
Definition: DenseCoeffsBase.h:526
Index colStride() const
Definition: DenseCoeffsBase.h:536
Index outerStride() const
Definition: DenseCoeffsBase.h:510
Index rowStride() const
Definition: DenseCoeffsBase.h:601
Index outerStride() const
Definition: DenseCoeffsBase.h:585
Index innerStride() const
Definition: DenseCoeffsBase.h:574
Index colStride() const
Definition: DenseCoeffsBase.h:611
Base class providing read-only coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:36
CoeffReturnType y() const
Definition: DenseCoeffsBase.h:195
CoeffReturnType x() const
Definition: DenseCoeffsBase.h:189
CoeffReturnType operator[](Index index) const
Definition: DenseCoeffsBase.h:159
CoeffReturnType z() const
Definition: DenseCoeffsBase.h:205
CoeffReturnType w() const
Definition: DenseCoeffsBase.h:215
CoeffReturnType coeff(Index index) const
Definition: DenseCoeffsBase.h:140
CoeffReturnType operator()(Index row, Index col) const
Definition: DenseCoeffsBase.h:116
CoeffReturnType coeff(Index row, Index col) const
Definition: DenseCoeffsBase.h:97
CoeffReturnType operator()(Index index) const
Definition: DenseCoeffsBase.h:179
Base class providing read/write coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:303
Scalar & operator()(Index index)
Definition: DenseCoeffsBase.h:425
Scalar & z()
Definition: DenseCoeffsBase.h:451
Scalar & operator[](Index index)
Definition: DenseCoeffsBase.h:406
Scalar & coeffRef(Index row, Index col)
Definition: DenseCoeffsBase.h:342
Scalar & coeffRef(Index index)
Definition: DenseCoeffsBase.h:389
Scalar & operator()(Index row, Index col)
Definition: DenseCoeffsBase.h:364
Scalar & x()
Definition: DenseCoeffsBase.h:435
Scalar & w()
Definition: DenseCoeffsBase.h:461
Scalar & y()
Definition: DenseCoeffsBase.h:441
@ DirectAccessors
Definition: Constants.h:380
@ ReadOnlyAccessors
Definition: Constants.h:376
@ WriteAccessors
Definition: Constants.h:378
@ DirectWriteAccessors
Definition: Constants.h:382
const unsigned int LinearAccessBit
Definition: Constants.h:130
const unsigned int DirectAccessBit
Definition: Constants.h:155
const unsigned int LvalueBit
Definition: Constants.h:144
const unsigned int RowMajorBit
Definition: Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition: Core:134
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: EigenBase.h:30
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:39
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:213