File indexing completed on 2025-01-18 09:56:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
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
0021
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
0032
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 }
0053
0054 template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
0055 class CwiseBinaryOpImpl;
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
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
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
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
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
0127 return internal::traits<typename internal::remove_all<LhsNested>::type>::ColsAtCompileTime==Dynamic ? m_rhs.cols() : m_lhs.cols();
0128 }
0129
0130
0131 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0132 const _LhsNested& lhs() const { return m_lhs; }
0133
0134 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0135 const _RhsNested& rhs() const { return m_rhs; }
0136
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
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
0156
0157
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
0169
0170
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 }
0182
0183 #endif