compbio
CwiseTernaryOp.h
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;
23  typedef typename traits<Ancestor>::XprKind XprKind;
24  enum {
25  RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
26  ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
27  MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
28  MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
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 
38  typedef typename internal::traits<Arg1>::StorageKind StorageKind;
39  typedef typename internal::traits<Arg1>::StorageIndex StorageIndex;
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:
90  typedef typename internal::remove_all<Arg1Type>::type Arg1;
91  typedef typename internal::remove_all<Arg2Type>::type Arg2;
92  typedef typename internal::remove_all<Arg3Type>::type Arg3;
93 
94  typedef typename CwiseTernaryOpImpl<
95  TernaryOp, Arg1Type, Arg2Type, Arg3Type,
96  typename internal::traits<Arg1Type>::StorageKind>::Base Base;
97  EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseTernaryOp)
98 
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
112  EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg2)
113  EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg3)
114 
115  // The index types should match
116  EIGEN_STATIC_ASSERT((internal::is_same<
118  typename internal::traits<Arg2Type>::StorageKind>::value),
119  STORAGE_KIND_MUST_MATCH)
120  EIGEN_STATIC_ASSERT((internal::is_same<
122  typename internal::traits<Arg3Type>::StorageKind>::value),
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
130  EIGEN_STRONG_INLINE Index rows() const {
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
147  EIGEN_STRONG_INLINE Index cols() const {
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:
178  Arg1Nested m_arg1;
179  Arg2Nested m_arg2;
180  Arg3Nested m_arg3;
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
Definition: CwiseTernaryOp.h:53
EIGEN_DEVICE_FUNC const TernaryOp & functor() const
Definition: CwiseTernaryOp.h:175
Definition: Meta.h:63
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:61
Definition: XprHelper.h:89
Definition: Meta.h:294
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Generic expression where a coefficient-wise ternary operator is applied to two expressions.
Definition: CwiseTernaryOp.h:84
EIGEN_DEVICE_FUNC const _Arg1Nested & arg1() const
Definition: CwiseTernaryOp.h:166
EIGEN_DEVICE_FUNC const _Arg3Nested & arg3() const
Definition: CwiseTernaryOp.h:172
Definition: benchGeometry.cpp:23
Definition: BandTriangularSolver.h:13
Definition: XprHelper.h:481
EIGEN_DEVICE_FUNC const _Arg2Nested & arg2() const
Definition: CwiseTernaryOp.h:169
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
Definition: ForwardDeclarations.h:17