Back to home page

EIC code displayed by LXR

 
 

    


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

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_ARRAYWRAPPER_H
0011 #define EIGEN_ARRAYWRAPPER_H
0012 
0013 namespace Eigen {
0014 
0015 /** \class ArrayWrapper
0016   * \ingroup Core_Module
0017   *
0018   * \brief Expression of a mathematical vector or matrix as an array object
0019   *
0020   * This class is the return type of MatrixBase::array(), and most of the time
0021   * this is the only way it is use.
0022   *
0023   * \sa MatrixBase::array(), class MatrixWrapper
0024   */
0025 
0026 namespace internal {
0027 template<typename ExpressionType>
0028 struct traits<ArrayWrapper<ExpressionType> >
0029   : public traits<typename remove_all<typename ExpressionType::Nested>::type >
0030 {
0031   typedef ArrayXpr XprKind;
0032   // Let's remove NestByRefBit
0033   enum {
0034     Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
0035     LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
0036     Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
0037   };
0038 };
0039 }
0040 
0041 template<typename ExpressionType>
0042 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
0043 {
0044   public:
0045     typedef ArrayBase<ArrayWrapper> Base;
0046     EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
0047     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
0048     typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
0049 
0050     typedef typename internal::conditional<
0051                        internal::is_lvalue<ExpressionType>::value,
0052                        Scalar,
0053                        const Scalar
0054                      >::type ScalarWithConstIfNotLvalue;
0055 
0056     typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
0057 
0058     using Base::coeffRef;
0059 
0060     EIGEN_DEVICE_FUNC
0061     explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
0062 
0063     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0064     inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
0065     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0066     inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
0067     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0068     inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
0069     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0070     inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
0071 
0072     EIGEN_DEVICE_FUNC
0073     inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
0074     EIGEN_DEVICE_FUNC
0075     inline const Scalar* data() const { return m_expression.data(); }
0076 
0077     EIGEN_DEVICE_FUNC
0078     inline const Scalar& coeffRef(Index rowId, Index colId) const
0079     {
0080       return m_expression.coeffRef(rowId, colId);
0081     }
0082 
0083     EIGEN_DEVICE_FUNC
0084     inline const Scalar& coeffRef(Index index) const
0085     {
0086       return m_expression.coeffRef(index);
0087     }
0088 
0089     template<typename Dest>
0090     EIGEN_DEVICE_FUNC
0091     inline void evalTo(Dest& dst) const { dst = m_expression; }
0092 
0093     EIGEN_DEVICE_FUNC
0094     const typename internal::remove_all<NestedExpressionType>::type&
0095     nestedExpression() const
0096     {
0097       return m_expression;
0098     }
0099 
0100     /** Forwards the resizing request to the nested expression
0101       * \sa DenseBase::resize(Index)  */
0102     EIGEN_DEVICE_FUNC
0103     void resize(Index newSize) { m_expression.resize(newSize); }
0104     /** Forwards the resizing request to the nested expression
0105       * \sa DenseBase::resize(Index,Index)*/
0106     EIGEN_DEVICE_FUNC
0107     void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
0108 
0109   protected:
0110     NestedExpressionType m_expression;
0111 };
0112 
0113 /** \class MatrixWrapper
0114   * \ingroup Core_Module
0115   *
0116   * \brief Expression of an array as a mathematical vector or matrix
0117   *
0118   * This class is the return type of ArrayBase::matrix(), and most of the time
0119   * this is the only way it is use.
0120   *
0121   * \sa MatrixBase::matrix(), class ArrayWrapper
0122   */
0123 
0124 namespace internal {
0125 template<typename ExpressionType>
0126 struct traits<MatrixWrapper<ExpressionType> >
0127  : public traits<typename remove_all<typename ExpressionType::Nested>::type >
0128 {
0129   typedef MatrixXpr XprKind;
0130   // Let's remove NestByRefBit
0131   enum {
0132     Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
0133     LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
0134     Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
0135   };
0136 };
0137 }
0138 
0139 template<typename ExpressionType>
0140 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
0141 {
0142   public:
0143     typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
0144     EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
0145     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
0146     typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
0147 
0148     typedef typename internal::conditional<
0149                        internal::is_lvalue<ExpressionType>::value,
0150                        Scalar,
0151                        const Scalar
0152                      >::type ScalarWithConstIfNotLvalue;
0153 
0154     typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
0155 
0156     using Base::coeffRef;
0157 
0158     EIGEN_DEVICE_FUNC
0159     explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
0160 
0161     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0162     inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
0163     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0164     inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
0165     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0166     inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
0167     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0168     inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
0169 
0170     EIGEN_DEVICE_FUNC
0171     inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
0172     EIGEN_DEVICE_FUNC
0173     inline const Scalar* data() const { return m_expression.data(); }
0174 
0175     EIGEN_DEVICE_FUNC
0176     inline const Scalar& coeffRef(Index rowId, Index colId) const
0177     {
0178       return m_expression.derived().coeffRef(rowId, colId);
0179     }
0180 
0181     EIGEN_DEVICE_FUNC
0182     inline const Scalar& coeffRef(Index index) const
0183     {
0184       return m_expression.coeffRef(index);
0185     }
0186 
0187     EIGEN_DEVICE_FUNC
0188     const typename internal::remove_all<NestedExpressionType>::type&
0189     nestedExpression() const
0190     {
0191       return m_expression;
0192     }
0193 
0194     /** Forwards the resizing request to the nested expression
0195       * \sa DenseBase::resize(Index)  */
0196     EIGEN_DEVICE_FUNC
0197     void resize(Index newSize) { m_expression.resize(newSize); }
0198     /** Forwards the resizing request to the nested expression
0199       * \sa DenseBase::resize(Index,Index)*/
0200     EIGEN_DEVICE_FUNC
0201     void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
0202 
0203   protected:
0204     NestedExpressionType m_expression;
0205 };
0206 
0207 } // end namespace Eigen
0208 
0209 #endif // EIGEN_ARRAYWRAPPER_H