CwiseBinaryOp.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_CWISE_BINARY_OP_H
12 #define EIGEN_CWISE_BINARY_OP_H
13 
14 // IWYU pragma: private
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 
19 namespace internal {
20 template <typename BinaryOp, typename Lhs, typename Rhs>
21 struct traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs>> {
22  // we must not inherit from traits<Lhs> since it has
23  // the potential to cause problems with MSVC
26  enum {
30  MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
31  };
32 
33  // even though we require Lhs and Rhs to have the same scalar type (see CwiseBinaryOp constructor),
34  // we still want to handle the case when the result type is different.
35  typedef typename result_of<BinaryOp(const typename Lhs::Scalar&, const typename Rhs::Scalar&)>::type Scalar;
37  BinaryOp>::ret StorageKind;
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_;
44  enum {
46  LhsNested_::Flags & RowMajorBit, RhsNested_::Flags & RowMajorBit>::value
47  };
48 };
49 } // end namespace internal
50 
51 template <typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
52 class CwiseBinaryOpImpl;
53 
74 template <typename BinaryOp, typename LhsType, typename RhsType>
75 class 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>,
80  public:
84 
85  typedef typename CwiseBinaryOpImpl<
86  BinaryOp, LhsType, RhsType,
91 
92  EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp, typename Lhs::Scalar, typename Rhs::Scalar)
94 
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_;
99 
100 #if EIGEN_COMP_MSVC
101  // Required for Visual Studio or the Copy constructor will probably not get inlined!
103 #endif
104 
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());
109  }
110 
112  // return the fixed size type if available to enable compile time optimizations
113  return internal::traits<internal::remove_all_t<LhsNested>>::RowsAtCompileTime == Dynamic ? m_rhs.rows()
114  : m_lhs.rows();
115  }
117  // return the fixed size type if available to enable compile time optimizations
118  return internal::traits<internal::remove_all_t<LhsNested>>::ColsAtCompileTime == Dynamic ? m_rhs.cols()
119  : m_lhs.cols();
120  }
121 
127  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const BinaryOp& functor() const { return m_functor; }
128 
129  protected:
132  const BinaryOp m_functor;
133 };
134 
135 // Generic API dispatcher
136 template <typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
137 class CwiseBinaryOpImpl : public internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs>>::type {
138  public:
140 };
141 
146 template <typename Derived>
147 template <typename OtherDerived>
150  return derived();
151 }
152 
157 template <typename Derived>
158 template <typename OtherDerived>
161  return derived();
162 }
163 
164 } // end namespace Eigen
165 
166 #endif // EIGEN_CWISE_BINARY_OP_H
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1149
#define EIGEN_NOEXCEPT
Definition: Macros.h:1267
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define eigen_assert(x)
Definition: Macros.h:910
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
#define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0, TYPE1)
Definition: StaticAssert.h:79
#define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP, LHS, RHS)
Definition: XprHelper.h:1082
SCALAR Scalar
Definition: bench_gemm.cpp:45
Definition: CwiseBinaryOp.h:137
internal::generic_xpr_base< CwiseBinaryOp< BinaryOp, Lhs, Rhs > >::type Base
Definition: CwiseBinaryOp.h:139
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:79
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: CwiseBinaryOp.h:116
const BinaryOp m_functor
Definition: CwiseBinaryOp.h:132
LhsNested m_lhs
Definition: CwiseBinaryOp.h:130
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CwiseBinaryOp(const Lhs &aLhs, const Rhs &aRhs, const BinaryOp &func=BinaryOp())
Definition: CwiseBinaryOp.h:105
std::remove_reference_t< LhsNested > LhsNested_
Definition: CwiseBinaryOp.h:97
RhsNested m_rhs
Definition: CwiseBinaryOp.h:131
std::remove_reference_t< RhsNested > RhsNested_
Definition: CwiseBinaryOp.h:98
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: CwiseBinaryOp.h:111
internal::ref_selector< LhsType >::type LhsNested
Definition: CwiseBinaryOp.h:95
internal::remove_all_t< LhsType > Lhs
Definition: CwiseBinaryOp.h:82
internal::ref_selector< RhsType >::type RhsNested
Definition: CwiseBinaryOp.h:96
internal::remove_all_t< RhsType > Rhs
Definition: CwiseBinaryOp.h:83
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const BinaryOp & functor() const
Definition: CwiseBinaryOp.h:127
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const RhsNested_ & rhs() const
Definition: CwiseBinaryOp.h:125
CwiseBinaryOpImpl< BinaryOp, LhsType, RhsType, typename internal::cwise_promote_storage_type< typename internal::traits< LhsType >::StorageKind, typename internal::traits< Rhs >::StorageKind, BinaryOp >::ret >::Base Base
Definition: CwiseBinaryOp.h:89
internal::remove_all_t< BinaryOp > Functor
Definition: CwiseBinaryOp.h:81
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const LhsNested_ & lhs() const
Definition: CwiseBinaryOp.h:123
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator-=(const MatrixBase< OtherDerived > &other)
Definition: CwiseBinaryOp.h:148
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator+=(const MatrixBase< OtherDerived > &other)
Definition: CwiseBinaryOp.h:159
Definition: XprHelper.h:134
const unsigned int RowMajorBit
Definition: Constants.h:70
Eigen::DenseIndex ret
Definition: level1_cplx_impl.h:43
@ Lhs
Definition: TensorContractionMapper.h:20
@ Rhs
Definition: TensorContractionMapper.h:20
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(Dst &dst, const Src &src)
Definition: AssignEvaluator.h:781
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
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
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
Template functor for scalar/packet assignment with addition.
Definition: AssignmentFunctors.h:52
Definition: XprHelper.h:575
Definition: XprHelper.h:145
Definition: Meta.h:388
Template functor for scalar/packet assignment with subtraction.
Definition: AssignmentFunctors.h:73
std::remove_reference_t< RhsNested > RhsNested_
Definition: CwiseBinaryOp.h:43
cwise_promote_storage_type< typename traits< Lhs >::StorageKind, typename traits< Rhs >::StorageKind, BinaryOp >::ret StorageKind
Definition: CwiseBinaryOp.h:37
Rhs::Nested RhsNested
Definition: CwiseBinaryOp.h:41
result_of< BinaryOp(const typename Lhs::Scalar &, const typename Rhs::Scalar &)>::type Scalar
Definition: CwiseBinaryOp.h:35
Lhs::Nested LhsNested
Definition: CwiseBinaryOp.h:40
traits< Ancestor >::XprKind XprKind
Definition: CwiseBinaryOp.h:25
promote_index_type< typename traits< Lhs >::StorageIndex, typename traits< Rhs >::StorageIndex >::type StorageIndex
Definition: CwiseBinaryOp.h:39
remove_all_t< Lhs > Ancestor
Definition: CwiseBinaryOp.h:24
std::remove_reference_t< LhsNested > LhsNested_
Definition: CwiseBinaryOp.h:42
Definition: ForwardDeclarations.h:21
Definition: benchGeometry.cpp:21