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>::Index Index;
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;
64 EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner)
const
66 return int(Derived::RowsAtCompileTime) == 1 ? 0
67 : int(Derived::ColsAtCompileTime) == 1 ? inner
72 EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner)
const
74 return int(Derived::ColsAtCompileTime) == 1 ? 0
75 : int(Derived::RowsAtCompileTime) == 1 ? inner
94 EIGEN_STRONG_INLINE CoeffReturnType
coeff(Index row, Index col)
const
96 eigen_internal_assert(row >= 0 && row < rows()
97 && col >= 0 && col < cols());
98 return derived().coeff(row, col);
101 EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner)
const
103 return coeff(rowIndexByOuterInner(outer, inner),
104 colIndexByOuterInner(outer, inner));
111 EIGEN_STRONG_INLINE CoeffReturnType
operator()(Index row, Index col)
const
113 eigen_assert(row >= 0 && row < rows()
114 && col >= 0 && col < cols());
115 return derived().coeff(row, col);
133 EIGEN_STRONG_INLINE CoeffReturnType
136 eigen_internal_assert(index >= 0 && index < size());
137 return derived().coeff(index);
149 EIGEN_STRONG_INLINE CoeffReturnType
152 #ifndef EIGEN2_SUPPORT
153 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
154 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
156 eigen_assert(index >= 0 && index < size());
157 return derived().coeff(index);
170 EIGEN_STRONG_INLINE CoeffReturnType
173 eigen_assert(index >= 0 && index < size());
174 return derived().coeff(index);
179 EIGEN_STRONG_INLINE CoeffReturnType
180 x()
const {
return (*
this)[0]; }
184 EIGEN_STRONG_INLINE CoeffReturnType
185 y()
const {
return (*
this)[1]; }
189 EIGEN_STRONG_INLINE CoeffReturnType
190 z()
const {
return (*
this)[2]; }
194 EIGEN_STRONG_INLINE CoeffReturnType
195 w()
const {
return (*
this)[3]; }
207 template<
int LoadMode>
208 EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col)
const
210 eigen_internal_assert(row >= 0 && row < rows()
211 && col >= 0 && col < cols());
212 return derived().template packet<LoadMode>(row,col);
217 template<
int LoadMode>
218 EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner)
const
220 return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
221 colIndexByOuterInner(outer, inner));
234 template<
int LoadMode>
235 EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const
237 eigen_internal_assert(index >= 0 && index < size());
238 return derived().template packet<LoadMode>(index);
248 void coeffRefByOuterInner();
250 void writePacketByOuterInner();
252 void copyCoeffByOuterInner();
254 void copyPacketByOuterInner();
273 template<
typename Derived>
274 class DenseCoeffsBase<Derived,
WriteAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors>
280 typedef typename internal::traits<Derived>::StorageKind StorageKind;
281 typedef typename internal::traits<Derived>::Index Index;
282 typedef typename internal::traits<Derived>::Scalar Scalar;
283 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
291 using Base::rowIndexByOuterInner;
292 using Base::colIndexByOuterInner;
293 using Base::operator[];
294 using Base::operator();
314 EIGEN_STRONG_INLINE Scalar&
coeffRef(Index row, Index col)
316 eigen_internal_assert(row >= 0 && row < rows()
317 && col >= 0 && col < cols());
318 return derived().coeffRef(row, col);
321 EIGEN_STRONG_INLINE Scalar&
322 coeffRefByOuterInner(Index outer, Index inner)
324 return coeffRef(rowIndexByOuterInner(outer, inner),
325 colIndexByOuterInner(outer, inner));
333 EIGEN_STRONG_INLINE Scalar&
336 eigen_assert(row >= 0 && row < rows()
337 && col >= 0 && col < cols());
338 return derived().coeffRef(row, col);
357 EIGEN_STRONG_INLINE Scalar&
360 eigen_internal_assert(index >= 0 && index < size());
361 return derived().coeffRef(index);
371 EIGEN_STRONG_INLINE Scalar&
374 #ifndef EIGEN2_SUPPORT
375 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
376 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
378 eigen_assert(index >= 0 && index < size());
379 return derived().coeffRef(index);
391 EIGEN_STRONG_INLINE Scalar&
394 eigen_assert(index >= 0 && index < size());
395 return derived().coeffRef(index);
400 EIGEN_STRONG_INLINE Scalar&
401 x() {
return (*
this)[0]; }
405 EIGEN_STRONG_INLINE Scalar&
406 y() {
return (*
this)[1]; }
410 EIGEN_STRONG_INLINE Scalar&
411 z() {
return (*
this)[2]; }
415 EIGEN_STRONG_INLINE Scalar&
416 w() {
return (*
this)[3]; }
428 template<
int StoreMode>
429 EIGEN_STRONG_INLINE
void writePacket
430 (Index row, Index col,
const typename internal::packet_traits<Scalar>::type& val)
432 eigen_internal_assert(row >= 0 && row < rows()
433 && col >= 0 && col < cols());
434 derived().template writePacket<StoreMode>(row,col,val);
439 template<
int StoreMode>
440 EIGEN_STRONG_INLINE
void writePacketByOuterInner
441 (Index outer, Index inner,
const typename internal::packet_traits<Scalar>::type& val)
443 writePacket<StoreMode>(rowIndexByOuterInner(outer, inner),
444 colIndexByOuterInner(outer, inner),
457 template<
int StoreMode>
458 EIGEN_STRONG_INLINE
void writePacket
459 (Index index,
const typename internal::packet_traits<Scalar>::type& val)
461 eigen_internal_assert(index >= 0 && index < size());
462 derived().template writePacket<StoreMode>(index,val);
465 #ifndef EIGEN_PARSED_BY_DOXYGEN
475 template<
typename OtherDerived>
476 EIGEN_STRONG_INLINE
void copyCoeff(Index row, Index col,
const DenseBase<OtherDerived>& other)
478 eigen_internal_assert(row >= 0 && row < rows()
479 && col >= 0 && col < cols());
480 derived().coeffRef(row, col) = other.derived().coeff(row, col);
491 template<
typename OtherDerived>
492 EIGEN_STRONG_INLINE
void copyCoeff(Index index,
const DenseBase<OtherDerived>& other)
494 eigen_internal_assert(index >= 0 && index < size());
495 derived().coeffRef(index) = other.derived().coeff(index);
499 template<
typename OtherDerived>
500 EIGEN_STRONG_INLINE
void copyCoeffByOuterInner(Index outer, Index inner,
const DenseBase<OtherDerived>& other)
502 const Index row = rowIndexByOuterInner(outer,inner);
503 const Index col = colIndexByOuterInner(outer,inner);
505 derived().copyCoeff(row, col, other);
516 template<
typename OtherDerived,
int StoreMode,
int LoadMode>
517 EIGEN_STRONG_INLINE
void copyPacket(Index row, Index col,
const DenseBase<OtherDerived>& other)
519 eigen_internal_assert(row >= 0 && row < rows()
520 && col >= 0 && col < cols());
521 derived().template writePacket<StoreMode>(row, col,
522 other.derived().template packet<LoadMode>(row, col));
533 template<
typename OtherDerived,
int StoreMode,
int LoadMode>
534 EIGEN_STRONG_INLINE
void copyPacket(Index index,
const DenseBase<OtherDerived>& other)
536 eigen_internal_assert(index >= 0 && index < size());
537 derived().template writePacket<StoreMode>(index,
538 other.derived().template packet<LoadMode>(index));
542 template<
typename OtherDerived,
int StoreMode,
int LoadMode>
543 EIGEN_STRONG_INLINE
void copyPacketByOuterInner(Index outer, Index inner,
const DenseBase<OtherDerived>& other)
545 const Index row = rowIndexByOuterInner(outer,inner);
546 const Index col = colIndexByOuterInner(outer,inner);
548 derived().template copyPacket< OtherDerived, StoreMode, LoadMode>(row, col, other);
565 template<
typename Derived>
566 class DenseCoeffsBase<Derived,
DirectAccessors> :
public DenseCoeffsBase<Derived, ReadOnlyAccessors>
571 typedef typename internal::traits<Derived>::Index Index;
572 typedef typename internal::traits<Derived>::Scalar Scalar;
586 return derived().innerStride();
596 return derived().outerStride();
600 inline Index stride()
const
602 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
611 return Derived::IsRowMajor ? outerStride() : innerStride();
620 return Derived::IsRowMajor ? innerStride() : outerStride();
635 template<
typename Derived>
637 :
public DenseCoeffsBase<Derived, WriteAccessors>
642 typedef typename internal::traits<Derived>::Index Index;
643 typedef typename internal::traits<Derived>::Scalar Scalar;
657 return derived().innerStride();
667 return derived().outerStride();
671 inline Index stride()
const
673 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
682 return Derived::IsRowMajor ? outerStride() : innerStride();
691 return Derived::IsRowMajor ? innerStride() : outerStride();
697 template<
typename Derived,
bool JustReturnZero>
698 struct first_aligned_impl
700 static inline typename Derived::Index run(
const Derived&)
704 template<
typename Derived>
705 struct first_aligned_impl<Derived, false>
707 static inline typename Derived::Index run(
const Derived& m)
709 return internal::first_aligned(&m.const_cast_derived().coeffRef(0,0), m.size());
718 template<
typename Derived>
719 static inline typename Derived::Index first_aligned(
const Derived& m)
721 return first_aligned_impl
726 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
727 struct inner_stride_at_compile_time
729 enum { ret = traits<Derived>::InnerStrideAtCompileTime };
732 template<
typename Derived>
733 struct inner_stride_at_compile_time<Derived, false>
738 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
739 struct outer_stride_at_compile_time
741 enum { ret = traits<Derived>::OuterStrideAtCompileTime };
744 template<
typename Derived>
745 struct outer_stride_at_compile_time<Derived, false>
754 #endif // EIGEN_DENSECOEFFSBASE_H
CoeffReturnType y() const
Definition: DenseCoeffsBase.h:185
CoeffReturnType operator()(Index row, Index col) const
Definition: DenseCoeffsBase.h:111
Scalar & y()
Definition: DenseCoeffsBase.h:406
CoeffReturnType x() const
Definition: DenseCoeffsBase.h:180
Definition: Constants.h:310
CoeffReturnType coeff(Index row, Index col) const
Definition: DenseCoeffsBase.h:94
Index rowStride() const
Definition: DenseCoeffsBase.h:680
Definition: Constants.h:314
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
Definition: Constants.h:312
Index innerStride() const
Definition: DenseCoeffsBase.h:584
Index innerStride() const
Definition: DenseCoeffsBase.h:655
Scalar & x()
Definition: DenseCoeffsBase.h:401
Definition: EigenBase.h:26
Scalar & z()
Definition: DenseCoeffsBase.h:411
Definition: Constants.h:316
Index colStride() const
Definition: DenseCoeffsBase.h:689
CoeffReturnType z() const
Definition: DenseCoeffsBase.h:190
CoeffReturnType coeff(Index index) const
Definition: DenseCoeffsBase.h:134
const unsigned int LvalueBit
Definition: Constants.h:131
CoeffReturnType operator[](Index index) const
Definition: DenseCoeffsBase.h:150
Scalar & coeffRef(Index row, Index col)
Definition: DenseCoeffsBase.h:314
CoeffReturnType operator()(Index index) const
Definition: DenseCoeffsBase.h:171
Index colStride() const
Definition: DenseCoeffsBase.h:618
Scalar & w()
Definition: DenseCoeffsBase.h:416
CoeffReturnType w() const
Definition: DenseCoeffsBase.h:195
Scalar & operator[](Index index)
Definition: DenseCoeffsBase.h:372
Base class providing read-only coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:34
Scalar & operator()(Index row, Index col)
Definition: DenseCoeffsBase.h:334
const unsigned int RowMajorBit
Definition: Constants.h:53
const unsigned int DirectAccessBit
Definition: Constants.h:142
Index outerStride() const
Definition: DenseCoeffsBase.h:665
Index outerStride() const
Definition: DenseCoeffsBase.h:594
Base class providing read/write coefficient access to matrices and arrays.
Definition: DenseCoeffsBase.h:274
Scalar & operator()(Index index)
Definition: DenseCoeffsBase.h:392
Scalar & coeffRef(Index index)
Definition: DenseCoeffsBase.h:358
const unsigned int AlignedBit
Definition: Constants.h:147
Index rowStride() const
Definition: DenseCoeffsBase.h:609