Eigen  5.0.1
 
Loading...
Searching...
No Matches
GenericPacketMathFunctionsFwd.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2019 Gael Guennebaud <gael.guennebaud@inria.fr>
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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_FWD_H
12#define EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_FWD_H
13
14// IWYU pragma: private
15#include "../../InternalHeaderCheck.h"
16
17namespace Eigen {
18namespace internal {
19
20// Forward declarations of the generic math functions
21// implemented in GenericPacketMathFunctions.h
22// This is needed to workaround a circular dependency.
23
24/***************************************************************************
25 * Some generic implementations to be used by implementers
26 ***************************************************************************/
27
31template <typename Packet>
32EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Packet pfrexp_generic(const Packet& a, Packet& exponent);
33
34// Extracts the biased exponent value from Packet p, and casts the results to
35// a floating-point Packet type. Used by pfrexp_generic. Override this if
36// there is no unpacket_traits<Packet>::integer_packet.
37template <typename Packet>
38EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Packet pfrexp_generic_get_biased_exponent(const Packet& p);
39
43template <typename Packet>
44EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Packet pldexp_generic(const Packet& a, const Packet& exponent);
45
47template <typename Packet>
48EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Packet pldexp_apply_factors(const Packet& a, const Packet& c1, const Packet& c2);
49
50// Explicitly multiplies
51// a * (2^e)
52// clamping e to the range
53// [NumTraits<Scalar>::min_exponent()-2, NumTraits<Scalar>::max_exponent()]
54//
55// This is approx 7x faster than pldexp_impl, but will prematurely over/underflow
56// if 2^e doesn't fit into a normal floating-point Scalar.
57//
58// Assumes IEEE floating point format
59template <typename Packet>
60EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Packet pldexp_fast(const Packet& a, const Packet& exponent);
61
62namespace unary_pow {
63// The two operations on a floating-point packet's raw bits that the integer-exponent pow needs: a right shift by
64// the mantissa width and a lane-wise subtraction, both of the exponent field. Defined in GenericPacketMathPow.h
65// in terms of unpacket_traits<Packet>::integer_packet. Override these, and has_exponent_bit_ops, where there is
66// no integer_packet but the two operations can still be expressed.
67template <typename Packet, typename = void>
68struct has_exponent_bit_ops;
69template <typename Packet>
70EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet exponent_bits_shift_right(const Packet& bits);
71template <typename Packet>
72EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet exponent_bits_sub(const Packet& a_bits, const Packet& b_bits);
73} // namespace unary_pow
74
76template <typename Packet>
77EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcbrt_float(const Packet& x_in);
78
80template <typename Packet>
81EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcbrt_double(const Packet& x_in);
82
84template <typename Packet>
85EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog_float(const Packet _x);
86
88template <typename Packet>
89EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog2_float(const Packet _x);
90
92template <typename Packet>
93EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog_double(const Packet _x);
94
96template <typename Packet>
97EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog2_double(const Packet _x);
98
100template <typename Packet>
101EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet generic_log1p(const Packet& x);
102
104template <typename Packet>
105EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet generic_log1p_float(const Packet& x);
106
108template <typename Packet>
109EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet generic_log1p_double(const Packet& x);
110
112template <typename Packet>
113EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog1p_float(const Packet& x) {
114 return generic_log1p_float(x);
115}
116
118template <typename Packet>
119EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog1p_double(const Packet& x) {
120 return generic_log1p_double(x);
121}
122
124template <typename Packet>
125EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet generic_expm1(const Packet& x);
126
128template <typename Packet>
129EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet generic_atan(const Packet& x);
130
132template <typename Packet>
133EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet generic_exp2(const Packet& x);
134
136template <typename Packet>
137EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet generic_exp2_reduced(const Packet& f);
138
140template <typename Packet, bool IsFinite = false>
141EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp_float(const Packet _x);
142
144template <typename Packet>
145EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp_double(const Packet _x);
146
148template <typename Packet>
149EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x);
150
152template <typename Packet>
153EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcos_float(const Packet& x);
154
156template <typename Packet>
157EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptan_float(const Packet& x);
158
160template <typename Packet>
161EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x);
162
164template <typename Packet>
165EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcos_double(const Packet& x);
166
168template <typename Packet>
169EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptan_double(const Packet& x);
170
172template <typename Packet>
173EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pasin_float(const Packet& x);
174
176template <typename Packet>
177EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pacos_float(const Packet& x);
178
180template <typename Packet>
181EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptanh_float(const Packet& x);
182
184template <typename Packet>
185EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptanh_double(const Packet& x);
186
188template <typename Packet>
189EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet patanh_float(const Packet& x);
190
192template <typename Packet>
193EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet patanh_double(const Packet& x);
194
196template <typename Packet>
197EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psinh_float(const Packet& x);
198
200template <typename Packet>
201EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psinh_double(const Packet& x);
202
204template <typename Packet>
205EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcosh_float(const Packet& x);
206
208template <typename Packet>
209EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcosh_double(const Packet& x);
210
212template <typename Packet>
213EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pasinh_float(const Packet& x);
214
216template <typename Packet>
217EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pasinh_double(const Packet& x);
218
220template <typename Packet>
221EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pacosh_float(const Packet& x);
222
224template <typename Packet>
225EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pacosh_double(const Packet& x);
226
228template <typename Packet>
229EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog10_float(const Packet& x);
230
232template <typename Packet>
233EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog10_double(const Packet& x);
234
236template <typename Packet>
237EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psqrt_complex(const Packet& a);
238
240template <typename Packet>
241EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pdiv_complex(const Packet& x, const Packet& y);
242
244template <typename Packet>
245EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pmul_complex(const Packet& x, const Packet& y);
246
247template <typename Packet, int N>
248struct ppolevl;
249
251template <typename Packet>
252EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog_complex(const Packet& x);
253
255template <typename Packet>
256EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp_complex(const Packet& x);
257
258template <typename Packet>
259EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet generic_rint(const Packet& a);
260
261template <typename Packet>
262EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet generic_floor(const Packet& a);
263
264template <typename Packet>
265EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet generic_ceil(const Packet& a);
266
267template <typename Packet>
268EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet generic_trunc(const Packet& a);
269
270template <typename Packet>
271EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet generic_round(const Packet& a);
272
273// Macros for instantiating these generic functions for different backends.
274#define EIGEN_PACKET_FUNCTION(METHOD, SCALAR, PACKET) \
275 template <> \
276 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_UNUSED PACKET p##METHOD<PACKET>(const PACKET& _x) { \
277 return p##METHOD##_##SCALAR(_x); \
278 }
279
280// Macros for instantiating these generic functions for different backends.
281#define EIGEN_GENERIC_PACKET_FUNCTION(METHOD, PACKET) \
282 template <> \
283 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_UNUSED PACKET p##METHOD<PACKET>(const PACKET& _x) { \
284 return generic_##METHOD(_x); \
285 }
286
287#define EIGEN_FLOAT_PACKET_FUNCTION(METHOD, PACKET) EIGEN_PACKET_FUNCTION(METHOD, float, PACKET)
288#define EIGEN_DOUBLE_PACKET_FUNCTION(METHOD, PACKET) EIGEN_PACKET_FUNCTION(METHOD, double, PACKET)
289
290#define EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(PACKET) \
291 EIGEN_FLOAT_PACKET_FUNCTION(sin, PACKET) \
292 EIGEN_FLOAT_PACKET_FUNCTION(cos, PACKET) \
293 EIGEN_FLOAT_PACKET_FUNCTION(tan, PACKET) \
294 EIGEN_FLOAT_PACKET_FUNCTION(asin, PACKET) \
295 EIGEN_FLOAT_PACKET_FUNCTION(acos, PACKET) \
296 EIGEN_FLOAT_PACKET_FUNCTION(sinh, PACKET) \
297 EIGEN_FLOAT_PACKET_FUNCTION(cosh, PACKET) \
298 EIGEN_FLOAT_PACKET_FUNCTION(tanh, PACKET) \
299 EIGEN_FLOAT_PACKET_FUNCTION(asinh, PACKET) \
300 EIGEN_FLOAT_PACKET_FUNCTION(acosh, PACKET) \
301 EIGEN_FLOAT_PACKET_FUNCTION(atanh, PACKET) \
302 EIGEN_FLOAT_PACKET_FUNCTION(log, PACKET) \
303 EIGEN_FLOAT_PACKET_FUNCTION(log2, PACKET) \
304 EIGEN_FLOAT_PACKET_FUNCTION(log10, PACKET) \
305 EIGEN_FLOAT_PACKET_FUNCTION(exp, PACKET) \
306 EIGEN_FLOAT_PACKET_FUNCTION(cbrt, PACKET) \
307 EIGEN_GENERIC_PACKET_FUNCTION(expm1, PACKET) \
308 EIGEN_GENERIC_PACKET_FUNCTION(exp2, PACKET) \
309 EIGEN_FLOAT_PACKET_FUNCTION(log1p, PACKET) \
310 EIGEN_GENERIC_PACKET_FUNCTION(atan, PACKET)
311
312#define EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_DOUBLE(PACKET) \
313 EIGEN_DOUBLE_PACKET_FUNCTION(sin, PACKET) \
314 EIGEN_DOUBLE_PACKET_FUNCTION(cos, PACKET) \
315 EIGEN_DOUBLE_PACKET_FUNCTION(tan, PACKET) \
316 EIGEN_DOUBLE_PACKET_FUNCTION(sinh, PACKET) \
317 EIGEN_DOUBLE_PACKET_FUNCTION(cosh, PACKET) \
318 EIGEN_DOUBLE_PACKET_FUNCTION(tanh, PACKET) \
319 EIGEN_DOUBLE_PACKET_FUNCTION(asinh, PACKET) \
320 EIGEN_DOUBLE_PACKET_FUNCTION(acosh, PACKET) \
321 EIGEN_DOUBLE_PACKET_FUNCTION(atanh, PACKET) \
322 EIGEN_DOUBLE_PACKET_FUNCTION(log, PACKET) \
323 EIGEN_DOUBLE_PACKET_FUNCTION(log2, PACKET) \
324 EIGEN_DOUBLE_PACKET_FUNCTION(log10, PACKET) \
325 EIGEN_DOUBLE_PACKET_FUNCTION(exp, PACKET) \
326 EIGEN_DOUBLE_PACKET_FUNCTION(cbrt, PACKET) \
327 EIGEN_GENERIC_PACKET_FUNCTION(expm1, PACKET) \
328 EIGEN_GENERIC_PACKET_FUNCTION(exp2, PACKET) \
329 EIGEN_DOUBLE_PACKET_FUNCTION(log1p, PACKET) \
330 EIGEN_GENERIC_PACKET_FUNCTION(atan, PACKET)
331
332// Macro to instantiate complex math function specializations (psqrt, plog, pexp)
333// that delegate to the generic implementations. Use in arch-specific Complex.h files.
334#define EIGEN_INSTANTIATE_COMPLEX_MATH_FUNCS(PacketType) \
335 template <> \
336 EIGEN_STRONG_INLINE PacketType psqrt<PacketType>(const PacketType& a) { \
337 return psqrt_complex<PacketType>(a); \
338 } \
339 template <> \
340 EIGEN_STRONG_INLINE PacketType plog<PacketType>(const PacketType& a) { \
341 return plog_complex<PacketType>(a); \
342 } \
343 template <> \
344 EIGEN_STRONG_INLINE PacketType pexp<PacketType>(const PacketType& a) { \
345 return pexp_complex<PacketType>(a); \
346 }
347
348// Variant without pexp, for backends where pexp needs special handling for a given packet type.
349#define EIGEN_INSTANTIATE_COMPLEX_MATH_FUNCS_NO_EXP(PacketType) \
350 template <> \
351 EIGEN_STRONG_INLINE PacketType psqrt<PacketType>(const PacketType& a) { \
352 return psqrt_complex<PacketType>(a); \
353 } \
354 template <> \
355 EIGEN_STRONG_INLINE PacketType plog<PacketType>(const PacketType& a) { \
356 return plog_complex<PacketType>(a); \
357 }
358
359} // end namespace internal
360} // end namespace Eigen
361
362#endif // EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_FWD_H