// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2016 Eugene Brevdo // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifndef EIGEN_TERNARY_FUNCTORS_H #define EIGEN_TERNARY_FUNCTORS_H // IWYU pragma: private #include "../InternalHeaderCheck.h" namespace Eigen { namespace internal { //---------- associative ternary functors ---------- template struct scalar_boolean_select_op { static constexpr bool ThenElseAreSame = is_same::value; EIGEN_STATIC_ASSERT(ThenElseAreSame, THEN AND ELSE MUST BE SAME TYPE) using Scalar = ThenScalar; using result_type = Scalar; EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const ThenScalar& a, const ElseScalar& b, const ConditionScalar& cond) const { return cond == ConditionScalar(0) ? b : a; } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b, const Packet& cond) const { return pselect(pcmp_eq(cond, pzero(cond)), b, a); } }; template struct functor_traits> { using Scalar = ThenScalar; enum { Cost = 1, PacketAccess = is_same::value && is_same::value && packet_traits::HasCmp }; }; } // end namespace internal } // end namespace Eigen #endif // EIGEN_TERNARY_FUNCTORS_H