TernaryFunctors.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) 2016 Eugene Brevdo <ebrevdo@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_TERNARY_FUNCTORS_H
11 #define EIGEN_TERNARY_FUNCTORS_H
12 
13 // IWYU pragma: private
14 #include "../InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 //---------- associative ternary functors ----------
21 
22 template <typename ThenScalar, typename ElseScalar, typename ConditionScalar>
25  EIGEN_STATIC_ASSERT(ThenElseAreSame, THEN AND ELSE MUST BE SAME TYPE)
26  using Scalar = ThenScalar;
28  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const ThenScalar& a, const ElseScalar& b,
29  const ConditionScalar& cond) const {
30  return cond == ConditionScalar(0) ? b : a;
31  }
32  template <typename Packet>
34  return pselect(pcmp_eq(cond, pzero(cond)), b, a);
35  }
36 };
37 
38 template <typename ThenScalar, typename ElseScalar, typename ConditionScalar>
39 struct functor_traits<scalar_boolean_select_op<ThenScalar, ElseScalar, ConditionScalar>> {
40  using Scalar = ThenScalar;
41  enum {
42  Cost = 1,
45  };
46 };
47 
48 } // end namespace internal
49 
50 } // end namespace Eigen
51 
52 #endif // EIGEN_TERNARY_FUNCTORS_H
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
#define TYPE
Definition: benchFFT.cpp:39
Scalar * b
Definition: benchVecAdd.cpp:17
const Scalar * a
Definition: level2_cplx_impl.h:32
EIGEN_STRONG_INLINE Packet8f pzero(const Packet8f &)
Definition: AVX/PacketMath.h:774
EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf &a, const Packet2cf &b)
Definition: AltiVec/Complex.h:353
EIGEN_STRONG_INLINE Packet4f pselect(const Packet4f &mask, const Packet4f &a, const Packet4f &b)
Definition: AltiVec/PacketMath.h:1474
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
Definition: Eigen_Colamd.h:49
#define AND(a, b)
Definition: oomph_metis_from_parmetis_3.1.1/macros.h:24
Definition: XprHelper.h:205
@ PacketAccess
Definition: XprHelper.h:206
@ Cost
Definition: XprHelper.h:206
Definition: Meta.h:205
Definition: GenericPacketMath.h:108
Definition: TernaryFunctors.h:23
ThenScalar Scalar
Definition: TernaryFunctors.h:26
static constexpr bool ThenElseAreSame
Definition: TernaryFunctors.h:24
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a, const Packet &b, const Packet &cond) const
Definition: TernaryFunctors.h:33
Scalar result_type
Definition: TernaryFunctors.h:27
Definition: ZVector/PacketMath.h:50