CwiseTernaryOp.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 // Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com>
7 //
8 // This Source Code Form is subject to the terms of the Mozilla
9 // Public License v. 2.0. If a copy of the MPL was not distributed
10 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 
12 #ifndef EIGEN_CWISE_TERNARY_OP_H
13 #define EIGEN_CWISE_TERNARY_OP_H
14 
15 // IWYU pragma: private
16 #include "./InternalHeaderCheck.h"
17 
18 namespace Eigen {
19 
20 namespace internal {
21 template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3>
22 struct traits<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3>> {
23  // we must not inherit from traits<Arg1> since it has
24  // the potential to cause problems with MSVC
27  enum {
31  MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
32  };
33 
34  // even though we require Arg1, Arg2, and Arg3 to have the same scalar type
35  // (see CwiseTernaryOp constructor),
36  // we still want to handle the case when the result type is different.
37  typedef typename result_of<TernaryOp(const typename Arg1::Scalar&, const typename Arg2::Scalar&,
38  const typename Arg3::Scalar&)>::type Scalar;
39 
42 
43  typedef typename Arg1::Nested Arg1Nested;
44  typedef typename Arg2::Nested Arg2Nested;
45  typedef typename Arg3::Nested Arg3Nested;
46  typedef std::remove_reference_t<Arg1Nested> Arg1Nested_;
47  typedef std::remove_reference_t<Arg2Nested> Arg2Nested_;
48  typedef std::remove_reference_t<Arg3Nested> Arg3Nested_;
49  enum { Flags = Arg1Nested_::Flags & RowMajorBit };
50 };
51 } // end namespace internal
52 
53 template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3, typename StorageKind>
54 class CwiseTernaryOpImpl;
55 
83 template <typename TernaryOp, typename Arg1Type, typename Arg2Type, typename Arg3Type>
84 class CwiseTernaryOp : public CwiseTernaryOpImpl<TernaryOp, Arg1Type, Arg2Type, Arg3Type,
85  typename internal::traits<Arg1Type>::StorageKind>,
87  public:
91 
92  // require the sizes to match
95 
96  // The index types should match
99  STORAGE_KIND_MUST_MATCH)
102  STORAGE_KIND_MUST_MATCH)
103 
104  typedef typename CwiseTernaryOpImpl<TernaryOp, Arg1Type, Arg2Type, Arg3Type,
107 
108  typedef typename internal::ref_selector<Arg1Type>::type Arg1Nested;
109  typedef typename internal::ref_selector<Arg2Type>::type Arg2Nested;
110  typedef typename internal::ref_selector<Arg3Type>::type Arg3Nested;
111  typedef std::remove_reference_t<Arg1Nested> Arg1Nested_;
112  typedef std::remove_reference_t<Arg2Nested> Arg2Nested_;
113  typedef std::remove_reference_t<Arg3Nested> Arg3Nested_;
114 
116  const TernaryOp& func = TernaryOp())
117  : m_arg1(a1), m_arg2(a2), m_arg3(a3), m_functor(func) {
118  eigen_assert(a1.rows() == a2.rows() && a1.cols() == a2.cols() && a1.rows() == a3.rows() && a1.cols() == a3.cols());
119  }
120 
122  // return the fixed size type if available to enable compile time
123  // optimizations
124  if (internal::traits<internal::remove_all_t<Arg1Nested>>::RowsAtCompileTime == Dynamic &&
126  return m_arg3.rows();
127  else if (internal::traits<internal::remove_all_t<Arg1Nested>>::RowsAtCompileTime == Dynamic &&
129  return m_arg2.rows();
130  else
131  return m_arg1.rows();
132  }
134  // return the fixed size type if available to enable compile time
135  // optimizations
136  if (internal::traits<internal::remove_all_t<Arg1Nested>>::ColsAtCompileTime == Dynamic &&
138  return m_arg3.cols();
139  else if (internal::traits<internal::remove_all_t<Arg1Nested>>::ColsAtCompileTime == Dynamic &&
141  return m_arg2.cols();
142  else
143  return m_arg1.cols();
144  }
145 
147  EIGEN_DEVICE_FUNC const Arg1Nested_& arg1() const { return m_arg1; }
149  EIGEN_DEVICE_FUNC const Arg2Nested_& arg2() const { return m_arg2; }
151  EIGEN_DEVICE_FUNC const Arg3Nested_& arg3() const { return m_arg3; }
153  EIGEN_DEVICE_FUNC const TernaryOp& functor() const { return m_functor; }
154 
155  protected:
159  const TernaryOp m_functor;
160 };
161 
162 // Generic API dispatcher
163 template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3, typename StorageKind>
164 class CwiseTernaryOpImpl : public internal::generic_xpr_base<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3>>::type {
165  public:
167 };
168 
169 } // end namespace Eigen
170 
171 #endif // EIGEN_CWISE_TERNARY_OP_H
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1149
#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(X, MSG)
Definition: StaticAssert.h:26
#define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0, TYPE1)
Definition: StaticAssert.h:79
SCALAR Scalar
Definition: bench_gemm.cpp:45
Definition: CwiseTernaryOp.h:164
internal::generic_xpr_base< CwiseTernaryOp< TernaryOp, Arg1Type, Arg2Type, Arg3Type > >::type Base
Definition: CwiseTernaryOp.h:166
Generic expression where a coefficient-wise ternary operator is applied to two expressions.
Definition: CwiseTernaryOp.h:86
internal::remove_all_t< Arg3Type > Arg3
Definition: CwiseTernaryOp.h:90
EIGEN_DEVICE_FUNC const Arg2Nested_ & arg2() const
Definition: CwiseTernaryOp.h:149
internal::remove_all_t< Arg2Type > Arg2
Definition: CwiseTernaryOp.h:89
EIGEN_DEVICE_FUNC const Arg3Nested_ & arg3() const
Definition: CwiseTernaryOp.h:151
internal::ref_selector< Arg3Type >::type Arg3Nested
Definition: CwiseTernaryOp.h:110
EIGEN_STATIC_ASSERT((internal::is_same< typename internal::traits< Arg1Type >::StorageKind, typename internal::traits< Arg2Type >::StorageKind >::value), STORAGE_KIND_MUST_MATCH) EIGEN_STATIC_ASSERT((internal typedef internal::ref_selector< Arg1Type >::type Arg1Nested
Definition: CwiseTernaryOp.h:97
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
Definition: CwiseTernaryOp.h:121
internal::remove_all_t< Arg1Type > Arg1
Definition: CwiseTernaryOp.h:88
Arg1Nested m_arg1
Definition: CwiseTernaryOp.h:156
Arg2Nested m_arg2
Definition: CwiseTernaryOp.h:157
std::remove_reference_t< Arg2Nested > Arg2Nested_
Definition: CwiseTernaryOp.h:112
std::remove_reference_t< Arg3Nested > Arg3Nested_
Definition: CwiseTernaryOp.h:113
std::remove_reference_t< Arg1Nested > Arg1Nested_
Definition: CwiseTernaryOp.h:111
Arg3Nested m_arg3
Definition: CwiseTernaryOp.h:158
internal::ref_selector< Arg2Type >::type Arg2Nested
Definition: CwiseTernaryOp.h:109
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
Definition: CwiseTernaryOp.h:133
const TernaryOp m_functor
Definition: CwiseTernaryOp.h:159
EIGEN_DEVICE_FUNC const TernaryOp & functor() const
Definition: CwiseTernaryOp.h:153
EIGEN_DEVICE_FUNC const Arg1Nested_ & arg1() const
Definition: CwiseTernaryOp.h:147
Definition: XprHelper.h:134
const unsigned int RowMajorBit
Definition: Constants.h:70
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
Definition: XprHelper.h:575
Definition: Meta.h:205
Definition: Meta.h:388
std::remove_reference_t< Arg1Nested > Arg1Nested_
Definition: CwiseTernaryOp.h:46
std::remove_reference_t< Arg3Nested > Arg3Nested_
Definition: CwiseTernaryOp.h:48
internal::traits< Arg1 >::StorageKind StorageKind
Definition: CwiseTernaryOp.h:40
remove_all_t< Arg1 > Ancestor
Definition: CwiseTernaryOp.h:25
internal::traits< Arg1 >::StorageIndex StorageIndex
Definition: CwiseTernaryOp.h:41
result_of< TernaryOp(const typename Arg1::Scalar &, const typename Arg2::Scalar &, const typename Arg3::Scalar &)>::type Scalar
Definition: CwiseTernaryOp.h:38
std::remove_reference_t< Arg2Nested > Arg2Nested_
Definition: CwiseTernaryOp.h:47
traits< Ancestor >::XprKind XprKind
Definition: CwiseTernaryOp.h:26
Definition: ForwardDeclarations.h:21
Definition: benchGeometry.cpp:21