alpaka
Abstraction Library for Parallel Kernel Acceleration
Traits.hpp
Go to the documentation of this file.
1 /* Copyright 2023 Benjamin Worpitz, Matthias Werner, Jan Stephan, Bernhard Manfred Gruber, Sergei Bastrakov,
2  * Andrea Bocci, RenĂ© Widera
3  * SPDX-License-Identifier: MPL-2.0
4  */
5 
6 #pragma once
7 
8 #include "alpaka/core/Common.hpp"
10 
11 #include <cmath>
12 #include <complex>
13 #if __has_include(<version>) // Not part of the C++17 standard but all major standard libraries include this
14 # include <version>
15 #endif
16 #ifdef __cpp_lib_math_constants
17 # include <numbers>
18 #endif
19 
20 namespace alpaka::math
21 {
22  namespace constants
23  {
24 #ifdef __cpp_lib_math_constants
25  inline constexpr double e = std::numbers::e;
26  inline constexpr double log2e = std::numbers::log2e;
27  inline constexpr double log10e = std::numbers::log10e;
28  inline constexpr double pi = std::numbers::pi;
29  inline constexpr double inv_pi = std::numbers::inv_pi;
30  inline constexpr double ln2 = std::numbers::ln2;
31  inline constexpr double ln10 = std::numbers::ln10;
32  inline constexpr double sqrt2 = std::numbers::sqrt2;
33 
34  template<typename T>
35  inline constexpr T e_v = std::numbers::e_v<T>;
36 
37  template<typename T>
38  inline constexpr T log2e_v = std::numbers::log2e_v<T>;
39 
40  template<typename T>
41  inline constexpr T log10e_v = std::numbers::log10e_v<T>;
42 
43  template<typename T>
44  inline constexpr T pi_v = std::numbers::pi_v<T>;
45 
46  template<typename T>
47  inline constexpr T inv_pi_v = std::numbers::inv_pi_v<T>;
48 
49  template<typename T>
50  inline constexpr T ln2_v = std::numbers::ln2_v<T>;
51 
52  template<typename T>
53  inline constexpr T ln10_v = std::numbers::ln10_v<T>;
54 
55  template<typename T>
56  inline constexpr T sqrt2_v = std::numbers::sqrt2_v<T>;
57 #else
58  inline constexpr double e = M_E;
59  inline constexpr double log2e = M_LOG2E;
60  inline constexpr double log10e = M_LOG10E;
61  inline constexpr double pi = M_PI;
62  inline constexpr double inv_pi = M_1_PI;
63  inline constexpr double ln2 = M_LN2;
64  inline constexpr double ln10 = M_LN10;
65  inline constexpr double sqrt2 = M_SQRT2;
66 
67  template<typename T>
68  inline constexpr T e_v = static_cast<T>(e);
69 
70  template<typename T>
71  inline constexpr T log2e_v = static_cast<T>(log2e);
72 
73  template<typename T>
74  inline constexpr T log10e_v = static_cast<T>(log10e);
75 
76  template<typename T>
77  inline constexpr T pi_v = static_cast<T>(pi);
78 
79  template<typename T>
80  inline constexpr T inv_pi_v = static_cast<T>(inv_pi);
81 
82  template<typename T>
83  inline constexpr T ln2_v = static_cast<T>(ln2);
84 
85  template<typename T>
86  inline constexpr T ln10_v = static_cast<T>(ln10);
87 
88  template<typename T>
89  inline constexpr T sqrt2_v = static_cast<T>(sqrt2);
90 
91  // Use predefined float constants when available
92 # if defined(M_Ef)
93  template<>
94  inline constexpr float e_v<float> = M_Ef;
95 # endif
96 
97 # if defined(M_LOG2Ef)
98  template<>
99  inline constexpr float log2e_v<float> = M_LOG2Ef;
100 # endif
101 
102 # if defined(M_LOG10Ef)
103  template<>
104  inline constexpr float log10e_v<float> = M_LOG10Ef;
105 # endif
106 
107 # if defined(M_PIf)
108  template<>
109  inline constexpr float pi_v<float> = M_PIf;
110 # endif
111 
112 # if defined(M_1_PIf)
113  template<>
114  inline constexpr float inv_pi_v<float> = M_1_PIf;
115 # endif
116 
117 # if defined(M_LN2f)
118  template<>
119  inline constexpr float ln2_v<float> = M_LN2f;
120 # endif
121 
122 # if defined(M_LN10f)
123  template<>
124  inline constexpr float ln10_v<float> = M_LN10f;
125 # endif
126 
127 # if defined(M_SQRT2f)
128  template<>
129  inline constexpr float sqrt2_v<float> = M_SQRT2f;
130 # endif
131 
132 #endif
133  } // namespace constants
134 
136  {
137  };
138 
140  {
141  };
142 
144  {
145  };
146 
148  {
149  };
150 
152  {
153  };
154 
156  {
157  };
158 
160  {
161  };
162 
164  {
165  };
166 
168  {
169  };
170 
172  {
173  };
174 
176  {
177  };
178 
180  {
181  };
182 
184  {
185  };
186 
188  {
189  };
190 
192  {
193  };
194 
196  {
197  };
198 
200  {
201  };
202 
204  {
205  };
206 
208  {
209  };
210 
212  {
213  };
214 
216  {
217  };
218 
220  {
221  };
222 
224  {
225  };
226 
228  {
229  };
230 
232  {
233  };
234 
236  {
237  };
238 
240  {
241  };
242 
244  {
245  };
246 
248  {
249  };
250 
252  {
253  };
254 
256  {
257  };
258 
260  {
261  };
262 
264  {
265  };
266 
268  {
269  };
270 
272  {
273  };
274 
276  {
277  };
278 
280  {
281  };
282 
284  {
285  };
286 
288  {
289  };
290 
291  //! The math traits.
292  namespace trait
293  {
294  //! The abs trait.
295  template<typename T, typename TArg, typename TSfinae = void>
296  struct Abs
297  {
298  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
299  {
300  // This is an ADL call. If you get a compile error here then your type is not supported by the
301  // backend and we could not find abs(TArg) in the namespace of your type.
302  using std::abs;
303  return abs(arg);
304  }
305  };
306 
307  //! The acos trait.
308  template<typename T, typename TArg, typename TSfinae = void>
309  struct Acos
310  {
311  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
312  {
313  // This is an ADL call. If you get a compile error here then your type is not supported by the
314  // backend and we could not find acos(TArg) in the namespace of your type.
315  using std::acos;
316  return acos(arg);
317  }
318  };
319 
320  //! The acosh trait.
321  template<typename T, typename TArg, typename TSfinae = void>
322  struct Acosh
323  {
324  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
325  {
326  // This is an ADL call. If you get a compile error here then your type is not supported by the
327  // backend and we could not find acosh(TArg) in the namespace of your type.
328  using std::acosh;
329  return acosh(arg);
330  }
331  };
332 
333  //! The arg trait.
334  template<typename T, typename TArgument, typename TSfinae = void>
335  struct Arg
336  {
337  // It is unclear why this is needed here and not in other math trait structs. But removing it causes
338  // warnings with calling a __host__ function from a __host__ __device__ function when building for CUDA.
340  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArgument const& argument)
341  {
342  // This is an ADL call. If you get a compile error here then your type is not supported by the
343  // backend and we could not find arg(TArgument) in the namespace of your type.
344  using std::arg;
345  return arg(argument);
346  }
347  };
348 
349  //! The asin trait.
350  template<typename T, typename TArg, typename TSfinae = void>
351  struct Asin
352  {
353  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
354  {
355  // This is an ADL call. If you get a compile error here then your type is not supported by the
356  // backend and we could not find asin(TArg) in the namespace of your type.
357  using std::asin;
358  return asin(arg);
359  }
360  };
361 
362  //! The asin trait.
363  template<typename T, typename TArg, typename TSfinae = void>
364  struct Asinh
365  {
366  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
367  {
368  // This is an ADL call. If you get a compile error here then your type is not supported by the
369  // backend and we could not find asin(TArg) in the namespace of your type.
370  using std::asinh;
371  return asinh(arg);
372  }
373  };
374 
375  //! The atan trait.
376  template<typename T, typename TArg, typename TSfinae = void>
377  struct Atan
378  {
379  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
380  {
381  // This is an ADL call. If you get a compile error here then your type is not supported by the
382  // backend and we could not find atan(TArg) in the namespace of your type.
383  using std::atan;
384  return atan(arg);
385  }
386  };
387 
388  //! The atanh trait.
389  template<typename T, typename TArg, typename TSfinae = void>
390  struct Atanh
391  {
392  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
393  {
394  // This is an ADL call. If you get a compile error here then your type is not supported by the
395  // backend and we could not find atanh(TArg) in the namespace of your type.
396  using std::atanh;
397  return atanh(arg);
398  }
399  };
400 
401  //! The atan2 trait.
402  template<typename T, typename Ty, typename Tx, typename TSfinae = void>
403  struct Atan2
404  {
405  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, Ty const& y, Tx const& x)
406  {
407  // This is an ADL call. If you get a compile error here then your type is not supported by the
408  // backend and we could not find atan2(Tx, Ty) in the namespace of your type.
409  using std::atan2;
410  return atan2(y, x);
411  }
412  };
413 
414  //! The cbrt trait.
415  template<typename T, typename TArg, typename TSfinae = void>
416  struct Cbrt
417  {
418  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
419  {
420  // This is an ADL call. If you get a compile error here then your type is not supported by the
421  // backend and we could not find cbrt(TArg) in the namespace of your type.
422  using std::cbrt;
423  return cbrt(arg);
424  } //! The erf trait.
425  };
426 
427  //! The ceil trait.
428  template<typename T, typename TArg, typename TSfinae = void>
429  struct Ceil
430  {
431  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
432  {
433  // This is an ADL call. If you get a compile error here then your type is not supported by the
434  // backend and we could not find ceil(TArg) in the namespace of your type.
435  using std::ceil;
436  return ceil(arg);
437  }
438  };
439 
440  //! The conj trait.
441  template<typename T, typename TArg, typename TSfinae = void>
442  struct Conj
443  {
444  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
445  {
446  // This is an ADL call. If you get a compile error here then your type is not supported by the
447  // backend and we could not find conj(TArg) in the namespace of your type.
448  using std::conj;
449  return conj(arg);
450  }
451  };
452 
453  //! The copysign trait.
454  template<typename T, typename TMag, typename TSgn, typename TSfinae = void>
455  struct Copysign
456  {
457  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TMag const& mag, TSgn const& sgn)
458  {
459  // This is an ADL call. If you get a compile error here then your type is not supported by the
460  // backend and we could not find copysign(TMag, TSgn) in the namespace of your type.
461  using std::copysign;
462  return copysign(mag, sgn);
463  }
464  };
465 
466  //! The cos trait.
467  template<typename T, typename TArg, typename TSfinae = void>
468  struct Cos
469  {
470  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
471  {
472  // This is an ADL call. If you get a compile error here then your type is not supported by the
473  // backend and we could not find cos(TArg) in the namespace of your type.
474  using std::cos;
475  return cos(arg);
476  }
477  };
478 
479  //! The cosh trait.
480  template<typename T, typename TArg, typename TSfinae = void>
481  struct Cosh
482  {
483  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
484  {
485  // This is an ADL call. If you get a compile error here then your type is not supported by the
486  // backend and we could not find cos(TArg) in the namespace of your type.
487  using std::cosh;
488  return cosh(arg);
489  }
490  };
491 
492  template<typename T, typename TArg, typename TSfinae = void>
493  struct Erf
494  {
495  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
496  {
497  // This is an ADL call. If you get a compile error here then your type is not supported by the
498  // backend and we could not find erf(TArg) in the namespace of your type.
499  using std::erf;
500  return erf(arg);
501  }
502  };
503 
504  //! The exp trait.
505  template<typename T, typename TArg, typename TSfinae = void>
506  struct Exp
507  {
508  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
509  {
510  // This is an ADL call. If you get a compile error here then your type is not supported by the
511  // backend and we could not find exp(TArg) in the namespace of your type.
512  using std::exp;
513  return exp(arg);
514  }
515  };
516 
517  //! The floor trait.
518  template<typename T, typename TArg, typename TSfinae = void>
519  struct Floor
520  {
521  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
522  {
523  // This is an ADL call. If you get a compile error here then your type is not supported by the
524  // backend and we could not find floor(TArg) in the namespace of your type.
525  using std::floor;
526  return floor(arg);
527  }
528  };
529 
530  //! The fma trait.
531  template<typename T, typename Tx, typename Ty, typename Tz, typename TSfinae = void>
532  struct Fma
533  {
534  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, Tx const& x, Ty const& y, Tz const& z)
535  {
536  // This is an ADL call. If you get a compile error here then your type is not supported by the
537  // backend and we could not find fma(Tx, Ty, Tz) in the namespace of your type.
538  using std::fma;
539  return fma(x, y, z);
540  }
541  };
542 
543  //! The fmod trait.
544  template<typename T, typename Tx, typename Ty, typename TSfinae = void>
545  struct Fmod
546  {
547  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, Tx const& x, Ty const& y)
548  {
549  // This is an ADL call. If you get a compile error here then your type is not supported by the
550  // backend and we could not find fmod(Tx, Ty) in the namespace of your type.
551  using std::fmod;
552  return fmod(x, y);
553  }
554  };
555 
556  //! The isfinite trait.
557  template<typename T, typename TArg, typename TSfinae = void>
558  struct Isfinite
559  {
560  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
561  {
562  // This is an ADL call. If you get a compile error here then your type is not supported by the
563  // backend and we could not find isfinite(TArg) in the namespace of your type.
564  using std::isfinite;
565  return isfinite(arg);
566  }
567  };
568 
569  //! The isinf trait.
570  template<typename T, typename TArg, typename TSfinae = void>
571  struct Isinf
572  {
573  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
574  {
575  // This is an ADL call. If you get a compile error here then your type is not supported by the
576  // backend and we could not find isinf(TArg) in the namespace of your type.
577  using std::isinf;
578  return isinf(arg);
579  }
580  };
581 
582  //! The isnan trait.
583  template<typename T, typename TArg, typename TSfinae = void>
584  struct Isnan
585  {
586  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
587  {
588  // This is an ADL call. If you get a compile error here then your type is not supported by the
589  // backend and we could not find isnan(TArg) in the namespace of your type.
590  using std::isnan;
591  return isnan(arg);
592  }
593  };
594 
595  //! The log trait.
596  template<typename T, typename TArg, typename TSfinae = void>
597  struct Log
598  {
599  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
600  {
601  // This is an ADL call. If you get a compile error here then your type is not supported by the
602  // backend and we could not find log(TArg) in the namespace of your type.
603  using std::log;
604  return log(arg);
605  }
606  };
607 
608  //! The bas 2 log trait.
609  template<typename T, typename TArg, typename TSfinae = void>
610  struct Log2
611  {
612  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
613  {
614  // This is an ADL call. If you get a compile error here then your type is not supported by the
615  // backend and we could not find log2(TArg) in the namespace of your type.
616  using std::log2;
617  return log2(arg);
618  }
619  };
620 
621  //! The base 10 log trait.
622  template<typename T, typename TArg, typename TSfinae = void>
623  struct Log10
624  {
625  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
626  {
627  // This is an ADL call. If you get a compile error here then your type is not supported by the
628  // backend and we could not find log10(TArg) in the namespace of your type.
629  using std::log10;
630  return log10(arg);
631  }
632  };
633 
634  //! The max trait.
635  template<typename T, typename Tx, typename Ty, typename TSfinae = void>
636  struct Max
637  {
638  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, Tx const& x, Ty const& y)
639  {
640  // This is an ADL call. If you get a compile error here then your type is not supported by the
641  // backend and we could not find max(Tx, Ty) in the namespace of your type.
642  using std::max;
643  return max(x, y);
644  }
645  };
646 
647  //! The min trait.
648  template<typename T, typename Tx, typename Ty, typename TSfinae = void>
649  struct Min
650  {
651  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, Tx const& x, Ty const& y)
652  {
653  // This is an ADL call. If you get a compile error here then your type is not supported by the
654  // backend and we could not find min(Tx, Ty) in the namespace of your type.
655  using std::min;
656  return min(x, y);
657  }
658  };
659 
660  //! The pow trait.
661  template<typename T, typename TBase, typename TExp, typename TSfinae = void>
662  struct Pow
663  {
664  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TBase const& base, TExp const& exp)
665  {
666  // This is an ADL call. If you get a compile error here then your type is not supported by the
667  // backend and we could not find pow(base, exp) in the namespace of your type.
668  using std::pow;
669  return pow(base, exp);
670  }
671  };
672 
673  //! The remainder trait.
674  template<typename T, typename Tx, typename Ty, typename TSfinae = void>
675  struct Remainder
676  {
677  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, Tx const& x, Ty const& y)
678  {
679  // This is an ADL call. If you get a compile error here then your type is not supported by the
680  // backend and we could not find remainder(Tx, Ty) in the namespace of your type.
681  using std::remainder;
682  return remainder(x, y);
683  }
684  };
685 
686  //! The round trait.
687  template<typename T, typename TArg, typename TSfinae = void>
688  struct Round
689  {
690  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
691  {
692  // This is an ADL call. If you get a compile error here then your type is not supported by the
693  // backend and we could not find round(TArg) in the namespace of your type.
694  using std::round;
695  return round(arg);
696  }
697  };
698 
699  //! The round trait.
700  template<typename T, typename TArg, typename TSfinae = void>
701  struct Lround
702  {
703  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
704  {
705  // This is an ADL call. If you get a compile error here then your type is not supported by the
706  // backend and we could not find lround(TArg) in the namespace of your type.
707  using std::lround;
708  return lround(arg);
709  }
710  };
711 
712  //! The round trait.
713  template<typename T, typename TArg, typename TSfinae = void>
714  struct Llround
715  {
716  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
717  {
718  // This is an ADL call. If you get a compile error here then your type is not supported by the
719  // backend and we could not find llround(TArg) in the namespace of your type.
720  using std::llround;
721  return llround(arg);
722  }
723  };
724 
725  namespace detail
726  {
727  //! Fallback implementation when no better ADL match was found
728  template<typename TArg>
729  ALPAKA_FN_HOST_ACC auto rsqrt(TArg const& arg)
730  {
731  // Still use ADL to try find sqrt(arg)
732  using std::sqrt;
733  return static_cast<TArg>(1) / sqrt(arg);
734  }
735  } // namespace detail
736 
737  //! The rsqrt trait.
738  template<typename T, typename TArg, typename TSfinae = void>
739  struct Rsqrt
740  {
741  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
742  {
743  // This is an ADL call. If you get a compile error here then your type is not supported by the
744  // backend and we could not find rsqrt(TArg) in the namespace of your type.
745  using detail::rsqrt;
746  return rsqrt(arg);
747  }
748  };
749 
750  //! The sin trait.
751  template<typename T, typename TArg, typename TSfinae = void>
752  struct Sin
753  {
754  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
755  {
756  // This is an ADL call. If you get a compile error here then your type is not supported by the
757  // backend and we could not find sin(TArg) in the namespace of your type.
758  using std::sin;
759  return sin(arg);
760  }
761  };
762 
763  //! The sin trait.
764  template<typename T, typename TArg, typename TSfinae = void>
765  struct Sinh
766  {
767  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
768  {
769  // This is an ADL call. If you get a compile error here then your type is not supported by the
770  // backend and we could not find sin(TArg) in the namespace of your type.
771  using std::sinh;
772  return sinh(arg);
773  }
774  };
775 
776  namespace detail
777  {
778  //! Fallback implementation when no better ADL match was found
779  template<typename TArg>
780  ALPAKA_FN_HOST_ACC auto sincos(TArg const& arg, TArg& result_sin, TArg& result_cos)
781  {
782  // Still use ADL to try find sin(arg) and cos(arg)
783  using std::sin;
784  result_sin = sin(arg);
785  using std::cos;
786  result_cos = cos(arg);
787  }
788  } // namespace detail
789 
790  //! The sincos trait.
791  template<typename T, typename TArg, typename TSfinae = void>
792  struct SinCos
793  {
794  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg, TArg& result_sin, TArg& result_cos)
795  {
796  // This is an ADL call. If you get a compile error here then your type is not supported by the
797  // backend and we could not find sincos(TArg, TArg&, TArg&) in the namespace of your type.
798  using detail::sincos;
799  return sincos(arg, result_sin, result_cos);
800  }
801  };
802 
803  //! The sqrt trait.
804  template<typename T, typename TArg, typename TSfinae = void>
805  struct Sqrt
806  {
807  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
808  {
809  // This is an ADL call. If you get a compile error here then your type is not supported by the
810  // backend and we could not find sqrt(TArg) in the namespace of your type.
811  using std::sqrt;
812  return sqrt(arg);
813  }
814  };
815 
816  //! The tan trait.
817  template<typename T, typename TArg, typename TSfinae = void>
818  struct Tan
819  {
820  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
821  {
822  // This is an ADL call. If you get a compile error here then your type is not supported by the
823  // backend and we could not find tan(TArg) in the namespace of your type.
824  using std::tan;
825  return tan(arg);
826  }
827  };
828 
829  //! The tanh trait.
830  template<typename T, typename TArg, typename TSfinae = void>
831  struct Tanh
832  {
833  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
834  {
835  // This is an ADL call. If you get a compile error here then your type is not supported by the
836  // backend and we could not find tanh(TArg) in the namespace of your type.
837  using std::tanh;
838  return tanh(arg);
839  }
840  };
841 
842  //! The trunc trait.
843  template<typename T, typename TArg, typename TSfinae = void>
844  struct Trunc
845  {
846  ALPAKA_FN_HOST_ACC auto operator()(T const& /* ctx */, TArg const& arg)
847  {
848  // This is an ADL call. If you get a compile error here then your type is not supported by the
849  // backend and we could not find trunc(TArg) in the namespace of your type.
850  using std::trunc;
851  return trunc(arg);
852  }
853  };
854  } // namespace trait
855 
856  //! Computes the absolute value.
857  //!
858  //! \tparam T The type of the object specializing Abs.
859  //! \tparam TArg The arg type.
860  //! \param abs_ctx The object specializing Abs.
861  //! \param arg The arg.
863  template<typename T, typename TArg>
864  ALPAKA_FN_HOST_ACC auto abs(T const& abs_ctx, TArg const& arg)
865  {
867  return trait::Abs<ImplementationBase, TArg>{}(abs_ctx, arg);
868  }
869 
870  //! Computes the principal value of the arc cosine.
871  //!
872  //! The valid real argument range is [-1.0, 1.0]. For other values
873  //! the result may depend on the backend and compilation options, will
874  //! likely be NaN.
875  //!
876  //! \tparam TArg The arg type.
877  //! \param acos_ctx The object specializing Acos.
878  //! \param arg The arg.
880  template<typename T, typename TArg>
881  ALPAKA_FN_HOST_ACC auto acos(T const& acos_ctx, TArg const& arg)
882  {
884  return trait::Acos<ImplementationBase, TArg>{}(acos_ctx, arg);
885  }
886 
887  //! Computes the principal value of the hyperbolic arc cosine.
888  //!
889  //! The valid real argument range is [1.0, Inf]. For other values
890  //! the result may depend on the backend and compilation options, will
891  //! likely be NaN.
892  //!
893  //! \tparam TArg The arg type.
894  //! \param acosh_ctx The object specializing Acos.
895  //! \param arg The arg.
897  template<typename T, typename TArg>
898  ALPAKA_FN_HOST_ACC auto acosh(T const& acosh_ctx, TArg const& arg)
899  {
901  return trait::Acosh<ImplementationBase, TArg>{}(acosh_ctx, arg);
902  }
903 
904  //! Computes the complex argument of the value.
905  //!
906  //! \tparam T The type of the object specializing Arg.
907  //! \tparam TArgument The argument type.
908  //! \param arg_ctx The object specializing Arg.
909  //! \param argument The argument.
911  template<typename T, typename TArgument>
912  ALPAKA_FN_HOST_ACC auto arg(T const& arg_ctx, TArgument const& argument)
913  {
915  return trait::Arg<ImplementationBase, TArgument>{}(arg_ctx, argument);
916  }
917 
918  //! Computes the principal value of the arc sine.
919  //!
920  //! The valid real argument range is [-1.0, 1.0]. For other values
921  //! the result may depend on the backend and compilation options, will
922  //! likely be NaN.
923  //!
924  //! \tparam TArg The arg type.
925  //! \param asin_ctx The object specializing Asin.
926  //! \param arg The arg.
928  template<typename T, typename TArg>
929  ALPAKA_FN_HOST_ACC auto asin(T const& asin_ctx, TArg const& arg)
930  {
932  return trait::Asin<ImplementationBase, TArg>{}(asin_ctx, arg);
933  }
934 
935  //! Computes the principal value of the hyperbolic arc sine.
936  //!
937  //! \tparam TArg The arg type.
938  //! \param asinh_ctx The object specializing Asin.
939  //! \param arg The arg.
941  template<typename T, typename TArg>
942  ALPAKA_FN_HOST_ACC auto asinh(T const& asinh_ctx, TArg const& arg)
943  {
945  return trait::Asinh<ImplementationBase, TArg>{}(asinh_ctx, arg);
946  }
947 
948  //! Computes the principal value of the arc tangent.
949  //!
950  //! \tparam TArg The arg type.
951  //! \param atan_ctx The object specializing Atan.
952  //! \param arg The arg.
954  template<typename T, typename TArg>
955  ALPAKA_FN_HOST_ACC auto atan(T const& atan_ctx, TArg const& arg)
956  {
958  return trait::Atan<ImplementationBase, TArg>{}(atan_ctx, arg);
959  }
960 
961  //! Computes the principal value of the hyperbolic arc tangent.
962  //!
963  //! The valid real argument range is [-1.0, 1.0]. For other values
964  //! the result may depend on the backend and compilation options, will
965  //! likely be NaN.
966 
967  //! \tparam TArg The arg type.
968  //! \param atanh_ctx The object specializing Atanh.
969  //! \param arg The arg.
971  template<typename T, typename TArg>
972  ALPAKA_FN_HOST_ACC auto atanh(T const& atanh_ctx, TArg const& arg)
973  {
975  return trait::Atanh<ImplementationBase, TArg>{}(atanh_ctx, arg);
976  }
977 
978  //! Computes the arc tangent of y/x using the signs of arguments to determine the correct quadrant.
979  //!
980  //! \tparam T The type of the object specializing Atan2.
981  //! \tparam Ty The y arg type.
982  //! \tparam Tx The x arg type.
983  //! \param atan2_ctx The object specializing Atan2.
984  //! \param y The y arg.
985  //! \param x The x arg.
987  template<typename T, typename Ty, typename Tx>
988  ALPAKA_FN_HOST_ACC auto atan2(T const& atan2_ctx, Ty const& y, Tx const& x)
989  {
991  return trait::Atan2<ImplementationBase, Ty, Tx>{}(atan2_ctx, y, x);
992  }
993 
994  //! Computes the cbrt.
995  //!
996  //! \tparam T The type of the object specializing Cbrt.
997  //! \tparam TArg The arg type.
998  //! \param cbrt_ctx The object specializing Cbrt.
999  //! \param arg The arg.
1001  template<typename T, typename TArg>
1002  ALPAKA_FN_HOST_ACC auto cbrt(T const& cbrt_ctx, TArg const& arg)
1003  {
1005  return trait::Cbrt<ImplementationBase, TArg>{}(cbrt_ctx, arg);
1006  }
1007 
1008  //! Computes the smallest integer value not less than arg.
1009  //!
1010  //! \tparam T The type of the object specializing Ceil.
1011  //! \tparam TArg The arg type.
1012  //! \param ceil_ctx The object specializing Ceil.
1013  //! \param arg The arg.
1015  template<typename T, typename TArg>
1016  ALPAKA_FN_HOST_ACC auto ceil(T const& ceil_ctx, TArg const& arg)
1017  {
1019  return trait::Ceil<ImplementationBase, TArg>{}(ceil_ctx, arg);
1020  }
1021 
1022  //! Computes the complex conjugate of arg.
1023  //!
1024  //! \tparam T The type of the object specializing Conj.
1025  //! \tparam TArg The arg type.
1026  //! \param conj_ctx The object specializing Conj.
1027  //! \param arg The arg.
1029  template<typename T, typename TArg>
1030  ALPAKA_FN_HOST_ACC auto conj(T const& conj_ctx, TArg const& arg)
1031  {
1033  return trait::Conj<ImplementationBase, TArg>{}(conj_ctx, arg);
1034  }
1035 
1036  //! Creates a value with the magnitude of mag and the sign of sgn.
1037  //!
1038  //! \tparam T The type of the object specializing Copysign.
1039  //! \tparam TMag The mag type.
1040  //! \tparam TSgn The sgn type.
1041  //! \param copysign_ctx The object specializing Copysign.
1042  //! \param mag The mag.
1043  //! \param sgn The sgn.
1045  template<typename T, typename TMag, typename TSgn>
1046  ALPAKA_FN_HOST_ACC auto copysign(T const& copysign_ctx, TMag const& mag, TSgn const& sgn)
1047  {
1049  return trait::Copysign<ImplementationBase, TMag, TSgn>{}(copysign_ctx, mag, sgn);
1050  }
1051 
1052  //! Computes the cosine (measured in radians).
1053  //!
1054  //! \tparam T The type of the object specializing Cos.
1055  //! \tparam TArg The arg type.
1056  //! \param cos_ctx The object specializing Cos.
1057  //! \param arg The arg.
1059  template<typename T, typename TArg>
1060  ALPAKA_FN_HOST_ACC auto cos(T const& cos_ctx, TArg const& arg)
1061  {
1063  return trait::Cos<ImplementationBase, TArg>{}(cos_ctx, arg);
1064  }
1065 
1066  //! Computes the hyperbolic cosine (measured in radians).
1067  //!
1068  //! \tparam T The type of the object specializing Cos.
1069  //! \tparam TArg The arg type.
1070  //! \param cosh_ctx The object specializing Cos.
1071  //! \param arg The arg.
1073  template<typename T, typename TArg>
1074  ALPAKA_FN_HOST_ACC auto cosh(T const& cosh_ctx, TArg const& arg)
1075  {
1077  return trait::Cosh<ImplementationBase, TArg>{}(cosh_ctx, arg);
1078  }
1079 
1080  //! Computes the error function of arg.
1081  //!
1082  //! \tparam T The type of the object specializing Erf.
1083  //! \tparam TArg The arg type.
1084  //! \param erf_ctx The object specializing Erf.
1085  //! \param arg The arg.
1087  template<typename T, typename TArg>
1088  ALPAKA_FN_HOST_ACC auto erf(T const& erf_ctx, TArg const& arg)
1089  {
1091  return trait::Erf<ImplementationBase, TArg>{}(erf_ctx, arg);
1092  }
1093 
1094  //! Computes the e (Euler's number, 2.7182818) raised to the given power arg.
1095  //!
1096  //! \tparam T The type of the object specializing Exp.
1097  //! \tparam TArg The arg type.
1098  //! \param exp_ctx The object specializing Exp.
1099  //! \param arg The arg.
1101  template<typename T, typename TArg>
1102  ALPAKA_FN_HOST_ACC auto exp(T const& exp_ctx, TArg const& arg)
1103  {
1105  return trait::Exp<ImplementationBase, TArg>{}(exp_ctx, arg);
1106  }
1107 
1108  //! Computes the largest integer value not greater than arg.
1109  //!
1110  //! \tparam T The type of the object specializing Floor.
1111  //! \tparam TArg The arg type.
1112  //! \param floor_ctx The object specializing Floor.
1113  //! \param arg The arg.
1115  template<typename T, typename TArg>
1116  ALPAKA_FN_HOST_ACC auto floor(T const& floor_ctx, TArg const& arg)
1117  {
1119  return trait::Floor<ImplementationBase, TArg>{}(floor_ctx, arg);
1120  }
1121 
1122  //! Computes x * y + z as if to infinite precision and rounded only once to fit the result type.
1123  //!
1124  //! \tparam T The type of the object specializing Fma.
1125  //! \tparam Tx The type of the first argument.
1126  //! \tparam Ty The type of the second argument.
1127  //! \tparam Tz The type of the third argument.
1128  //! \param fma_ctx The object specializing .
1129  //! \param x The first argument.
1130  //! \param y The second argument.
1131  //! \param z The third argument.
1133  template<typename T, typename Tx, typename Ty, typename Tz>
1134  ALPAKA_FN_HOST_ACC auto fma(T const& fma_ctx, Tx const& x, Ty const& y, Tz const& z)
1135  {
1137  return trait::Fma<ImplementationBase, Tx, Ty, Tz>{}(fma_ctx, x, y, z);
1138  }
1139 
1140  //! Computes the floating-point remainder of the division operation x/y.
1141  //!
1142  //! \tparam T The type of the object specializing Fmod.
1143  //! \tparam Tx The type of the first argument.
1144  //! \tparam Ty The type of the second argument.
1145  //! \param fmod_ctx The object specializing Fmod.
1146  //! \param x The first argument.
1147  //! \param y The second argument.
1149  template<typename T, typename Tx, typename Ty>
1150  ALPAKA_FN_HOST_ACC auto fmod(T const& fmod_ctx, Tx const& x, Ty const& y)
1151  {
1153  return trait::Fmod<ImplementationBase, Tx, Ty>{}(fmod_ctx, x, y);
1154  }
1155 
1156  //! Checks if given value is finite.
1157  //!
1158  //! \tparam T The type of the object specializing Isfinite.
1159  //! \tparam TArg The arg type.
1160  //! \param ctx The object specializing Isfinite.
1161  //! \param arg The arg.
1163  template<typename T, typename TArg>
1164  ALPAKA_FN_HOST_ACC auto isfinite(T const& ctx, TArg const& arg)
1165  {
1168  }
1169 
1170  //! Checks if given value is inf.
1171  //!
1172  //! \tparam T The type of the object specializing Isinf.
1173  //! \tparam TArg The arg type.
1174  //! \param ctx The object specializing Isinf.
1175  //! \param arg The arg.
1177  template<typename T, typename TArg>
1178  ALPAKA_FN_HOST_ACC auto isinf(T const& ctx, TArg const& arg)
1179  {
1182  }
1183 
1184  //! Checks if given value is NaN.
1185  //!
1186  //! \tparam T The type of the object specializing Isnan.
1187  //! \tparam TArg The arg type.
1188  //! \param ctx The object specializing Isnan.
1189  //! \param arg The arg.
1191  template<typename T, typename TArg>
1192  ALPAKA_FN_HOST_ACC auto isnan(T const& ctx, TArg const& arg)
1193  {
1196  }
1197 
1198  //! Computes the the natural (base e) logarithm of arg.
1199  //!
1200  //! Valid real arguments are non-negative. For other values the result
1201  //! may depend on the backend and compilation options, will likely
1202  //! be NaN.
1203  //!
1204  //! \tparam T The type of the object specializing Log.
1205  //! \tparam TArg The arg type.
1206  //! \param log_ctx The object specializing Log.
1207  //! \param arg The arg.
1209  template<typename T, typename TArg>
1210  ALPAKA_FN_HOST_ACC auto log(T const& log_ctx, TArg const& arg)
1211  {
1213  return trait::Log<ImplementationBase, TArg>{}(log_ctx, arg);
1214  }
1215 
1216  //! Computes the the natural (base 2) logarithm of arg.
1217  //!
1218  //! Valid real arguments are non-negative. For other values the result
1219  //! may depend on the backend and compilation options, will likely
1220  //! be NaN.
1221  //!
1222  //! \tparam T The type of the object specializing Log2.
1223  //! \tparam TArg The arg type.
1224  //! \param log2_ctx The object specializing Log2.
1225  //! \param arg The arg.
1227  template<typename T, typename TArg>
1228  ALPAKA_FN_HOST_ACC auto log2(T const& log2_ctx, TArg const& arg)
1229  {
1231  return trait::Log2<ImplementationBase, TArg>{}(log2_ctx, arg);
1232  }
1233 
1234  //! Computes the the natural (base 10) logarithm of arg.
1235  //!
1236  //! Valid real arguments are non-negative. For other values the result
1237  //! may depend on the backend and compilation options, will likely
1238  //! be NaN.
1239  //!
1240  //! \tparam T The type of the object specializing Log10.
1241  //! \tparam TArg The arg type.
1242  //! \param log10_ctx The object specializing Log10.
1243  //! \param arg The arg.
1245  template<typename T, typename TArg>
1246  ALPAKA_FN_HOST_ACC auto log10(T const& log10_ctx, TArg const& arg)
1247  {
1249  return trait::Log10<ImplementationBase, TArg>{}(log10_ctx, arg);
1250  }
1251 
1252  //! Returns the larger of two arguments.
1253  //! NaNs are treated as missing data (between a NaN and a numeric value, the numeric value is chosen).
1254  //!
1255  //! \tparam T The type of the object specializing Max.
1256  //! \tparam Tx The type of the first argument.
1257  //! \tparam Ty The type of the second argument.
1258  //! \param max_ctx The object specializing Max.
1259  //! \param x The first argument.
1260  //! \param y The second argument.
1262  template<typename T, typename Tx, typename Ty>
1263  ALPAKA_FN_HOST_ACC auto max(T const& max_ctx, Tx const& x, Ty const& y)
1264  {
1266  return trait::Max<ImplementationBase, Tx, Ty>{}(max_ctx, x, y);
1267  }
1268 
1269  //! Returns the smaller of two arguments.
1270  //! NaNs are treated as missing data (between a NaN and a numeric value, the numeric value is chosen).
1271  //!
1272  //! \tparam T The type of the object specializing Min.
1273  //! \tparam Tx The type of the first argument.
1274  //! \tparam Ty The type of the second argument.
1275  //! \param min_ctx The object specializing Min.
1276  //! \param x The first argument.
1277  //! \param y The second argument.
1279  template<typename T, typename Tx, typename Ty>
1280  ALPAKA_FN_HOST_ACC auto min(T const& min_ctx, Tx const& x, Ty const& y)
1281  {
1283  return trait::Min<ImplementationBase, Tx, Ty>{}(min_ctx, x, y);
1284  }
1285 
1286  //! Computes the value of base raised to the power exp.
1287  //!
1288  //! Valid real arguments for base are non-negative. For other values
1289  //! the result may depend on the backend and compilation options, will
1290  //! likely be NaN.
1291  //!
1292  //! \tparam T The type of the object specializing Pow.
1293  //! \tparam TBase The base type.
1294  //! \tparam TExp The exponent type.
1295  //! \param pow_ctx The object specializing Pow.
1296  //! \param base The base.
1297  //! \param exp The exponent.
1299  template<typename T, typename TBase, typename TExp>
1300  ALPAKA_FN_HOST_ACC auto pow(T const& pow_ctx, TBase const& base, TExp const& exp)
1301  {
1303  return trait::Pow<ImplementationBase, TBase, TExp>{}(pow_ctx, base, exp);
1304  }
1305 
1306  //! Computes the IEEE remainder of the floating point division operation x/y.
1307  //!
1308  //! \tparam T The type of the object specializing Remainder.
1309  //! \tparam Tx The type of the first argument.
1310  //! \tparam Ty The type of the second argument.
1311  //! \param remainder_ctx The object specializing Max.
1312  //! \param x The first argument.
1313  //! \param y The second argument.
1315  template<typename T, typename Tx, typename Ty>
1316  ALPAKA_FN_HOST_ACC auto remainder(T const& remainder_ctx, Tx const& x, Ty const& y)
1317  {
1319  return trait::Remainder<ImplementationBase, Tx, Ty>{}(remainder_ctx, x, y);
1320  }
1321 
1322  //! Computes the nearest integer value to arg (in floating-point format), rounding halfway cases away from
1323  //! zero, regardless of the current rounding mode.
1324  //!
1325  //! \tparam T The type of the object specializing Round.
1326  //! \tparam TArg The arg type.
1327  //! \param round_ctx The object specializing Round.
1328  //! \param arg The arg.
1330  template<typename T, typename TArg>
1331  ALPAKA_FN_HOST_ACC auto round(T const& round_ctx, TArg const& arg)
1332  {
1334  return trait::Round<ImplementationBase, TArg>{}(round_ctx, arg);
1335  }
1336 
1337  //! Computes the nearest integer value to arg (in integer format), rounding halfway cases away from zero,
1338  //! regardless of the current rounding mode.
1339  //!
1340  //! \tparam T The type of the object specializing Round.
1341  //! \tparam TArg The arg type.
1342  //! \param lround_ctx The object specializing Round.
1343  //! \param arg The arg.
1345  template<typename T, typename TArg>
1346  ALPAKA_FN_HOST_ACC auto lround(T const& lround_ctx, TArg const& arg) -> long int
1347  {
1349  return trait::Lround<ImplementationBase, TArg>{}(lround_ctx, arg);
1350  }
1351 
1352  //! Computes the nearest integer value to arg (in integer format), rounding halfway cases away from zero,
1353  //! regardless of the current rounding mode.
1354  //!
1355  //! \tparam T The type of the object specializing Round.
1356  //! \tparam TArg The arg type.
1357  //! \param llround_ctx The object specializing Round.
1358  //! \param arg The arg.
1360  template<typename T, typename TArg>
1361  ALPAKA_FN_HOST_ACC auto llround(T const& llround_ctx, TArg const& arg) -> long long int
1362  {
1364  return trait::Llround<ImplementationBase, TArg>{}(llround_ctx, arg);
1365  }
1366 
1367  //! Computes the rsqrt.
1368  //!
1369  //! Valid real arguments are positive. For other values the result
1370  //! may depend on the backend and compilation options, will likely
1371  //! be NaN.
1372  //!
1373  //! \tparam T The type of the object specializing Rsqrt.
1374  //! \tparam TArg The arg type.
1375  //! \param rsqrt_ctx The object specializing Rsqrt.
1376  //! \param arg The arg.
1378  template<typename T, typename TArg>
1379  ALPAKA_FN_HOST_ACC auto rsqrt(T const& rsqrt_ctx, TArg const& arg)
1380  {
1382  return trait::Rsqrt<ImplementationBase, TArg>{}(rsqrt_ctx, arg);
1383  }
1384 
1385  //! Computes the sine (measured in radians).
1386  //!
1387  //! \tparam T The type of the object specializing Sin.
1388  //! \tparam TArg The arg type.
1389  //! \param sin_ctx The object specializing Sin.
1390  //! \param arg The arg.
1392  template<typename T, typename TArg>
1393  ALPAKA_FN_HOST_ACC auto sin(T const& sin_ctx, TArg const& arg)
1394  {
1396  return trait::Sin<ImplementationBase, TArg>{}(sin_ctx, arg);
1397  }
1398 
1399  //! Computes the hyperbolic sine (measured in radians).
1400  //!
1401  //! \tparam T The type of the object specializing Sin.
1402  //! \tparam TArg The arg type.
1403  //! \param sinh_ctx The object specializing Sin.
1404  //! \param arg The arg.
1406  template<typename T, typename TArg>
1407  ALPAKA_FN_HOST_ACC auto sinh(T const& sinh_ctx, TArg const& arg)
1408  {
1410  return trait::Sinh<ImplementationBase, TArg>{}(sinh_ctx, arg);
1411  }
1412 
1413  //! Computes the sine and cosine (measured in radians).
1414  //!
1415  //! \tparam T The type of the object specializing SinCos.
1416  //! \tparam TArg The arg type.
1417  //! \param sincos_ctx The object specializing SinCos.
1418  //! \param arg The arg.
1419  //! \param result_sin result of sine
1420  //! \param result_cos result of cosine
1422  template<typename T, typename TArg>
1423  ALPAKA_FN_HOST_ACC auto sincos(T const& sincos_ctx, TArg const& arg, TArg& result_sin, TArg& result_cos) -> void
1424  {
1426  trait::SinCos<ImplementationBase, TArg>{}(sincos_ctx, arg, result_sin, result_cos);
1427  }
1428 
1429  //! Computes the square root of arg.
1430  //!
1431  //! Valid real arguments are non-negative. For other values the result
1432  //! may depend on the backend and compilation options, will likely
1433  //! be NaN.
1434  //!
1435  //! \tparam T The type of the object specializing Sqrt.
1436  //! \tparam TArg The arg type.
1437  //! \param sqrt_ctx The object specializing Sqrt.
1438  //! \param arg The arg.
1440  template<typename T, typename TArg>
1441  ALPAKA_FN_HOST_ACC auto sqrt(T const& sqrt_ctx, TArg const& arg)
1442  {
1444  return trait::Sqrt<ImplementationBase, TArg>{}(sqrt_ctx, arg);
1445  }
1446 
1447  //! Computes the tangent (measured in radians).
1448  //!
1449  //! \tparam T The type of the object specializing Tan.
1450  //! \tparam TArg The arg type.
1451  //! \param tan_ctx The object specializing Tan.
1452  //! \param arg The arg.
1454  template<typename T, typename TArg>
1455  ALPAKA_FN_HOST_ACC auto tan(T const& tan_ctx, TArg const& arg)
1456  {
1458  return trait::Tan<ImplementationBase, TArg>{}(tan_ctx, arg);
1459  }
1460 
1461  //! Computes the hyperbolic tangent (measured in radians).
1462  //!
1463  //! \tparam T The type of the object specializing Tanh.
1464  //! \tparam TArg The arg type.
1465  //! \param tanh_ctx The object specializing Tanh.
1466  //! \param arg The arg.
1468  template<typename T, typename TArg>
1469  ALPAKA_FN_HOST_ACC auto tanh(T const& tanh_ctx, TArg const& arg)
1470  {
1472  return trait::Tanh<ImplementationBase, TArg>{}(tanh_ctx, arg);
1473  }
1474 
1475  //! Computes the nearest integer not greater in magnitude than arg.
1476  //!
1477  //! \tparam T The type of the object specializing Trunc.
1478  //! \tparam TArg The arg type.
1479  //! \param trunc_ctx The object specializing Trunc.
1480  //! \param arg The arg.
1482  template<typename T, typename TArg>
1483  ALPAKA_FN_HOST_ACC auto trunc(T const& trunc_ctx, TArg const& arg)
1484  {
1486  return trait::Trunc<ImplementationBase, TArg>{}(trunc_ctx, arg);
1487  }
1488 } // namespace alpaka::math
#define ALPAKA_FN_HOST_ACC
Definition: Common.hpp:39
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
Definition: Common.hpp:82
typename detail::ImplementationBaseType< TConcept, TDerived >::type ImplementationBase
Returns the type that implements the given concept in the inheritance hierarchy.
Definition: Concepts.hpp:66
constexpr T ln2_v
Definition: Traits.hpp:83
constexpr double inv_pi
Definition: Traits.hpp:62
constexpr T sqrt2_v
Definition: Traits.hpp:89
constexpr double log10e
Definition: Traits.hpp:60
constexpr T log10e_v
Definition: Traits.hpp:74
constexpr double e
Definition: Traits.hpp:58
constexpr T ln10_v
Definition: Traits.hpp:86
constexpr double ln10
Definition: Traits.hpp:64
constexpr double log2e
Definition: Traits.hpp:59
constexpr double sqrt2
Definition: Traits.hpp:65
constexpr T inv_pi_v
Definition: Traits.hpp:80
constexpr T pi_v
Definition: Traits.hpp:77
constexpr double ln2
Definition: Traits.hpp:63
constexpr double pi
Definition: Traits.hpp:61
constexpr T log2e_v
Definition: Traits.hpp:71
ALPAKA_FN_HOST_ACC auto sincos(TArg const &arg, TArg &result_sin, TArg &result_cos)
Fallback implementation when no better ADL match was found.
Definition: Traits.hpp:780
ALPAKA_FN_HOST_ACC auto rsqrt(TArg const &arg)
Fallback implementation when no better ADL match was found.
Definition: Traits.hpp:729
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto tanh(T const &tanh_ctx, TArg const &arg)
Computes the hyperbolic tangent (measured in radians).
Definition: Traits.hpp:1469
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto cosh(T const &cosh_ctx, TArg const &arg)
Computes the hyperbolic cosine (measured in radians).
Definition: Traits.hpp:1074
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto pow(T const &pow_ctx, TBase const &base, TExp const &exp)
Computes the value of base raised to the power exp.
Definition: Traits.hpp:1300
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto max(T const &max_ctx, Tx const &x, Ty const &y)
Returns the larger of two arguments. NaNs are treated as missing data (between a NaN and a numeric va...
Definition: Traits.hpp:1263
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto sqrt(T const &sqrt_ctx, TArg const &arg)
Computes the square root of arg.
Definition: Traits.hpp:1441
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto atan(T const &atan_ctx, TArg const &arg)
Computes the principal value of the arc tangent.
Definition: Traits.hpp:955
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto floor(T const &floor_ctx, TArg const &arg)
Computes the largest integer value not greater than arg.
Definition: Traits.hpp:1116
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto asin(T const &asin_ctx, TArg const &arg)
Computes the principal value of the arc sine.
Definition: Traits.hpp:929
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto exp(T const &exp_ctx, TArg const &arg)
Computes the e (Euler's number, 2.7182818) raised to the given power arg.
Definition: Traits.hpp:1102
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto isfinite(T const &ctx, TArg const &arg)
Checks if given value is finite.
Definition: Traits.hpp:1164
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto cos(T const &cos_ctx, TArg const &arg)
Computes the cosine (measured in radians).
Definition: Traits.hpp:1060
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto acos(T const &acos_ctx, TArg const &arg)
Computes the principal value of the arc cosine.
Definition: Traits.hpp:881
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto acosh(T const &acosh_ctx, TArg const &arg)
Computes the principal value of the hyperbolic arc cosine.
Definition: Traits.hpp:898
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto log10(T const &log10_ctx, TArg const &arg)
Computes the the natural (base 10) logarithm of arg.
Definition: Traits.hpp:1246
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto conj(T const &conj_ctx, TArg const &arg)
Computes the complex conjugate of arg.
Definition: Traits.hpp:1030
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto llround(T const &llround_ctx, TArg const &arg) -> long long int
Computes the nearest integer value to arg (in integer format), rounding halfway cases away from zero,...
Definition: Traits.hpp:1361
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto fmod(T const &fmod_ctx, Tx const &x, Ty const &y)
Computes the floating-point remainder of the division operation x/y.
Definition: Traits.hpp:1150
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto asinh(T const &asinh_ctx, TArg const &arg)
Computes the principal value of the hyperbolic arc sine.
Definition: Traits.hpp:942
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto log2(T const &log2_ctx, TArg const &arg)
Computes the the natural (base 2) logarithm of arg.
Definition: Traits.hpp:1228
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto trunc(T const &trunc_ctx, TArg const &arg)
Computes the nearest integer not greater in magnitude than arg.
Definition: Traits.hpp:1483
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto tan(T const &tan_ctx, TArg const &arg)
Computes the tangent (measured in radians).
Definition: Traits.hpp:1455
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto copysign(T const &copysign_ctx, TMag const &mag, TSgn const &sgn)
Creates a value with the magnitude of mag and the sign of sgn.
Definition: Traits.hpp:1046
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto isinf(T const &ctx, TArg const &arg)
Checks if given value is inf.
Definition: Traits.hpp:1178
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto atanh(T const &atanh_ctx, TArg const &arg)
Computes the principal value of the hyperbolic arc tangent.
Definition: Traits.hpp:972
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto ceil(T const &ceil_ctx, TArg const &arg)
Computes the smallest integer value not less than arg.
Definition: Traits.hpp:1016
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto lround(T const &lround_ctx, TArg const &arg) -> long int
Computes the nearest integer value to arg (in integer format), rounding halfway cases away from zero,...
Definition: Traits.hpp:1346
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto sincos(T const &sincos_ctx, TArg const &arg, TArg &result_sin, TArg &result_cos) -> void
Computes the sine and cosine (measured in radians).
Definition: Traits.hpp:1423
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto fma(T const &fma_ctx, Tx const &x, Ty const &y, Tz const &z)
Computes x * y + z as if to infinite precision and rounded only once to fit the result type.
Definition: Traits.hpp:1134
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto remainder(T const &remainder_ctx, Tx const &x, Ty const &y)
Computes the IEEE remainder of the floating point division operation x/y.
Definition: Traits.hpp:1316
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto isnan(T const &ctx, TArg const &arg)
Checks if given value is NaN.
Definition: Traits.hpp:1192
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto cbrt(T const &cbrt_ctx, TArg const &arg)
Computes the cbrt.
Definition: Traits.hpp:1002
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto min(T const &min_ctx, Tx const &x, Ty const &y)
Returns the smaller of two arguments. NaNs are treated as missing data (between a NaN and a numeric v...
Definition: Traits.hpp:1280
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto atan2(T const &atan2_ctx, Ty const &y, Tx const &x)
Computes the arc tangent of y/x using the signs of arguments to determine the correct quadrant.
Definition: Traits.hpp:988
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto sin(T const &sin_ctx, TArg const &arg)
Computes the sine (measured in radians).
Definition: Traits.hpp:1393
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto rsqrt(T const &rsqrt_ctx, TArg const &arg)
Computes the rsqrt.
Definition: Traits.hpp:1379
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto sinh(T const &sinh_ctx, TArg const &arg)
Computes the hyperbolic sine (measured in radians).
Definition: Traits.hpp:1407
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto abs(T const &abs_ctx, TArg const &arg)
Computes the absolute value.
Definition: Traits.hpp:864
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto log(T const &log_ctx, TArg const &arg)
Computes the the natural (base e) logarithm of arg.
Definition: Traits.hpp:1210
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto round(T const &round_ctx, TArg const &arg)
Computes the nearest integer value to arg (in floating-point format), rounding halfway cases away fro...
Definition: Traits.hpp:1331
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto arg(T const &arg_ctx, TArgument const &argument)
Computes the complex argument of the value.
Definition: Traits.hpp:912
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto erf(T const &erf_ctx, TArg const &arg)
Computes the error function of arg.
Definition: Traits.hpp:1088
The abs trait.
Definition: Traits.hpp:297
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:298
The acos trait.
Definition: Traits.hpp:310
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:311
The acosh trait.
Definition: Traits.hpp:323
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:324
The arg trait.
Definition: Traits.hpp:336
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto operator()(T const &, TArgument const &argument)
Definition: Traits.hpp:340
The asin trait.
Definition: Traits.hpp:352
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:353
The asin trait.
Definition: Traits.hpp:365
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:366
The atan2 trait.
Definition: Traits.hpp:404
ALPAKA_FN_HOST_ACC auto operator()(T const &, Ty const &y, Tx const &x)
Definition: Traits.hpp:405
The atan trait.
Definition: Traits.hpp:378
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:379
The atanh trait.
Definition: Traits.hpp:391
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:392
The cbrt trait.
Definition: Traits.hpp:417
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:418
The ceil trait.
Definition: Traits.hpp:430
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:431
The conj trait.
Definition: Traits.hpp:443
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:444
The copysign trait.
Definition: Traits.hpp:456
ALPAKA_FN_HOST_ACC auto operator()(T const &, TMag const &mag, TSgn const &sgn)
Definition: Traits.hpp:457
The cos trait.
Definition: Traits.hpp:469
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:470
The cosh trait.
Definition: Traits.hpp:482
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:483
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:495
The exp trait.
Definition: Traits.hpp:507
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:508
The floor trait.
Definition: Traits.hpp:520
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:521
The fma trait.
Definition: Traits.hpp:533
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y, Tz const &z)
Definition: Traits.hpp:534
The fmod trait.
Definition: Traits.hpp:546
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y)
Definition: Traits.hpp:547
The isfinite trait.
Definition: Traits.hpp:559
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:560
The isinf trait.
Definition: Traits.hpp:572
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:573
The isnan trait.
Definition: Traits.hpp:585
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:586
The round trait.
Definition: Traits.hpp:715
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:716
The base 10 log trait.
Definition: Traits.hpp:624
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:625
The bas 2 log trait.
Definition: Traits.hpp:611
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:612
The log trait.
Definition: Traits.hpp:598
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:599
The round trait.
Definition: Traits.hpp:702
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:703
The max trait.
Definition: Traits.hpp:637
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y)
Definition: Traits.hpp:638
The min trait.
Definition: Traits.hpp:650
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y)
Definition: Traits.hpp:651
The pow trait.
Definition: Traits.hpp:663
ALPAKA_FN_HOST_ACC auto operator()(T const &, TBase const &base, TExp const &exp)
Definition: Traits.hpp:664
The remainder trait.
Definition: Traits.hpp:676
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y)
Definition: Traits.hpp:677
The round trait.
Definition: Traits.hpp:689
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:690
The rsqrt trait.
Definition: Traits.hpp:740
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:741
The sincos trait.
Definition: Traits.hpp:793
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg, TArg &result_sin, TArg &result_cos)
Definition: Traits.hpp:794
The sin trait.
Definition: Traits.hpp:753
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:754
The sin trait.
Definition: Traits.hpp:766
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:767
The sqrt trait.
Definition: Traits.hpp:806
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:807
The tan trait.
Definition: Traits.hpp:819
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:820
The tanh trait.
Definition: Traits.hpp:832
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:833
The trunc trait.
Definition: Traits.hpp:845
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition: Traits.hpp:846