10#ifndef EIGEN_DENSECOEFFSBASE_H
11#define EIGEN_DENSECOEFFSBASE_H
14#include "./InternalHeaderCheck.h"
20struct 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;
37template <
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
64 typedef EigenBase<Derived> Base;
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));
111 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr CoeffReturnType operator()(
Index row,
Index col)
const {
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();
268template <
typename Derived>
269class DenseCoeffsBase<Derived,
WriteAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors> {
271 typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base;
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;
276 typedef typename NumTraits<Scalar>::Real RealScalar;
279 using Base::colIndexByOuterInner;
282 using Base::rowIndexByOuterInner;
285 using Base::operator[];
286 using Base::operator();
306 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Scalar& coeffRef(
Index row,
Index col) {
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));
320 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Scalar& operator()(
Index row,
Index col) {
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);
354 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Scalar& operator[](
Index 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);
370 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Scalar& operator()(
Index 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);
413template <
typename Derived>
414class DenseCoeffsBase<Derived,
DirectAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors> {
416 typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base;
417 typedef typename internal::traits<Derived>::Scalar Scalar;
418 typedef typename NumTraits<Scalar>::Real RealScalar;
439 constexpr Index stride()
const {
return Derived::IsVectorAtCompileTime ? innerStride() : outerStride(); }
466template <
typename Derived>
469 typedef DenseCoeffsBase<Derived, WriteAccessors> Base;
470 typedef typename internal::traits<Derived>::Scalar Scalar;
471 typedef typename NumTraits<Scalar>::Real RealScalar;
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(); }
513template <
int Alignment,
typename Derived,
bool JustReturnZero>
514struct first_aligned_impl {
515 static constexpr Index run(
const Derived&)
noexcept {
return 0; }
518template <
int Alignment,
typename Derived>
519struct first_aligned_impl<Alignment, Derived, false> {
520 static inline Index run(
const Derived& m) {
return internal::first_aligned<Alignment>(m.data(), m.size()); }
531template <
int Alignment,
typename Derived>
532static 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());
537template <
typename Derived>
538static 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);
544template <typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
545struct inner_stride_at_compile_time {
546 enum { ret = traits<Derived>::InnerStrideAtCompileTime };
549template <
typename Derived>
550struct inner_stride_at_compile_time<Derived, false> {
554template <typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
555struct outer_stride_at_compile_time {
556 enum { ret = traits<Derived>::OuterStrideAtCompileTime };
559template <
typename Derived>
560struct outer_stride_at_compile_time<Derived, false> {
constexpr Index rowStride() const
Definition DenseCoeffsBase.h:445
constexpr Index innerStride() const
Definition DenseCoeffsBase.h:429
constexpr Index colStride() const
Definition DenseCoeffsBase.h:451
constexpr Index outerStride() const
Definition DenseCoeffsBase.h:436
constexpr Index colStride() const noexcept
Definition DenseCoeffsBase.h:506
constexpr Index innerStride() const noexcept
Definition DenseCoeffsBase.h:482
constexpr Index outerStride() const noexcept
Definition DenseCoeffsBase.h:489
constexpr Index rowStride() const noexcept
Definition DenseCoeffsBase.h:498
@ DirectAccessors
Definition Constants.h:376
@ ReadOnlyAccessors
Definition Constants.h:372
@ WriteAccessors
Definition Constants.h:374
@ DirectWriteAccessors
Definition Constants.h:378
const unsigned int LinearAccessBit
Definition Constants.h:133
const unsigned int DirectAccessBit
Definition Constants.h:159
const unsigned int LvalueBit
Definition Constants.h:148
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
Definition EigenBase.h:33