Eigen  3.4.90 (git rev 9589cc4e7fd8e4538bedef80dd36c7738977a8be)
 
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Loading...
Searching...
No Matches
TernaryFunctors.h
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
16namespace Eigen {
17
18namespace internal {
19
20//---------- associative ternary functors ----------
21
22template <typename ThenScalar, typename ElseScalar, typename ConditionScalar>
23struct scalar_boolean_select_op {
24 static constexpr bool ThenElseAreSame = is_same<ThenScalar, ElseScalar>::value;
25 EIGEN_STATIC_ASSERT(ThenElseAreSame, THEN AND ELSE MUST BE SAME TYPE)
26 using Scalar = ThenScalar;
27 using result_type = Scalar;
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>
33 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b, const Packet& cond) const {
34 return pselect(pcmp_eq(cond, pzero(cond)), b, a);
35 }
36};
37
38template <typename ThenScalar, typename ElseScalar, typename ConditionScalar>
39struct functor_traits<scalar_boolean_select_op<ThenScalar, ElseScalar, ConditionScalar>> {
40 using Scalar = ThenScalar;
41 enum {
42 Cost = 1,
43 PacketAccess = is_same<ThenScalar, ElseScalar>::value && is_same<ConditionScalar, Scalar>::value &&
44 packet_traits<Scalar>::HasCmp
45 };
46};
47
48} // end namespace internal
49
50} // end namespace Eigen
51
52#endif // EIGEN_TERNARY_FUNCTORS_H
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1