#pragma once #include #include #include #include // std functions // // The implementation of these functions also follow the design of C++20 namespace std { template constexpr T real(const c10::complex& z) { return z.real(); } template constexpr T imag(const c10::complex& z) { return z.imag(); } template C10_HOST_DEVICE T abs(const c10::complex& z) { #if defined(__CUDACC__) || defined(__HIPCC__) return thrust::abs(static_cast>(z)); #else return std::abs(static_cast>(z)); #endif } #if defined(USE_ROCM) #define ROCm_Bug(x) #else #define ROCm_Bug(x) x #endif template C10_HOST_DEVICE T arg(const c10::complex& z) { return ROCm_Bug(std)::atan2(std::imag(z), std::real(z)); } #undef ROCm_Bug template constexpr T norm(const c10::complex& z) { return z.real() * z.real() + z.imag() * z.imag(); } // For std::conj, there are other versions of it: // constexpr std::complex conj( float z ); // template< class DoubleOrInteger > // constexpr std::complex conj( DoubleOrInteger z ); // constexpr std::complex conj( long double z ); // These are not implemented // TODO(@zasdfgbnm): implement them as c10::conj template constexpr c10::complex conj(const c10::complex& z) { return c10::complex(z.real(), -z.imag()); } // Thrust does not have complex --> complex version of thrust::proj, // so this function is not implemented at c10 right now. // TODO(@zasdfgbnm): implement it by ourselves // There is no c10 version of std::polar, because std::polar always // returns std::complex. Use c10::polar instead; } // namespace std #define C10_INTERNAL_INCLUDE_COMPLEX_REMAINING_H // math functions are included in a separate file #include // IWYU pragma: keep // utilities for complex types #include // IWYU pragma: keep #undef C10_INTERNAL_INCLUDE_COMPLEX_REMAINING_H