complex_utils.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #if !defined(C10_INTERNAL_INCLUDE_COMPLEX_REMAINING_H)
  2. #error \
  3. "c10/util/complex_utils.h is not meant to be individually included. Include c10/util/complex.h instead."
  4. #endif
  5. #include <limits>
  6. namespace c10 {
  7. template <typename T>
  8. struct is_complex : public std::false_type {};
  9. template <typename T>
  10. struct is_complex<std::complex<T>> : public std::true_type {};
  11. template <typename T>
  12. struct is_complex<c10::complex<T>> : public std::true_type {};
  13. // Extract double from std::complex<double>; is identity otherwise
  14. // TODO: Write in more idiomatic C++17
  15. template <typename T>
  16. struct scalar_value_type {
  17. using type = T;
  18. };
  19. template <typename T>
  20. struct scalar_value_type<std::complex<T>> {
  21. using type = T;
  22. };
  23. template <typename T>
  24. struct scalar_value_type<c10::complex<T>> {
  25. using type = T;
  26. };
  27. } // namespace c10
  28. namespace std {
  29. template <typename T>
  30. class numeric_limits<c10::complex<T>> : public numeric_limits<T> {};
  31. template <typename T>
  32. bool isnan(const c10::complex<T>& v) {
  33. return std::isnan(v.real()) || std::isnan(v.imag());
  34. }
  35. } // namespace std