12#ifndef EIGEN_CWISE_BINARY_OP_H
13#define EIGEN_CWISE_BINARY_OP_H
16#include "./InternalHeaderCheck.h"
21template <
typename BinaryOp>
22struct binary_op_compatibility {
23 using type = BinaryOp;
27template <
typename LhsScalar,
typename RhsScalar>
28struct binary_op_compatibility<fast_mult_op<LhsScalar, RhsScalar>> {
29 using type = scalar_product_op<LhsScalar, RhsScalar>;
32template <
typename BinaryOp,
typename Lhs,
typename Rhs>
33struct traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs>> {
36 using Ancestor = remove_all_t<Lhs>;
37 using XprKind =
typename traits<Ancestor>::XprKind;
39 RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
40 ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
41 MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
42 MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
47 using Scalar =
typename result_of<BinaryOp(
const typename Lhs::Scalar&,
const typename Rhs::Scalar&)>::type;
48 using StorageKind =
typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind,
49 typename traits<Rhs>::StorageKind, BinaryOp>::ret;
51 typename promote_index_type<typename traits<Lhs>::StorageIndex,
typename traits<Rhs>::StorageIndex>::type;
52 using LhsNested =
typename Lhs::Nested;
53 using RhsNested =
typename Rhs::Nested;
54 using LhsNested_ = std::remove_reference_t<LhsNested>;
55 using RhsNested_ = std::remove_reference_t<RhsNested>;
57 Flags = cwise_promote_storage_order<typename traits<Lhs>::StorageKind,
typename traits<Rhs>::StorageKind,
63template <
typename BinaryOp,
typename Lhs,
typename Rhs,
typename StorageKind>
64class CwiseBinaryOpImpl;
86template <
typename BinaryOp,
typename LhsType,
typename RhsType>
87class CwiseBinaryOp :
public CwiseBinaryOpImpl<BinaryOp, LhsType, RhsType,
88 typename internal::cwise_promote_storage_type<
89 typename internal::traits<LhsType>::StorageKind,
90 typename internal::traits<RhsType>::StorageKind, BinaryOp>::ret>,
91 internal::no_assignment_operator {
93 using Functor = internal::remove_all_t<BinaryOp>;
94 using Lhs = internal::remove_all_t<LhsType>;
95 using Rhs = internal::remove_all_t<RhsType>;
97 using Base =
typename CwiseBinaryOpImpl<
98 BinaryOp, LhsType, RhsType,
99 typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
100 typename internal::traits<Rhs>::StorageKind, BinaryOp>::ret>::Base;
101 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp)
103 EIGEN_CHECK_BINARY_COMPATIBILITY(
typename internal::binary_op_compatibility<BinaryOp>::type,
typename Lhs::Scalar,
104 typename Rhs::Scalar)
105 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs)
107 using LhsNested =
typename internal::ref_selector<LhsType>::type;
108 using RhsNested =
typename internal::ref_selector<RhsType>::type;
109 using LhsNested_ = std::remove_reference_t<LhsNested>;
110 using RhsNested_ = std::remove_reference_t<RhsNested>;
112 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE CwiseBinaryOp(
const Lhs& aLhs,
const Rhs& aRhs,
113 const BinaryOp& func = BinaryOp())
114 : m_lhs(aLhs), m_rhs(aRhs), m_functor(func) {
115 EIGEN_INTERNAL_ASSERT_SAME_SHAPE(aLhs, aRhs);
118 EIGEN_DEVICE_FUNC
constexpr Index rows()
const noexcept {
120 return internal::traits<internal::remove_all_t<LhsNested>>::RowsAtCompileTime == Dynamic ? m_rhs.rows()
123 EIGEN_DEVICE_FUNC
constexpr Index cols()
const noexcept {
125 return internal::traits<internal::remove_all_t<LhsNested>>::ColsAtCompileTime == Dynamic ? m_rhs.cols()
130 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
const LhsNested_&
lhs()
const {
return m_lhs; }
132 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
const RhsNested_&
rhs()
const {
return m_rhs; }
134 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
const BinaryOp&
functor()
const {
return m_functor; }
139 const BinaryOp m_functor;
143template <
typename BinaryOp,
typename Lhs,
typename Rhs,
typename StorageKind>
144class CwiseBinaryOpImpl :
public internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs>>::type {
146 using Base =
typename internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs>>::type;
153template <
typename Derived>
154template <
typename OtherDerived>
155EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Derived& MatrixBase<Derived>::operator-=(
const MatrixBase<OtherDerived>& other) {
156 call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar, typename OtherDerived::Scalar>());
164template <
typename Derived>
165template <
typename OtherDerived>
166EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Derived& MatrixBase<Derived>::operator+=(
const MatrixBase<OtherDerived>& other) {
167 call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar, typename OtherDerived::Scalar>());
constexpr const LhsNested_ & lhs() const
Definition CwiseBinaryOp.h:130
constexpr const BinaryOp & functor() const
Definition CwiseBinaryOp.h:134
constexpr const RhsNested_ & rhs() const
Definition CwiseBinaryOp.h:132
constexpr unsigned int RowMajorBit
Definition Constants.h:71