|
15 | 15 | #include <cmath> |
16 | 16 | #include <complex> |
17 | 17 | #include <iostream> |
| 18 | +#include <type_traits> |
18 | 19 |
|
19 | 20 | namespace alpaka |
20 | 21 | { |
21 | 22 | //! Implementation of a complex number useable on host and device. |
22 | 23 | //! |
23 | 24 | //! It follows the layout of std::complex and so array-oriented access. |
24 | | - //! Inside the class template implements all methods and operators as std::complex<T>. |
25 | | - //! Additionally, provides an implicit conversion to and from std::complex<T>. |
| 25 | + //! The class template implements all methods and operators as std::complex<T>. |
| 26 | + //! Additionally, it provides an implicit conversion to and from std::complex<T>. |
26 | 27 | //! All methods besides operators << and >> are host-device. |
27 | | - //! Note that it does not provide non-member functions of std::complex besides the operators. |
| 28 | + //! It does not provide non-member functions of std::complex besides the operators. |
28 | 29 | //! Those are provided the same way as alpaka math functions for real numbers. |
29 | 30 | //! |
30 | 31 | //! Note that unlike most of alpaka, this is a concrete type template, and not merely a concept. |
31 | 32 | //! |
32 | | - //! Naming and order of the methods match https://en.cppreference.com/w/cpp/numeric/complex. |
| 33 | + //! Naming and order of the methods match https://en.cppreference.com/w/cpp/numeric/complex in C++17. |
| 34 | + //! Implementation chose to not extend it e.g. by adding constexpr to some places that would get it in C++20. |
| 35 | + //! The motivation is that with internal conversion to std::complex<T> for CPU backends, it would define the common |
| 36 | + //! interface for genetic code anyways. |
| 37 | + //! So it is more clear to have alpaka's interface exactly matching when possible, and not "improving". |
| 38 | + //! \TODO: when switching to C++20, update the interface to match C++20 std::complex<T>. |
33 | 39 | //! |
34 | 40 | //! @tparam T type of the real and imaginary part: float, double, or long double. |
35 | 41 | template<typename T> |
36 | 42 | class Complex |
37 | 43 | { |
38 | 44 | public: |
| 45 | + // Make sure the input type is floating-point |
| 46 | + static_assert(std::is_floating_point_v<T>); |
| 47 | + |
39 | 48 | //! Type of the real and imaginary parts |
40 | 49 | using value_type = T; |
41 | 50 |
|
@@ -307,8 +316,7 @@ namespace alpaka |
307 | 316 | template<typename T> |
308 | 317 | constexpr ALPAKA_FN_HOST_ACC bool operator!=(Complex<T> const& lhs, Complex<T> const& rhs) |
309 | 318 | { |
310 | | - return !math::floatEqualExactNoWarning(lhs.real(), rhs.real()) |
311 | | - || !math::floatEqualExactNoWarning(lhs.imag(), rhs.imag()); |
| 319 | + return !(lhs == rhs); |
312 | 320 | } |
313 | 321 |
|
314 | 322 | //! Inequality of a complex and a real number |
@@ -381,7 +389,7 @@ namespace alpaka |
381 | 389 | return std::acosh(std::complex<T>(x)); |
382 | 390 | } |
383 | 391 |
|
384 | | - //! Host-side arg falling back to std:: implementation |
| 392 | + //! Argument |
385 | 393 | template<typename T> |
386 | 394 | constexpr ALPAKA_FN_HOST T arg(Complex<T> const& x) |
387 | 395 | { |
|
0 commit comments