Eigen  5.0.1
 
Loading...
Searching...
No Matches
UnaryFunctors.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// This Source Code Form is subject to the terms of the Mozilla
5// Public License v. 2.0. If a copy of the MPL was not distributed
6// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
7// SPDX-FileCopyrightText: The Eigen Authors
8// SPDX-License-Identifier: MPL-2.0
9
10#ifndef EIGEN_NEON_UNARY_FUNCTORS_H
11#define EIGEN_NEON_UNARY_FUNCTORS_H
12
13// IWYU pragma: private
14#include "../../InternalHeaderCheck.h"
15
16namespace Eigen {
17
18namespace internal {
19
20#if EIGEN_ARCH_ARM64 && EIGEN_HAS_ARM64_FP16
24template <>
25struct scalar_logistic_op<Eigen::half> {
26 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half operator()(const Eigen::half& x) const {
27 // Convert to float and call scalar_logistic_op<float>.
28 const scalar_logistic_op<float> float_op;
29 return Eigen::half(float_op(float(x)));
30 }
31
32 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half packetOp(const Eigen::half& x) const { return this->operator()(x); }
33
34 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf packetOp(const Packet4hf& x) const {
35 const scalar_logistic_op<float> float_op;
36 return vcvt_f16_f32(float_op.packetOp(vcvt_f32_f16(x)));
37 }
38
39 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8hf packetOp(const Packet8hf& x) const {
40 const scalar_logistic_op<float> float_op;
41 return vcombine_f16(vcvt_f16_f32(float_op.packetOp(vcvt_f32_f16(vget_low_f16(x)))),
42 vcvt_f16_f32(float_op.packetOp(vcvt_f32_f16(vget_high_f16(x)))));
43 }
44};
45
46template <>
47struct functor_traits<scalar_logistic_op<Eigen::half>> {
48 enum {
49 Cost = functor_traits<scalar_logistic_op<float>>::Cost,
50 PacketAccess = functor_traits<scalar_logistic_op<float>>::PacketAccess,
51 };
52};
53#endif // EIGEN_ARCH_ARM64 && EIGEN_HAS_ARM64_FP16
54
55} // end namespace internal
56
57} // end namespace Eigen
58
59#endif // EIGEN_NEON_UNARY_FUNCTORS_H