11#ifndef EIGEN_CWISE_BINARY_OP_H
12#define EIGEN_CWISE_BINARY_OP_H
15#include "./InternalHeaderCheck.h"
20template <
typename BinaryOp,
typename Lhs,
typename Rhs>
21struct traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs>> {
24 typedef remove_all_t<Lhs> Ancestor;
25 typedef typename traits<Ancestor>::XprKind XprKind;
27 RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
28 ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
29 MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
30 MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
35 typedef typename result_of<BinaryOp(
const typename Lhs::Scalar&,
const typename Rhs::Scalar&)>::type Scalar;
36 typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind,
typename traits<Rhs>::StorageKind,
37 BinaryOp>::ret StorageKind;
38 typedef typename promote_index_type<typename traits<Lhs>::StorageIndex,
typename traits<Rhs>::StorageIndex>::type
40 typedef typename Lhs::Nested LhsNested;
41 typedef typename Rhs::Nested RhsNested;
42 typedef std::remove_reference_t<LhsNested> LhsNested_;
43 typedef std::remove_reference_t<RhsNested> RhsNested_;
45 Flags = cwise_promote_storage_order<typename traits<Lhs>::StorageKind,
typename traits<Rhs>::StorageKind,
51template <
typename BinaryOp,
typename Lhs,
typename Rhs,
typename StorageKind>
52class CwiseBinaryOpImpl;
74template <
typename BinaryOp,
typename LhsType,
typename RhsType>
75class CwiseBinaryOp :
public CwiseBinaryOpImpl<BinaryOp, LhsType, RhsType,
76 typename internal::cwise_promote_storage_type<
77 typename internal::traits<LhsType>::StorageKind,
78 typename internal::traits<RhsType>::StorageKind, BinaryOp>::ret>,
79 internal::no_assignment_operator {
81 typedef internal::remove_all_t<BinaryOp> Functor;
82 typedef internal::remove_all_t<LhsType> Lhs;
83 typedef internal::remove_all_t<RhsType> Rhs;
85 typedef typename CwiseBinaryOpImpl<
86 BinaryOp, LhsType, RhsType,
87 typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
88 typename internal::traits<Rhs>::StorageKind, BinaryOp>::ret>::Base
92 EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,
typename Lhs::Scalar,
typename Rhs::Scalar)
93 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs)
95 typedef typename internal::ref_selector<LhsType>::type LhsNested;
96 typedef typename internal::ref_selector<RhsType>::type RhsNested;
97 typedef std::remove_reference_t<LhsNested> LhsNested_;
98 typedef std::remove_reference_t<RhsNested> RhsNested_;
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
CwiseBinaryOp(
const Lhs& aLhs,
const Rhs& aRhs,
106 const BinaryOp& func = BinaryOp())
107 : m_lhs(aLhs), m_rhs(aRhs), m_functor(func) {
108 eigen_assert(aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols());
111 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
Index rows()
const EIGEN_NOEXCEPT {
113 return internal::traits<internal::remove_all_t<LhsNested>>::RowsAtCompileTime ==
Dynamic ? m_rhs.rows()
116 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
Index cols()
const EIGEN_NOEXCEPT {
118 return internal::traits<internal::remove_all_t<LhsNested>>::ColsAtCompileTime ==
Dynamic ? m_rhs.cols()
123 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const LhsNested_&
lhs()
const {
return m_lhs; }
125 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const RhsNested_&
rhs()
const {
return m_rhs; }
127 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const BinaryOp&
functor()
const {
return m_functor; }
132 const BinaryOp m_functor;
136template <
typename BinaryOp,
typename Lhs,
typename Rhs,
typename StorageKind>
137class CwiseBinaryOpImpl :
public internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs>>::type {
139 typedef typename internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs>>::type Base;
146template <
typename Derived>
147template <
typename OtherDerived>
149 call_assignment(derived(), other.
derived(), internal::sub_assign_op<Scalar, typename OtherDerived::Scalar>());
157template <
typename Derived>
158template <
typename OtherDerived>
160 call_assignment(derived(), other.
derived(), internal::add_assign_op<Scalar, typename OtherDerived::Scalar>());
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:79
const RhsNested_ & rhs() const
Definition CwiseBinaryOp.h:125
const LhsNested_ & lhs() const
Definition CwiseBinaryOp.h:123
const BinaryOp & functor() const
Definition CwiseBinaryOp.h:127
Derived & derived()
Definition EigenBase.h:49
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83
const int Dynamic
Definition Constants.h:25