10 #ifndef EIGEN_DENSECOEFFSBASE_H 11 #define EIGEN_DENSECOEFFSBASE_H 14 #include "./InternalHeaderCheck.h" 20 struct add_const_on_value_type_if_arithmetic {
21 typedef std::conditional_t<is_arithmetic<T>::value, T, add_const_on_value_type_t<T>> type;
37 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;
58 std::conditional_t<internal::is_arithmetic<Scalar>::value, Scalar,
const Scalar>>
61 typedef typename internal::add_const_on_value_type_if_arithmetic<typename internal::packet_traits<Scalar>::type>::type
70 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Index rowIndexByOuterInner(
Index outer,
Index inner)
const {
71 return int(Derived::RowsAtCompileTime) == 1 ? 0
72 : int(Derived::ColsAtCompileTime) == 1 ? inner
77 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Index colIndexByOuterInner(
Index outer,
Index inner)
const {
78 return int(Derived::ColsAtCompileTime) == 1 ? 0
79 : int(Derived::RowsAtCompileTime) == 1 ? inner
98 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr CoeffReturnType
coeff(
Index row,
Index col)
const {
99 eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
100 return internal::evaluator<Derived>(derived()).coeff(row, col);
103 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr CoeffReturnType coeffByOuterInner(
Index outer,
Index inner)
const {
104 return coeff(rowIndexByOuterInner(outer, inner), colIndexByOuterInner(outer, inner));
112 eigen_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
113 return coeff(row, col);
131 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr CoeffReturnType
coeff(
Index index)
const {
132 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
133 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
134 eigen_internal_assert(index >= 0 && index < size());
135 return internal::evaluator<Derived>(derived()).coeff(index);
146 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr CoeffReturnType
operator[](
Index index)
const {
147 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
148 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
149 eigen_assert(index >= 0 && index < size());
163 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr CoeffReturnType
operator()(
Index index)
const {
164 eigen_assert(index >= 0 && index < size());
170 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr CoeffReturnType
x()
const {
return (*
this)[0]; }
174 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr CoeffReturnType
y()
const {
175 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 2, OUT_OF_RANGE_ACCESS);
181 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr CoeffReturnType
z()
const {
182 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 3, OUT_OF_RANGE_ACCESS);
188 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr CoeffReturnType
w()
const {
189 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 4, OUT_OF_RANGE_ACCESS);
203 template <
int LoadMode>
204 EIGEN_STRONG_INLINE PacketReturnType packet(
Index row,
Index col)
const {
205 typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
206 eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
207 return internal::evaluator<Derived>(derived()).
template packet<LoadMode, DefaultPacketType>(row, col);
211 template <
int LoadMode>
212 EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(
Index outer,
Index inner)
const {
213 return packet<LoadMode>(rowIndexByOuterInner(outer, inner), colIndexByOuterInner(outer, inner));
226 template <
int LoadMode>
227 EIGEN_STRONG_INLINE PacketReturnType packet(
Index index)
const {
228 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
229 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
230 typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
231 eigen_internal_assert(index >= 0 && index < size());
232 return internal::evaluator<Derived>(derived()).
template packet<LoadMode, DefaultPacketType>(index);
242 void coeffRefByOuterInner();
244 void writePacketByOuterInner();
246 void copyCoeffByOuterInner();
248 void copyPacketByOuterInner();
268 template <
typename Derived>
269 class DenseCoeffsBase<Derived,
WriteAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors> {
273 typedef typename internal::traits<Derived>::StorageKind StorageKind;
274 typedef typename internal::traits<Derived>::Scalar Scalar;
275 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
279 using Base::colIndexByOuterInner;
282 using Base::rowIndexByOuterInner;
285 using Base::operator[];
286 using Base::operator();
307 eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
308 return internal::evaluator<Derived>(derived()).coeffRef(row, col);
311 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRefByOuterInner(
Index outer,
Index inner) {
312 return coeffRef(rowIndexByOuterInner(outer, inner), colIndexByOuterInner(outer, inner));
321 eigen_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
322 return coeffRef(row, col);
340 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Scalar&
coeffRef(
Index index) {
341 EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags &
LinearAccessBit,
342 THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
343 eigen_internal_assert(index >= 0 && index < size());
344 return internal::evaluator<Derived>(derived()).coeffRef(index);
355 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
356 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
357 eigen_assert(index >= 0 && index < size());
358 return coeffRef(index);
371 eigen_assert(index >= 0 && index < size());
372 return coeffRef(index);
377 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Scalar&
x() {
return (*
this)[0]; }
381 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Scalar&
y() {
382 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 2, OUT_OF_RANGE_ACCESS);
388 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Scalar&
z() {
389 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 3, OUT_OF_RANGE_ACCESS);
395 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Scalar&
w() {
396 EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 4, OUT_OF_RANGE_ACCESS);
413 template <
typename Derived>
414 class DenseCoeffsBase<Derived,
DirectAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors> {
417 typedef typename internal::traits<Derived>::Scalar Scalar;
439 constexpr
Index stride()
const {
return Derived::IsVectorAtCompileTime ? innerStride() : outerStride(); }
445 EIGEN_DEVICE_FUNC constexpr
Index rowStride()
const {
return Derived::IsRowMajor ? outerStride() : innerStride(); }
451 EIGEN_DEVICE_FUNC constexpr
Index colStride()
const {
return Derived::IsRowMajor ? innerStride() : outerStride(); }
466 template <
typename Derived>
470 typedef typename internal::traits<Derived>::Scalar Scalar;
482 EIGEN_DEVICE_FUNC constexpr
Index innerStride() const noexcept {
return derived().innerStride(); }
489 EIGEN_DEVICE_FUNC constexpr
Index outerStride() const noexcept {
return derived().outerStride(); }
492 constexpr
Index stride() const noexcept {
return Derived::IsVectorAtCompileTime ? innerStride() : outerStride(); }
499 return Derived::IsRowMajor ? outerStride() : innerStride();
507 return Derived::IsRowMajor ? innerStride() : outerStride();
513 template <
int Alignment,
typename Derived,
bool JustReturnZero>
514 struct first_aligned_impl {
515 static constexpr
Index run(
const Derived&) noexcept {
return 0; }
518 template <
int Alignment,
typename Derived>
519 struct first_aligned_impl<Alignment, Derived, false> {
520 static inline Index run(
const Derived& m) {
return internal::first_aligned<Alignment>(m.data(), m.size()); }
531 template <
int Alignment,
typename Derived>
532 static inline Index first_aligned(
const DenseBase<Derived>& m) {
533 enum { ReturnZero = (int(evaluator<Derived>::Alignment) >= Alignment) || !(Derived::Flags &
DirectAccessBit) };
534 return first_aligned_impl<Alignment, Derived, ReturnZero>::run(m.derived());
537 template <
typename Derived>
538 static inline Index first_default_aligned(
const DenseBase<Derived>& m) {
539 typedef typename Derived::Scalar Scalar;
540 typedef typename packet_traits<Scalar>::type DefaultPacketType;
541 return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment), Derived>(m);
544 template <typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
545 struct inner_stride_at_compile_time {
546 enum { ret = traits<Derived>::InnerStrideAtCompileTime };
549 template <
typename Derived>
550 struct inner_stride_at_compile_time<Derived, false> {
554 template <typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
555 struct outer_stride_at_compile_time {
556 enum { ret = traits<Derived>::OuterStrideAtCompileTime };
559 template <
typename Derived>
560 struct outer_stride_at_compile_time<Derived, false> {
568 #endif // EIGEN_DENSECOEFFSBASE_H constexpr CoeffReturnType x() const
Definition: DenseCoeffsBase.h:170
constexpr Scalar & operator()(Index row, Index col)
Definition: DenseCoeffsBase.h:320
Definition: Constants.h:374
constexpr CoeffReturnType operator()(Index row, Index col) const
Definition: DenseCoeffsBase.h:111
constexpr Index rowStride() const
Definition: DenseCoeffsBase.h:445
constexpr Scalar & x()
Definition: DenseCoeffsBase.h:377
const unsigned int DirectAccessBit
Definition: Constants.h:159
constexpr CoeffReturnType coeff(Index row, Index col) const
Definition: DenseCoeffsBase.h:98
constexpr Index outerStride() const noexcept
Definition: DenseCoeffsBase.h:489
const unsigned int LvalueBit
Definition: Constants.h:148
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
constexpr CoeffReturnType z() const
Definition: DenseCoeffsBase.h:181
constexpr CoeffReturnType coeff(Index index) const
Definition: DenseCoeffsBase.h:131
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
const unsigned int RowMajorBit
Definition: Constants.h:70
constexpr Index colStride() const noexcept
Definition: DenseCoeffsBase.h:506
constexpr Index innerStride() const
Definition: DenseCoeffsBase.h:429
Definition: EigenBase.h:33
Definition: Constants.h:372
constexpr Scalar & operator()(Index index)
Definition: DenseCoeffsBase.h:370
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
constexpr CoeffReturnType y() const
Definition: DenseCoeffsBase.h:174
constexpr CoeffReturnType operator()(Index index) const
Definition: DenseCoeffsBase.h:163
constexpr Scalar & coeffRef(Index row, Index col)
Definition: DenseCoeffsBase.h:306
Definition: Constants.h:376
constexpr Scalar & z()
Definition: DenseCoeffsBase.h:388
constexpr Scalar & operator[](Index index)
Definition: DenseCoeffsBase.h:354
constexpr Scalar & y()
Definition: DenseCoeffsBase.h:381
Definition: Constants.h:378
constexpr Scalar & w()
Definition: DenseCoeffsBase.h:395
constexpr CoeffReturnType operator[](Index index) const
Definition: DenseCoeffsBase.h:146
constexpr CoeffReturnType w() const
Definition: DenseCoeffsBase.h:188
Base class providing read-only coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:38
constexpr Index rowStride() const noexcept
Definition: DenseCoeffsBase.h:498
constexpr Index innerStride() const noexcept
Definition: DenseCoeffsBase.h:482
Base class providing read/write coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:269
constexpr Index outerStride() const
Definition: DenseCoeffsBase.h:436
const unsigned int LinearAccessBit
Definition: Constants.h:133
constexpr Index colStride() const
Definition: DenseCoeffsBase.h:451
constexpr Scalar & coeffRef(Index index)
Definition: DenseCoeffsBase.h:340