Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:56:13

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_FORCEALIGNEDACCESS_H
0011 #define EIGEN_FORCEALIGNEDACCESS_H
0012 
0013 namespace Eigen {
0014 
0015 /** \class ForceAlignedAccess
0016   * \ingroup Core_Module
0017   *
0018   * \brief Enforce aligned packet loads and stores regardless of what is requested
0019   *
0020   * \param ExpressionType the type of the object of which we are forcing aligned packet access
0021   *
0022   * This class is the return type of MatrixBase::forceAlignedAccess()
0023   * and most of the time this is the only way it is used.
0024   *
0025   * \sa MatrixBase::forceAlignedAccess()
0026   */
0027 
0028 namespace internal {
0029 template<typename ExpressionType>
0030 struct traits<ForceAlignedAccess<ExpressionType> > : public traits<ExpressionType>
0031 {};
0032 }
0033 
0034 template<typename ExpressionType> class ForceAlignedAccess
0035   : public internal::dense_xpr_base< ForceAlignedAccess<ExpressionType> >::type
0036 {
0037   public:
0038 
0039     typedef typename internal::dense_xpr_base<ForceAlignedAccess>::type Base;
0040     EIGEN_DENSE_PUBLIC_INTERFACE(ForceAlignedAccess)
0041 
0042     EIGEN_DEVICE_FUNC explicit inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {}
0043 
0044     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0045     inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
0046     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0047     inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
0048     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0049     inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
0050     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0051     inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
0052 
0053     EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index row, Index col) const
0054     {
0055       return m_expression.coeff(row, col);
0056     }
0057 
0058     EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index col)
0059     {
0060       return m_expression.const_cast_derived().coeffRef(row, col);
0061     }
0062 
0063     EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index index) const
0064     {
0065       return m_expression.coeff(index);
0066     }
0067 
0068     EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index index)
0069     {
0070       return m_expression.const_cast_derived().coeffRef(index);
0071     }
0072 
0073     template<int LoadMode>
0074     inline const PacketScalar packet(Index row, Index col) const
0075     {
0076       return m_expression.template packet<Aligned>(row, col);
0077     }
0078 
0079     template<int LoadMode>
0080     inline void writePacket(Index row, Index col, const PacketScalar& x)
0081     {
0082       m_expression.const_cast_derived().template writePacket<Aligned>(row, col, x);
0083     }
0084 
0085     template<int LoadMode>
0086     inline const PacketScalar packet(Index index) const
0087     {
0088       return m_expression.template packet<Aligned>(index);
0089     }
0090 
0091     template<int LoadMode>
0092     inline void writePacket(Index index, const PacketScalar& x)
0093     {
0094       m_expression.const_cast_derived().template writePacket<Aligned>(index, x);
0095     }
0096 
0097     EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; }
0098 
0099   protected:
0100     const ExpressionType& m_expression;
0101 
0102   private:
0103     ForceAlignedAccess& operator=(const ForceAlignedAccess&);
0104 };
0105 
0106 /** \returns an expression of *this with forced aligned access
0107   * \sa forceAlignedAccessIf(),class ForceAlignedAccess
0108   */
0109 template<typename Derived>
0110 inline const ForceAlignedAccess<Derived>
0111 MatrixBase<Derived>::forceAlignedAccess() const
0112 {
0113   return ForceAlignedAccess<Derived>(derived());
0114 }
0115 
0116 /** \returns an expression of *this with forced aligned access
0117   * \sa forceAlignedAccessIf(), class ForceAlignedAccess
0118   */
0119 template<typename Derived>
0120 inline ForceAlignedAccess<Derived>
0121 MatrixBase<Derived>::forceAlignedAccess()
0122 {
0123   return ForceAlignedAccess<Derived>(derived());
0124 }
0125 
0126 /** \returns an expression of *this with forced aligned access if \a Enable is true.
0127   * \sa forceAlignedAccess(), class ForceAlignedAccess
0128   */
0129 template<typename Derived>
0130 template<bool Enable>
0131 inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type
0132 MatrixBase<Derived>::forceAlignedAccessIf() const
0133 {
0134   return derived();  // FIXME This should not work but apparently is never used
0135 }
0136 
0137 /** \returns an expression of *this with forced aligned access if \a Enable is true.
0138   * \sa forceAlignedAccess(), class ForceAlignedAccess
0139   */
0140 template<typename Derived>
0141 template<bool Enable>
0142 inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type
0143 MatrixBase<Derived>::forceAlignedAccessIf()
0144 {
0145   return derived();  // FIXME This should not work but apparently is never used
0146 }
0147 
0148 } // end namespace Eigen
0149 
0150 #endif // EIGEN_FORCEALIGNEDACCESS_H