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 namespace Eigen {
16 
17 namespace internal {
18 template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3>
19 struct traits<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > {
20  // we must not inherit from traits<Arg1> since it has
21  // the potential to cause problems with MSVC
22  typedef typename remove_all<Arg1>::type Ancestor;
24  enum {
29  };
30 
31  // even though we require Arg1, Arg2, and Arg3 to have the same scalar type
32  // (see CwiseTernaryOp constructor),
33  // we still want to handle the case when the result type is different.
34  typedef typename result_of<TernaryOp(
35  const typename Arg1::Scalar&, const typename Arg2::Scalar&,
36  const typename Arg3::Scalar&)>::type Scalar;
37 
40 
41  typedef typename Arg1::Nested Arg1Nested;
42  typedef typename Arg2::Nested Arg2Nested;
43  typedef typename Arg3::Nested Arg3Nested;
47  enum { Flags = _Arg1Nested::Flags & RowMajorBit };
48 };
49 } // end namespace internal
50 
51 template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3,
52  typename StorageKind>
54 
82 template <typename TernaryOp, typename Arg1Type, typename Arg2Type,
83  typename Arg3Type>
85  TernaryOp, Arg1Type, Arg2Type, Arg3Type,
86  typename internal::traits<Arg1Type>::StorageKind>,
88 {
89  public:
93 
94  typedef typename CwiseTernaryOpImpl<
95  TernaryOp, Arg1Type, Arg2Type, Arg3Type,
98 
99  typedef typename internal::ref_selector<Arg1Type>::type Arg1Nested;
100  typedef typename internal::ref_selector<Arg2Type>::type Arg2Nested;
101  typedef typename internal::ref_selector<Arg3Type>::type Arg3Nested;
102  typedef typename internal::remove_reference<Arg1Nested>::type _Arg1Nested;
103  typedef typename internal::remove_reference<Arg2Nested>::type _Arg2Nested;
104  typedef typename internal::remove_reference<Arg3Nested>::type _Arg3Nested;
105 
106  EIGEN_DEVICE_FUNC
107  EIGEN_STRONG_INLINE CwiseTernaryOp(const Arg1& a1, const Arg2& a2,
108  const Arg3& a3,
109  const TernaryOp& func = TernaryOp())
110  : m_arg1(a1), m_arg2(a2), m_arg3(a3), m_functor(func) {
111  // require the sizes to match
114 
115  // The index types should match
119  STORAGE_KIND_MUST_MATCH)
123  STORAGE_KIND_MUST_MATCH)
124 
125  eigen_assert(a1.rows() == a2.rows() && a1.cols() == a2.cols() &&
126  a1.rows() == a3.rows() && a1.cols() == a3.cols());
127  }
128 
129  EIGEN_DEVICE_FUNC
131  // return the fixed size type if available to enable compile time
132  // optimizations
134  RowsAtCompileTime == Dynamic &&
136  RowsAtCompileTime == Dynamic)
137  return m_arg3.rows();
139  RowsAtCompileTime == Dynamic &&
141  RowsAtCompileTime == Dynamic)
142  return m_arg2.rows();
143  else
144  return m_arg1.rows();
145  }
146  EIGEN_DEVICE_FUNC
148  // return the fixed size type if available to enable compile time
149  // optimizations
151  ColsAtCompileTime == Dynamic &&
153  ColsAtCompileTime == Dynamic)
154  return m_arg3.cols();
156  ColsAtCompileTime == Dynamic &&
158  ColsAtCompileTime == Dynamic)
159  return m_arg2.cols();
160  else
161  return m_arg1.cols();
162  }
163 
165  EIGEN_DEVICE_FUNC
166  const _Arg1Nested& arg1() const { return m_arg1; }
168  EIGEN_DEVICE_FUNC
169  const _Arg2Nested& arg2() const { return m_arg2; }
171  EIGEN_DEVICE_FUNC
172  const _Arg3Nested& arg3() const { return m_arg3; }
174  EIGEN_DEVICE_FUNC
175  const TernaryOp& functor() const { return m_functor; }
176 
177  protected:
181  const TernaryOp m_functor;
182 };
183 
184 // Generic API dispatcher
185 template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3,
186  typename StorageKind>
187 class CwiseTernaryOpImpl
189  CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >::type {
190  public:
191  typedef typename internal::generic_xpr_base<
193 };
194 
195 } // end namespace Eigen
196 
197 #endif // EIGEN_CWISE_TERNARY_OP_H
result_of< TernaryOp(const typename Arg1::Scalar &, const typename Arg2::Scalar &, const typename Arg3::Scalar &)>::type Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:33
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:852
#define EIGEN_STRONG_INLINE
Definition: Macros.h:494
EIGEN_DEVICE_FUNC const _Arg1Nested & arg1() const
internal::remove_all< Arg1Type >::type Arg1
EIGEN_DEVICE_FUNC const _Arg2Nested & arg2() const
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:124
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
const unsigned int RowMajorBit
Definition: Constants.h:61
const TernaryOp m_functor
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
#define eigen_assert(x)
Definition: Macros.h:579
Generic expression where a coefficient-wise ternary operator is applied to two expressions.
internal::remove_all< Arg2Type >::type Arg2
internal::remove_all< Arg3Type >::type Arg3
internal::generic_xpr_base< CwiseTernaryOp< TernaryOp, Arg1, Arg2, Arg3 > >::type Base
EIGEN_DEVICE_FUNC const TernaryOp & functor() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
const int Dynamic
Definition: Constants.h:21
EIGEN_DEVICE_FUNC const _Arg3Nested & arg3() const
Definition: pytypes.h:897
CwiseTernaryOpImpl< TernaryOp, Arg1Type, Arg2Type, Arg3Type, typename internal::traits< Arg1Type >::StorageKind >::Base Base
#define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0, TYPE1)
Definition: StaticAssert.h:189


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:54