File indexing completed on 2025-10-30 08:39:31
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 #ifndef EIGEN_DENSECOEFFSBASE_H
0011 #define EIGEN_DENSECOEFFSBASE_H
0012 
0013 namespace Eigen {
0014 
0015 namespace internal {
0016 template<typename T> struct add_const_on_value_type_if_arithmetic
0017 {
0018   typedef typename conditional<is_arithmetic<T>::value, T, typename add_const_on_value_type<T>::type>::type type;
0019 };
0020 }
0021 
0022 
0023 
0024 
0025 
0026 
0027 
0028 
0029 
0030 
0031 
0032 
0033 
0034 template<typename Derived>
0035 class DenseCoeffsBase<Derived,ReadOnlyAccessors> : public EigenBase<Derived>
0036 {
0037   public:
0038     typedef typename internal::traits<Derived>::StorageKind StorageKind;
0039     typedef typename internal::traits<Derived>::Scalar Scalar;
0040     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
0041 
0042     
0043     
0044     
0045     
0046     
0047     
0048     
0049     typedef typename internal::conditional<bool(internal::traits<Derived>::Flags&LvalueBit),
0050                          const Scalar&,
0051                          typename internal::conditional<internal::is_arithmetic<Scalar>::value, Scalar, const Scalar>::type
0052                      >::type CoeffReturnType;
0053 
0054     typedef typename internal::add_const_on_value_type_if_arithmetic<
0055                          typename internal::packet_traits<Scalar>::type
0056                      >::type PacketReturnType;
0057 
0058     typedef EigenBase<Derived> Base;
0059     using Base::rows;
0060     using Base::cols;
0061     using Base::size;
0062     using Base::derived;
0063 
0064     EIGEN_DEVICE_FUNC
0065     EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const
0066     {
0067       return int(Derived::RowsAtCompileTime) == 1 ? 0
0068           : int(Derived::ColsAtCompileTime) == 1 ? inner
0069           : int(Derived::Flags)&RowMajorBit ? outer
0070           : inner;
0071     }
0072 
0073     EIGEN_DEVICE_FUNC
0074     EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) const
0075     {
0076       return int(Derived::ColsAtCompileTime) == 1 ? 0
0077           : int(Derived::RowsAtCompileTime) == 1 ? inner
0078           : int(Derived::Flags)&RowMajorBit ? inner
0079           : outer;
0080     }
0081 
0082     
0083 
0084 
0085 
0086 
0087 
0088 
0089 
0090 
0091 
0092 
0093 
0094 
0095 
0096     EIGEN_DEVICE_FUNC
0097     EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
0098     {
0099       eigen_internal_assert(row >= 0 && row < rows()
0100                          && col >= 0 && col < cols());
0101       return internal::evaluator<Derived>(derived()).coeff(row,col);
0102     }
0103 
0104     EIGEN_DEVICE_FUNC
0105     EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner) const
0106     {
0107       return coeff(rowIndexByOuterInner(outer, inner),
0108                    colIndexByOuterInner(outer, inner));
0109     }
0110 
0111     
0112 
0113 
0114 
0115     EIGEN_DEVICE_FUNC
0116     EIGEN_STRONG_INLINE CoeffReturnType operator()(Index row, Index col) const
0117     {
0118       eigen_assert(row >= 0 && row < rows()
0119           && col >= 0 && col < cols());
0120       return coeff(row, col);
0121     }
0122 
0123     
0124 
0125 
0126 
0127 
0128 
0129 
0130 
0131 
0132 
0133 
0134 
0135 
0136 
0137 
0138     EIGEN_DEVICE_FUNC
0139     EIGEN_STRONG_INLINE CoeffReturnType
0140     coeff(Index index) const
0141     {
0142       EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit,
0143                           THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
0144       eigen_internal_assert(index >= 0 && index < size());
0145       return internal::evaluator<Derived>(derived()).coeff(index);
0146     }
0147 
0148 
0149     
0150 
0151 
0152 
0153 
0154 
0155 
0156 
0157     EIGEN_DEVICE_FUNC
0158     EIGEN_STRONG_INLINE CoeffReturnType
0159     operator[](Index index) const
0160     {
0161       EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
0162                           THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
0163       eigen_assert(index >= 0 && index < size());
0164       return coeff(index);
0165     }
0166 
0167     
0168 
0169 
0170 
0171 
0172 
0173 
0174 
0175 
0176 
0177     EIGEN_DEVICE_FUNC
0178     EIGEN_STRONG_INLINE CoeffReturnType
0179     operator()(Index index) const
0180     {
0181       eigen_assert(index >= 0 && index < size());
0182       return coeff(index);
0183     }
0184 
0185     
0186 
0187     EIGEN_DEVICE_FUNC
0188     EIGEN_STRONG_INLINE CoeffReturnType
0189     x() const { return (*this)[0]; }
0190 
0191     
0192 
0193     EIGEN_DEVICE_FUNC
0194     EIGEN_STRONG_INLINE CoeffReturnType
0195     y() const
0196     {
0197       EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
0198       return (*this)[1];
0199     }
0200 
0201     
0202 
0203     EIGEN_DEVICE_FUNC
0204     EIGEN_STRONG_INLINE CoeffReturnType
0205     z() const
0206     {
0207       EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
0208       return (*this)[2];
0209     }
0210 
0211     
0212 
0213     EIGEN_DEVICE_FUNC
0214     EIGEN_STRONG_INLINE CoeffReturnType
0215     w() const
0216     {
0217       EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
0218       return (*this)[3];
0219     }
0220 
0221     
0222 
0223 
0224 
0225 
0226 
0227 
0228 
0229 
0230 
0231     template<int LoadMode>
0232     EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col) const
0233     {
0234       typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
0235       eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
0236       return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(row,col);
0237     }
0238 
0239 
0240     
0241     template<int LoadMode>
0242     EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner) const
0243     {
0244       return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
0245                               colIndexByOuterInner(outer, inner));
0246     }
0247 
0248     
0249 
0250 
0251 
0252 
0253 
0254 
0255 
0256 
0257 
0258     template<int LoadMode>
0259     EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
0260     {
0261       EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit,
0262                           THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
0263       typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
0264       eigen_internal_assert(index >= 0 && index < size());
0265       return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(index);
0266     }
0267 
0268   protected:
0269     
0270     
0271     
0272     
0273     
0274     void coeffRef();
0275     void coeffRefByOuterInner();
0276     void writePacket();
0277     void writePacketByOuterInner();
0278     void copyCoeff();
0279     void copyCoeffByOuterInner();
0280     void copyPacket();
0281     void copyPacketByOuterInner();
0282     void stride();
0283     void innerStride();
0284     void outerStride();
0285     void rowStride();
0286     void colStride();
0287 };
0288 
0289 
0290 
0291 
0292 
0293 
0294 
0295 
0296 
0297 
0298 
0299 
0300 
0301 template<typename Derived>
0302 class DenseCoeffsBase<Derived, WriteAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
0303 {
0304   public:
0305 
0306     typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base;
0307 
0308     typedef typename internal::traits<Derived>::StorageKind StorageKind;
0309     typedef typename internal::traits<Derived>::Scalar Scalar;
0310     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
0311     typedef typename NumTraits<Scalar>::Real RealScalar;
0312 
0313     using Base::coeff;
0314     using Base::rows;
0315     using Base::cols;
0316     using Base::size;
0317     using Base::derived;
0318     using Base::rowIndexByOuterInner;
0319     using Base::colIndexByOuterInner;
0320     using Base::operator[];
0321     using Base::operator();
0322     using Base::x;
0323     using Base::y;
0324     using Base::z;
0325     using Base::w;
0326 
0327     
0328 
0329 
0330 
0331 
0332 
0333 
0334 
0335 
0336 
0337 
0338 
0339 
0340 
0341     EIGEN_DEVICE_FUNC
0342     EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
0343     {
0344       eigen_internal_assert(row >= 0 && row < rows()
0345                          && col >= 0 && col < cols());
0346       return internal::evaluator<Derived>(derived()).coeffRef(row,col);
0347     }
0348 
0349     EIGEN_DEVICE_FUNC
0350     EIGEN_STRONG_INLINE Scalar&
0351     coeffRefByOuterInner(Index outer, Index inner)
0352     {
0353       return coeffRef(rowIndexByOuterInner(outer, inner),
0354                       colIndexByOuterInner(outer, inner));
0355     }
0356 
0357     
0358 
0359 
0360 
0361 
0362     EIGEN_DEVICE_FUNC
0363     EIGEN_STRONG_INLINE Scalar&
0364     operator()(Index row, Index col)
0365     {
0366       eigen_assert(row >= 0 && row < rows()
0367           && col >= 0 && col < cols());
0368       return coeffRef(row, col);
0369     }
0370 
0371 
0372     
0373 
0374 
0375 
0376 
0377 
0378 
0379 
0380 
0381 
0382 
0383 
0384 
0385 
0386 
0387     EIGEN_DEVICE_FUNC
0388     EIGEN_STRONG_INLINE Scalar&
0389     coeffRef(Index index)
0390     {
0391       EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit,
0392                           THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
0393       eigen_internal_assert(index >= 0 && index < size());
0394       return internal::evaluator<Derived>(derived()).coeffRef(index);
0395     }
0396 
0397     
0398 
0399 
0400 
0401 
0402 
0403 
0404     EIGEN_DEVICE_FUNC
0405     EIGEN_STRONG_INLINE Scalar&
0406     operator[](Index index)
0407     {
0408       EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
0409                           THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
0410       eigen_assert(index >= 0 && index < size());
0411       return coeffRef(index);
0412     }
0413 
0414     
0415 
0416 
0417 
0418 
0419 
0420 
0421 
0422 
0423     EIGEN_DEVICE_FUNC
0424     EIGEN_STRONG_INLINE Scalar&
0425     operator()(Index index)
0426     {
0427       eigen_assert(index >= 0 && index < size());
0428       return coeffRef(index);
0429     }
0430 
0431     
0432 
0433     EIGEN_DEVICE_FUNC
0434     EIGEN_STRONG_INLINE Scalar&
0435     x() { return (*this)[0]; }
0436 
0437     
0438 
0439     EIGEN_DEVICE_FUNC
0440     EIGEN_STRONG_INLINE Scalar&
0441     y()
0442     {
0443       EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
0444       return (*this)[1];
0445     }
0446 
0447     
0448 
0449     EIGEN_DEVICE_FUNC
0450     EIGEN_STRONG_INLINE Scalar&
0451     z()
0452     {
0453       EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
0454       return (*this)[2];
0455     }
0456 
0457     
0458 
0459     EIGEN_DEVICE_FUNC
0460     EIGEN_STRONG_INLINE Scalar&
0461     w()
0462     {
0463       EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
0464       return (*this)[3];
0465     }
0466 };
0467 
0468 
0469 
0470 
0471 
0472 
0473 
0474 
0475 
0476 
0477 
0478 
0479 
0480 template<typename Derived>
0481 class DenseCoeffsBase<Derived, DirectAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
0482 {
0483   public:
0484 
0485     typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base;
0486     typedef typename internal::traits<Derived>::Scalar Scalar;
0487     typedef typename NumTraits<Scalar>::Real RealScalar;
0488 
0489     using Base::rows;
0490     using Base::cols;
0491     using Base::size;
0492     using Base::derived;
0493 
0494     
0495 
0496 
0497 
0498     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0499     inline Index innerStride() const
0500     {
0501       return derived().innerStride();
0502     }
0503 
0504     
0505 
0506 
0507 
0508 
0509     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0510     inline Index outerStride() const
0511     {
0512       return derived().outerStride();
0513     }
0514 
0515     
0516     EIGEN_CONSTEXPR inline Index stride() const
0517     {
0518       return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
0519     }
0520 
0521     
0522 
0523 
0524 
0525     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0526     inline Index rowStride() const
0527     {
0528       return Derived::IsRowMajor ? outerStride() : innerStride();
0529     }
0530 
0531     
0532 
0533 
0534 
0535     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0536     inline Index colStride() const
0537     {
0538       return Derived::IsRowMajor ? innerStride() : outerStride();
0539     }
0540 };
0541 
0542 
0543 
0544 
0545 
0546 
0547 
0548 
0549 
0550 
0551 
0552 
0553 
0554 template<typename Derived>
0555 class DenseCoeffsBase<Derived, DirectWriteAccessors>
0556   : public DenseCoeffsBase<Derived, WriteAccessors>
0557 {
0558   public:
0559 
0560     typedef DenseCoeffsBase<Derived, WriteAccessors> Base;
0561     typedef typename internal::traits<Derived>::Scalar Scalar;
0562     typedef typename NumTraits<Scalar>::Real RealScalar;
0563 
0564     using Base::rows;
0565     using Base::cols;
0566     using Base::size;
0567     using Base::derived;
0568 
0569     
0570 
0571 
0572 
0573     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0574     inline Index innerStride() const EIGEN_NOEXCEPT
0575     {
0576       return derived().innerStride();
0577     }
0578 
0579     
0580 
0581 
0582 
0583 
0584     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0585     inline Index outerStride() const EIGEN_NOEXCEPT
0586     {
0587       return derived().outerStride();
0588     }
0589 
0590     
0591     EIGEN_CONSTEXPR inline Index stride() const EIGEN_NOEXCEPT
0592     {
0593       return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
0594     }
0595 
0596     
0597 
0598 
0599 
0600     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0601     inline Index rowStride() const EIGEN_NOEXCEPT
0602     {
0603       return Derived::IsRowMajor ? outerStride() : innerStride();
0604     }
0605 
0606     
0607 
0608 
0609 
0610     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0611     inline Index colStride() const EIGEN_NOEXCEPT
0612     {
0613       return Derived::IsRowMajor ? innerStride() : outerStride();
0614     }
0615 };
0616 
0617 namespace internal {
0618 
0619 template<int Alignment, typename Derived, bool JustReturnZero>
0620 struct first_aligned_impl
0621 {
0622   static EIGEN_CONSTEXPR inline Index run(const Derived&) EIGEN_NOEXCEPT
0623   { return 0; }
0624 };
0625 
0626 template<int Alignment, typename Derived>
0627 struct first_aligned_impl<Alignment, Derived, false>
0628 {
0629   static inline Index run(const Derived& m)
0630   {
0631     return internal::first_aligned<Alignment>(m.data(), m.size());
0632   }
0633 };
0634 
0635 
0636 
0637 
0638 
0639 
0640 
0641 
0642 template<int Alignment, typename Derived>
0643 static inline Index first_aligned(const DenseBase<Derived>& m)
0644 {
0645   enum { ReturnZero = (int(evaluator<Derived>::Alignment) >= Alignment) || !(Derived::Flags & DirectAccessBit) };
0646   return first_aligned_impl<Alignment, Derived, ReturnZero>::run(m.derived());
0647 }
0648 
0649 template<typename Derived>
0650 static inline Index first_default_aligned(const DenseBase<Derived>& m)
0651 {
0652   typedef typename Derived::Scalar Scalar;
0653   typedef typename packet_traits<Scalar>::type DefaultPacketType;
0654   return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment),Derived>(m);
0655 }
0656 
0657 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
0658 struct inner_stride_at_compile_time
0659 {
0660   enum { ret = traits<Derived>::InnerStrideAtCompileTime };
0661 };
0662 
0663 template<typename Derived>
0664 struct inner_stride_at_compile_time<Derived, false>
0665 {
0666   enum { ret = 0 };
0667 };
0668 
0669 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
0670 struct outer_stride_at_compile_time
0671 {
0672   enum { ret = traits<Derived>::OuterStrideAtCompileTime };
0673 };
0674 
0675 template<typename Derived>
0676 struct outer_stride_at_compile_time<Derived, false>
0677 {
0678   enum { ret = 0 };
0679 };
0680 
0681 } 
0682 
0683 } 
0684 
0685 #endif