Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
0006 //
0007 // This Source Code Form is subject to the terms of the Mozilla
0008 // Public License v. 2.0. If a copy of the MPL was not distributed
0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0010 
0011 #ifndef EIGEN_CWISE_BINARY_OP_H
0012 #define EIGEN_CWISE_BINARY_OP_H
0013 
0014 namespace Eigen {
0015 
0016 namespace internal {
0017 template<typename BinaryOp, typename Lhs, typename Rhs>
0018 struct traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
0019 {
0020   // we must not inherit from traits<Lhs> since it has
0021   // the potential to cause problems with MSVC
0022   typedef typename remove_all<Lhs>::type Ancestor;
0023   typedef typename traits<Ancestor>::XprKind XprKind;
0024   enum {
0025     RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
0026     ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
0027     MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
0028     MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
0029   };
0030 
0031   // even though we require Lhs and Rhs to have the same scalar type (see CwiseBinaryOp constructor),
0032   // we still want to handle the case when the result type is different.
0033   typedef typename result_of<
0034                      BinaryOp(
0035                        const typename Lhs::Scalar&,
0036                        const typename Rhs::Scalar&
0037                      )
0038                    >::type Scalar;
0039   typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind,
0040                                               typename traits<Rhs>::StorageKind,
0041                                               BinaryOp>::ret StorageKind;
0042   typedef typename promote_index_type<typename traits<Lhs>::StorageIndex,
0043                                       typename traits<Rhs>::StorageIndex>::type StorageIndex;
0044   typedef typename Lhs::Nested LhsNested;
0045   typedef typename Rhs::Nested RhsNested;
0046   typedef typename remove_reference<LhsNested>::type _LhsNested;
0047   typedef typename remove_reference<RhsNested>::type _RhsNested;
0048   enum {
0049     Flags = cwise_promote_storage_order<typename traits<Lhs>::StorageKind,typename traits<Rhs>::StorageKind,_LhsNested::Flags & RowMajorBit,_RhsNested::Flags & RowMajorBit>::value
0050   };
0051 };
0052 } // end namespace internal
0053 
0054 template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
0055 class CwiseBinaryOpImpl;
0056 
0057 /** \class CwiseBinaryOp
0058   * \ingroup Core_Module
0059   *
0060   * \brief Generic expression where a coefficient-wise binary operator is applied to two expressions
0061   *
0062   * \tparam BinaryOp template functor implementing the operator
0063   * \tparam LhsType the type of the left-hand side
0064   * \tparam RhsType the type of the right-hand side
0065   *
0066   * This class represents an expression  where a coefficient-wise binary operator is applied to two expressions.
0067   * It is the return type of binary operators, by which we mean only those binary operators where
0068   * both the left-hand side and the right-hand side are Eigen expressions.
0069   * For example, the return type of matrix1+matrix2 is a CwiseBinaryOp.
0070   *
0071   * Most of the time, this is the only way that it is used, so you typically don't have to name
0072   * CwiseBinaryOp types explicitly.
0073   *
0074   * \sa MatrixBase::binaryExpr(const MatrixBase<OtherDerived> &,const CustomBinaryOp &) const, class CwiseUnaryOp, class CwiseNullaryOp
0075   */
0076 template<typename BinaryOp, typename LhsType, typename RhsType>
0077 class CwiseBinaryOp :
0078   public CwiseBinaryOpImpl<
0079           BinaryOp, LhsType, RhsType,
0080           typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
0081                                                         typename internal::traits<RhsType>::StorageKind,
0082                                                         BinaryOp>::ret>,
0083   internal::no_assignment_operator
0084 {
0085   public:
0086 
0087     typedef typename internal::remove_all<BinaryOp>::type Functor;
0088     typedef typename internal::remove_all<LhsType>::type Lhs;
0089     typedef typename internal::remove_all<RhsType>::type Rhs;
0090 
0091     typedef typename CwiseBinaryOpImpl<
0092         BinaryOp, LhsType, RhsType,
0093         typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
0094                                                       typename internal::traits<Rhs>::StorageKind,
0095                                                       BinaryOp>::ret>::Base Base;
0096     EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp)
0097 
0098     typedef typename internal::ref_selector<LhsType>::type LhsNested;
0099     typedef typename internal::ref_selector<RhsType>::type RhsNested;
0100     typedef typename internal::remove_reference<LhsNested>::type _LhsNested;
0101     typedef typename internal::remove_reference<RhsNested>::type _RhsNested;
0102 
0103 #if EIGEN_COMP_MSVC && EIGEN_HAS_CXX11
0104     //Required for Visual Studio or the Copy constructor will probably not get inlined!
0105     EIGEN_STRONG_INLINE
0106     CwiseBinaryOp(const CwiseBinaryOp<BinaryOp,LhsType,RhsType>&) = default;
0107 #endif
0108 
0109     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0110     CwiseBinaryOp(const Lhs& aLhs, const Rhs& aRhs, const BinaryOp& func = BinaryOp())
0111       : m_lhs(aLhs), m_rhs(aRhs), m_functor(func)
0112     {
0113       EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename Rhs::Scalar);
0114       // require the sizes to match
0115       EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs)
0116       eigen_assert(aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols());
0117     }
0118 
0119     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
0120     Index rows() const EIGEN_NOEXCEPT {
0121       // return the fixed size type if available to enable compile time optimizations
0122       return internal::traits<typename internal::remove_all<LhsNested>::type>::RowsAtCompileTime==Dynamic ? m_rhs.rows() : m_lhs.rows();
0123     }
0124     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
0125     Index cols() const EIGEN_NOEXCEPT {
0126       // return the fixed size type if available to enable compile time optimizations
0127       return internal::traits<typename internal::remove_all<LhsNested>::type>::ColsAtCompileTime==Dynamic ? m_rhs.cols() : m_lhs.cols();
0128     }
0129 
0130     /** \returns the left hand side nested expression */
0131     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0132     const _LhsNested& lhs() const { return m_lhs; }
0133     /** \returns the right hand side nested expression */
0134     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0135     const _RhsNested& rhs() const { return m_rhs; }
0136     /** \returns the functor representing the binary operation */
0137     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0138     const BinaryOp& functor() const { return m_functor; }
0139 
0140   protected:
0141     LhsNested m_lhs;
0142     RhsNested m_rhs;
0143     const BinaryOp m_functor;
0144 };
0145 
0146 // Generic API dispatcher
0147 template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
0148 class CwiseBinaryOpImpl
0149   : public internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type
0150 {
0151 public:
0152   typedef typename internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type Base;
0153 };
0154 
0155 /** replaces \c *this by \c *this - \a other.
0156   *
0157   * \returns a reference to \c *this
0158   */
0159 template<typename Derived>
0160 template<typename OtherDerived>
0161 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
0162 MatrixBase<Derived>::operator-=(const MatrixBase<OtherDerived> &other)
0163 {
0164   call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
0165   return derived();
0166 }
0167 
0168 /** replaces \c *this by \c *this + \a other.
0169   *
0170   * \returns a reference to \c *this
0171   */
0172 template<typename Derived>
0173 template<typename OtherDerived>
0174 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
0175 MatrixBase<Derived>::operator+=(const MatrixBase<OtherDerived>& other)
0176 {
0177   call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
0178   return derived();
0179 }
0180 
0181 } // end namespace Eigen
0182 
0183 #endif // EIGEN_CWISE_BINARY_OP_H