10 #ifndef EIGEN_DENSECOEFFSBASE_H
11 #define EIGEN_DENSECOEFFSBASE_H
13 #include "./InternalHeaderCheck.h"
18 template<
typename T>
struct add_const_on_value_type_if_arithmetic
20 typedef std::conditional_t<is_arithmetic<T>::value, T, add_const_on_value_type_t<T>> type;
36 template<
typename Derived>
40 typedef typename internal::traits<Derived>::StorageKind StorageKind;
41 typedef typename internal::traits<Derived>::Scalar Scalar;
42 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
51 typedef std::conditional_t<bool(internal::traits<Derived>::Flags&
LvalueBit),
53 std::conditional_t<internal::is_arithmetic<Scalar>::value, Scalar,
const Scalar>
56 typedef typename internal::add_const_on_value_type_if_arithmetic<
57 typename internal::packet_traits<Scalar>::type
58 >::type PacketReturnType;
67 EIGEN_STRONG_INLINE
Index rowIndexByOuterInner(
Index outer,
Index inner)
const
69 return int(Derived::RowsAtCompileTime) == 1 ? 0
70 : int(Derived::ColsAtCompileTime) == 1 ? inner
76 EIGEN_STRONG_INLINE
Index colIndexByOuterInner(
Index outer,
Index inner)
const
78 return int(Derived::ColsAtCompileTime) == 1 ? 0
79 : int(Derived::RowsAtCompileTime) == 1 ? inner
101 eigen_internal_assert(row >= 0 && row < rows()
102 && col >= 0 && col < cols());
103 return internal::evaluator<Derived>(derived()).coeff(row,col);
107 EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(
Index outer,
Index inner)
const
109 return coeff(rowIndexByOuterInner(outer, inner),
110 colIndexByOuterInner(outer, inner));
120 eigen_assert(row >= 0 && row < rows()
121 && col >= 0 && col < cols());
122 return coeff(row, col);
141 EIGEN_STRONG_INLINE CoeffReturnType
144 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
145 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
146 eigen_internal_assert(index >= 0 && index < size());
147 return internal::evaluator<Derived>(derived()).coeff(index);
160 EIGEN_STRONG_INLINE CoeffReturnType
163 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
164 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
165 eigen_assert(index >= 0 && index < size());
180 EIGEN_STRONG_INLINE CoeffReturnType
183 eigen_assert(index >= 0 && index < size());
190 EIGEN_STRONG_INLINE CoeffReturnType
191 x()
const {
return (*
this)[0]; }
196 EIGEN_STRONG_INLINE CoeffReturnType
199 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
206 EIGEN_STRONG_INLINE CoeffReturnType
209 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
216 EIGEN_STRONG_INLINE CoeffReturnType
219 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
233 template<
int LoadMode>
234 EIGEN_STRONG_INLINE PacketReturnType packet(
Index row,
Index col)
const
236 typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
237 eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
238 return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(row,col);
243 template<
int LoadMode>
244 EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(
Index outer,
Index inner)
const
246 return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
247 colIndexByOuterInner(outer, inner));
260 template<
int LoadMode>
261 EIGEN_STRONG_INLINE PacketReturnType packet(
Index index)
const
263 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
264 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
265 typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
266 eigen_internal_assert(index >= 0 && index < size());
267 return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(index);
277 void coeffRefByOuterInner();
279 void writePacketByOuterInner();
281 void copyCoeffByOuterInner();
283 void copyPacketByOuterInner();
303 template<
typename Derived>
304 class DenseCoeffsBase<Derived,
WriteAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors>
310 typedef typename internal::traits<Derived>::StorageKind StorageKind;
311 typedef typename internal::traits<Derived>::Scalar Scalar;
312 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
320 using Base::rowIndexByOuterInner;
321 using Base::colIndexByOuterInner;
322 using Base::operator[];
323 using Base::operator();
346 eigen_internal_assert(row >= 0 && row < rows()
347 && col >= 0 && col < cols());
348 return internal::evaluator<Derived>(derived()).coeffRef(row,col);
352 EIGEN_STRONG_INLINE Scalar&
353 coeffRefByOuterInner(
Index outer,
Index inner)
355 return coeffRef(rowIndexByOuterInner(outer, inner),
356 colIndexByOuterInner(outer, inner));
365 EIGEN_STRONG_INLINE Scalar&
368 eigen_assert(row >= 0 && row < rows()
369 && col >= 0 && col < cols());
370 return coeffRef(row, col);
390 EIGEN_STRONG_INLINE Scalar&
393 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
394 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
395 eigen_internal_assert(index >= 0 && index < size());
396 return internal::evaluator<Derived>(derived()).coeffRef(index);
407 EIGEN_STRONG_INLINE Scalar&
410 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
411 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
412 eigen_assert(index >= 0 && index < size());
413 return coeffRef(index);
426 EIGEN_STRONG_INLINE Scalar&
429 eigen_assert(index >= 0 && index < size());
430 return coeffRef(index);
436 EIGEN_STRONG_INLINE Scalar&
437 x() {
return (*
this)[0]; }
442 EIGEN_STRONG_INLINE Scalar&
445 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
452 EIGEN_STRONG_INLINE Scalar&
455 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
462 EIGEN_STRONG_INLINE Scalar&
465 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
482 template<
typename Derived>
483 class DenseCoeffsBase<Derived,
DirectAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors>
488 typedef typename internal::traits<Derived>::Scalar Scalar;
500 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
503 return derived().innerStride();
511 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
514 return derived().outerStride();
518 EIGEN_CONSTEXPR
inline Index stride()
const
520 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
527 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
530 return Derived::IsRowMajor ? outerStride() : innerStride();
537 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
540 return Derived::IsRowMajor ? innerStride() : outerStride();
556 template<
typename Derived>
558 :
public DenseCoeffsBase<Derived, WriteAccessors>
563 typedef typename internal::traits<Derived>::Scalar Scalar;
575 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
578 return derived().innerStride();
586 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
589 return derived().outerStride();
593 EIGEN_CONSTEXPR
inline Index stride() const EIGEN_NOEXCEPT
595 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
602 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
605 return Derived::IsRowMajor ? outerStride() : innerStride();
612 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
615 return Derived::IsRowMajor ? innerStride() : outerStride();
621 template<
int Alignment,
typename Derived,
bool JustReturnZero>
622 struct first_aligned_impl
624 static EIGEN_CONSTEXPR
inline Index run(
const Derived&) EIGEN_NOEXCEPT
628 template<
int Alignment,
typename Derived>
629 struct first_aligned_impl<Alignment, Derived, false>
631 static inline Index run(
const Derived& m)
633 return internal::first_aligned<Alignment>(m.data(), m.size());
644 template<
int Alignment,
typename Derived>
645 static inline Index first_aligned(
const DenseBase<Derived>& m)
647 enum { ReturnZero = (int(evaluator<Derived>::Alignment) >= Alignment) || !(Derived::Flags &
DirectAccessBit) };
648 return first_aligned_impl<Alignment, Derived, ReturnZero>::run(m.derived());
651 template<
typename Derived>
652 static inline Index first_default_aligned(
const DenseBase<Derived>& m)
654 typedef typename Derived::Scalar Scalar;
655 typedef typename packet_traits<Scalar>::type DefaultPacketType;
656 return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment),Derived>(m);
659 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
660 struct inner_stride_at_compile_time
662 enum { ret = traits<Derived>::InnerStrideAtCompileTime };
665 template<
typename Derived>
666 struct inner_stride_at_compile_time<Derived, false>
671 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
672 struct outer_stride_at_compile_time
674 enum { ret = traits<Derived>::OuterStrideAtCompileTime };
677 template<
typename Derived>
678 struct outer_stride_at_compile_time<Derived, false>
EIGEN_CONSTEXPR Index innerStride() const
Definition: DenseCoeffsBase.h:501
EIGEN_CONSTEXPR Index rowStride() const
Definition: DenseCoeffsBase.h:528
EIGEN_CONSTEXPR Index outerStride() const
Definition: DenseCoeffsBase.h:512
EIGEN_CONSTEXPR Index colStride() const
Definition: DenseCoeffsBase.h:538
EIGEN_CONSTEXPR Index innerStride() const EIGEN_NOEXCEPT
Definition: DenseCoeffsBase.h:576
EIGEN_CONSTEXPR Index rowStride() const EIGEN_NOEXCEPT
Definition: DenseCoeffsBase.h:603
EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT
Definition: DenseCoeffsBase.h:587
EIGEN_CONSTEXPR Index colStride() const EIGEN_NOEXCEPT
Definition: DenseCoeffsBase.h:613
Base class providing read-only coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:38
CoeffReturnType y() const
Definition: DenseCoeffsBase.h:197
CoeffReturnType x() const
Definition: DenseCoeffsBase.h:191
CoeffReturnType operator[](Index index) const
Definition: DenseCoeffsBase.h:161
CoeffReturnType z() const
Definition: DenseCoeffsBase.h:207
CoeffReturnType w() const
Definition: DenseCoeffsBase.h:217
CoeffReturnType coeff(Index index) const
Definition: DenseCoeffsBase.h:142
CoeffReturnType operator()(Index row, Index col) const
Definition: DenseCoeffsBase.h:118
CoeffReturnType coeff(Index row, Index col) const
Definition: DenseCoeffsBase.h:99
CoeffReturnType operator()(Index index) const
Definition: DenseCoeffsBase.h:181
Base class providing read/write coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:305
Scalar & operator()(Index index)
Definition: DenseCoeffsBase.h:427
Scalar & z()
Definition: DenseCoeffsBase.h:453
Scalar & operator[](Index index)
Definition: DenseCoeffsBase.h:408
Scalar & coeffRef(Index row, Index col)
Definition: DenseCoeffsBase.h:344
Scalar & coeffRef(Index index)
Definition: DenseCoeffsBase.h:391
Scalar & operator()(Index row, Index col)
Definition: DenseCoeffsBase.h:366
Scalar & x()
Definition: DenseCoeffsBase.h:437
Scalar & w()
Definition: DenseCoeffsBase.h:463
Scalar & y()
Definition: DenseCoeffsBase.h:443
@ DirectAccessors
Definition: Constants.h:382
@ ReadOnlyAccessors
Definition: Constants.h:378
@ WriteAccessors
Definition: Constants.h:380
@ DirectWriteAccessors
Definition: Constants.h:384
const unsigned int LinearAccessBit
Definition: Constants.h:132
const unsigned int DirectAccessBit
Definition: Constants.h:157
const unsigned int LvalueBit
Definition: Constants.h:146
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
Definition: EigenBase.h:32
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:231