Eigen  5.0.1-dev+7c7d8473
 
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 =
25 is_same<std::remove_const_t<ThenScalar>, std::remove_const_t<ElseScalar>>::value;
26 EIGEN_STATIC_ASSERT(ThenElseAreSame, THEN AND ELSE MUST BE SAME TYPE)
27 using Scalar = ThenScalar;
28 using result_type = Scalar;
29 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const ThenScalar& a, const ElseScalar& b,
30 const ConditionScalar& cond) const {
31 return cond == ConditionScalar(0) ? b : a;
32 }
33 template <typename Packet>
34 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b, const Packet& cond) const {
35 return pselect(pcmp_eq(cond, pzero(cond)), b, a);
36 }
37};
38
39template <typename ThenScalar, typename ElseScalar, typename ConditionScalar>
40struct functor_traits<scalar_boolean_select_op<ThenScalar, ElseScalar, ConditionScalar>> {
41 using Scalar = ThenScalar;
42 enum {
43 Cost = 1,
44 PacketAccess = is_same<ThenScalar, ElseScalar>::value && is_same<ConditionScalar, Scalar>::value &&
45 packet_traits<Scalar>::HasCmp
46 };
47};
48
49} // end namespace internal
50
51} // end namespace Eigen
52
53#endif // EIGEN_TERNARY_FUNCTORS_H
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1