Rename is_complex_t -> is_complex (#39906)

Summary:
`is_complex_t` is a bad name. For example in std, there are `std::is_same` but not `std::is_same_t`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/39906

Reviewed By: mrshenli

Differential Revision: D22665013

Pulled By: anjali411

fbshipit-source-id: 4b71745f5e2ea2d8cf5845d95ada4556c87e040d
This commit is contained in:
Xiang Gao
2020-09-01 20:40:24 -07:00
committed by Facebook GitHub Bot
parent 9db90fe1f3
commit 263412e536
8 changed files with 38 additions and 38 deletions

View File

@ -34,7 +34,7 @@ inline C10_HOST_DEVICE bool _isnan(T val) {
} }
template <typename T, template <typename T,
typename std::enable_if<c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<c10::is_complex<T>::value, int>::type = 0>
inline bool _isnan(T val) { inline bool _isnan(T val) {
return std::isnan(val.real()) || std::isnan(val.imag()); return std::isnan(val.real()) || std::isnan(val.imag());
} }

View File

@ -216,7 +216,7 @@ public:
return ret; return ret;
} }
template <typename other_t_abs = T, template <typename other_t_abs = T,
typename std::enable_if<!is_floating_point<other_t_abs>::value && !c10::is_complex_t<other_t_abs>::value, int>::type = 0> typename std::enable_if<!is_floating_point<other_t_abs>::value && !c10::is_complex<other_t_abs>::value, int>::type = 0>
Vec256<T> abs() const { Vec256<T> abs() const {
// other_t_abs is for SFINAE and clarity. Make sure it is not changed. // other_t_abs is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<other_t_abs, T>::value, "other_t_abs must be T"); static_assert(std::is_same<other_t_abs, T>::value, "other_t_abs must be T");
@ -232,7 +232,7 @@ public:
return map([](T x) -> T { return std::abs(x); }); return map([](T x) -> T { return std::abs(x); });
} }
template <typename complex_t_abs = T, template <typename complex_t_abs = T,
typename std::enable_if<c10::is_complex_t<complex_t_abs>::value, int>::type = 0> typename std::enable_if<c10::is_complex<complex_t_abs>::value, int>::type = 0>
Vec256<T> abs() const { Vec256<T> abs() const {
// complex_t_abs is for SFINAE and clarity. Make sure it is not changed. // complex_t_abs is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<complex_t_abs, T>::value, "complex_t_abs must be T"); static_assert(std::is_same<complex_t_abs, T>::value, "complex_t_abs must be T");
@ -240,56 +240,56 @@ public:
return map([](T x) { return static_cast<T>(std::abs(x)); }); return map([](T x) { return static_cast<T>(std::abs(x)); });
} }
template <typename other_t_angle = T, template <typename other_t_angle = T,
typename std::enable_if<!c10::is_complex_t<other_t_angle>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<other_t_angle>::value, int>::type = 0>
Vec256<T> angle() const { Vec256<T> angle() const {
// other_t_angle is for SFINAE and clarity. Make sure it is not changed. // other_t_angle is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<other_t_angle, T>::value, "other_t_angle must be T"); static_assert(std::is_same<other_t_angle, T>::value, "other_t_angle must be T");
return Vec256(0); return Vec256(0);
} }
template <typename complex_t_angle = T, template <typename complex_t_angle = T,
typename std::enable_if<c10::is_complex_t<complex_t_angle>::value, int>::type = 0> typename std::enable_if<c10::is_complex<complex_t_angle>::value, int>::type = 0>
Vec256<T> angle() const { Vec256<T> angle() const {
// complex_t_angle is for SFINAE and clarity. Make sure it is not changed. // complex_t_angle is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<complex_t_angle, T>::value, "complex_t_angle must be T"); static_assert(std::is_same<complex_t_angle, T>::value, "complex_t_angle must be T");
return map([](T x) { return static_cast<T>(std::arg(x)); }); return map([](T x) { return static_cast<T>(std::arg(x)); });
} }
template <typename other_t_real = T, template <typename other_t_real = T,
typename std::enable_if<!c10::is_complex_t<other_t_real>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<other_t_real>::value, int>::type = 0>
Vec256<T> real() const { Vec256<T> real() const {
// other_t_real is for SFINAE and clarity. Make sure it is not changed. // other_t_real is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<other_t_real, T>::value, "other_t_real must be T"); static_assert(std::is_same<other_t_real, T>::value, "other_t_real must be T");
return *this; return *this;
} }
template <typename complex_t_real = T, template <typename complex_t_real = T,
typename std::enable_if<c10::is_complex_t<complex_t_real>::value, int>::type = 0> typename std::enable_if<c10::is_complex<complex_t_real>::value, int>::type = 0>
Vec256<T> real() const { Vec256<T> real() const {
// complex_t_real is for SFINAE and clarity. Make sure it is not changed. // complex_t_real is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<complex_t_real, T>::value, "complex_t_real must be T"); static_assert(std::is_same<complex_t_real, T>::value, "complex_t_real must be T");
return map([](T x) { return static_cast<T>(x.real()); }); return map([](T x) { return static_cast<T>(x.real()); });
} }
template <typename other_t_imag = T, template <typename other_t_imag = T,
typename std::enable_if<!c10::is_complex_t<other_t_imag>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<other_t_imag>::value, int>::type = 0>
Vec256<T> imag() const { Vec256<T> imag() const {
// other_t_imag is for SFINAE and clarity. Make sure it is not changed. // other_t_imag is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<other_t_imag, T>::value, "other_t_imag must be T"); static_assert(std::is_same<other_t_imag, T>::value, "other_t_imag must be T");
return Vec256(0); return Vec256(0);
} }
template <typename complex_t_imag = T, template <typename complex_t_imag = T,
typename std::enable_if<c10::is_complex_t<complex_t_imag>::value, int>::type = 0> typename std::enable_if<c10::is_complex<complex_t_imag>::value, int>::type = 0>
Vec256<T> imag() const { Vec256<T> imag() const {
// complex_t_imag is for SFINAE and clarity. Make sure it is not changed. // complex_t_imag is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<complex_t_imag, T>::value, "complex_t_imag must be T"); static_assert(std::is_same<complex_t_imag, T>::value, "complex_t_imag must be T");
return map([](T x) { return static_cast<T>(x.imag()); }); return map([](T x) { return static_cast<T>(x.imag()); });
} }
template <typename other_t_conj = T, template <typename other_t_conj = T,
typename std::enable_if<!c10::is_complex_t<other_t_conj>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<other_t_conj>::value, int>::type = 0>
Vec256<T> conj() const { Vec256<T> conj() const {
// other_t_conj is for SFINAE and clarity. Make sure it is not changed. // other_t_conj is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<other_t_conj, T>::value, "other_t_conj must be T"); static_assert(std::is_same<other_t_conj, T>::value, "other_t_conj must be T");
return *this; return *this;
} }
template <typename complex_t_conj = T, template <typename complex_t_conj = T,
typename std::enable_if<c10::is_complex_t<complex_t_conj>::value, int>::type = 0> typename std::enable_if<c10::is_complex<complex_t_conj>::value, int>::type = 0>
Vec256<T> conj() const { Vec256<T> conj() const {
// complex_t_conj is for SFINAE and clarity. Make sure it is not changed. // complex_t_conj is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<complex_t_conj, T>::value, "complex_t_conj must be T"); static_assert(std::is_same<complex_t_conj, T>::value, "complex_t_conj must be T");
@ -351,14 +351,14 @@ public:
return map(std::log1p); return map(std::log1p);
} }
template <typename other_t_log2 = T, template <typename other_t_log2 = T,
typename std::enable_if<!c10::is_complex_t<other_t_log2>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<other_t_log2>::value, int>::type = 0>
Vec256<T> log2() const { Vec256<T> log2() const {
// other_t_log2 is for SFINAE and clarity. Make sure it is not changed. // other_t_log2 is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<other_t_log2, T>::value, "other_t_log2 must be T"); static_assert(std::is_same<other_t_log2, T>::value, "other_t_log2 must be T");
return map(std::log2); return map(std::log2);
} }
template <typename complex_t_log2 = T, template <typename complex_t_log2 = T,
typename std::enable_if<c10::is_complex_t<complex_t_log2>::value, int>::type = 0> typename std::enable_if<c10::is_complex<complex_t_log2>::value, int>::type = 0>
Vec256<T> log2() const { Vec256<T> log2() const {
// complex_t_log2 is for SFINAE and clarity. Make sure it is not changed. // complex_t_log2 is for SFINAE and clarity. Make sure it is not changed.
static_assert(std::is_same<complex_t_log2, T>::value, "complex_t_log2 must be T"); static_assert(std::is_same<complex_t_log2, T>::value, "complex_t_log2 must be T");
@ -522,7 +522,7 @@ template <class T> Vec256<T> inline operator||(
// Implements the IEEE 754 201X `maximum` operation, which propagates NaN if // Implements the IEEE 754 201X `maximum` operation, which propagates NaN if
// either input is a NaN. // either input is a NaN.
template <class T, template <class T,
typename std::enable_if<!c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline maximum(const Vec256<T> &a, const Vec256<T> &b) { Vec256<T> inline maximum(const Vec256<T> &a, const Vec256<T> &b) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {
@ -538,7 +538,7 @@ Vec256<T> inline maximum(const Vec256<T> &a, const Vec256<T> &b) {
} }
template <class T, template <class T,
typename std::enable_if<c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline maximum(const Vec256<T> &a, const Vec256<T> &b) { Vec256<T> inline maximum(const Vec256<T> &a, const Vec256<T> &b) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {
@ -565,7 +565,7 @@ inline T maximum(const T& a, const T& b) {
// Implements the IEEE 754 201X `minimum` operation, which propagates NaN if // Implements the IEEE 754 201X `minimum` operation, which propagates NaN if
// either input is a NaN. // either input is a NaN.
template <class T, template <class T,
typename std::enable_if<!c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline minimum(const Vec256<T> &a, const Vec256<T> &b) { Vec256<T> inline minimum(const Vec256<T> &a, const Vec256<T> &b) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {
@ -581,7 +581,7 @@ Vec256<T> inline minimum(const Vec256<T> &a, const Vec256<T> &b) {
} }
template <class T, template <class T,
typename std::enable_if<c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline minimum(const Vec256<T> &a, const Vec256<T> &b) { Vec256<T> inline minimum(const Vec256<T> &a, const Vec256<T> &b) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {
@ -607,7 +607,7 @@ inline T minimum(const T& a, const T& b) {
// To save BC, it will not propagate NaN based on IEEE 754 201X // To save BC, it will not propagate NaN based on IEEE 754 201X
template <class T, template <class T,
typename std::enable_if<!c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline clamp(const Vec256<T> &a, const Vec256<T> &min_vec, const Vec256<T> &max_vec) { Vec256<T> inline clamp(const Vec256<T> &a, const Vec256<T> &min_vec, const Vec256<T> &max_vec) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {
@ -617,7 +617,7 @@ Vec256<T> inline clamp(const Vec256<T> &a, const Vec256<T> &min_vec, const Vec25
} }
template <class T, template <class T,
typename std::enable_if<c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline clamp(const Vec256<T> &a, const Vec256<T> &min_vec, const Vec256<T> &max_vec) { Vec256<T> inline clamp(const Vec256<T> &a, const Vec256<T> &min_vec, const Vec256<T> &max_vec) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {
@ -627,7 +627,7 @@ Vec256<T> inline clamp(const Vec256<T> &a, const Vec256<T> &min_vec, const Vec25
} }
template <class T, template <class T,
typename std::enable_if<!c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline clamp_max(const Vec256<T> &a, const Vec256<T> &max_vec) { Vec256<T> inline clamp_max(const Vec256<T> &a, const Vec256<T> &max_vec) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {
@ -637,7 +637,7 @@ Vec256<T> inline clamp_max(const Vec256<T> &a, const Vec256<T> &max_vec) {
} }
template <class T, template <class T,
typename std::enable_if<c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline clamp_max(const Vec256<T> &a, const Vec256<T> &max_vec) { Vec256<T> inline clamp_max(const Vec256<T> &a, const Vec256<T> &max_vec) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {
@ -647,7 +647,7 @@ Vec256<T> inline clamp_max(const Vec256<T> &a, const Vec256<T> &max_vec) {
} }
template <class T, template <class T,
typename std::enable_if<!c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<!c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline clamp_min(const Vec256<T> &a, const Vec256<T> &min_vec) { Vec256<T> inline clamp_min(const Vec256<T> &a, const Vec256<T> &min_vec) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {
@ -657,7 +657,7 @@ Vec256<T> inline clamp_min(const Vec256<T> &a, const Vec256<T> &min_vec) {
} }
template <class T, template <class T,
typename std::enable_if<c10::is_complex_t<T>::value, int>::type = 0> typename std::enable_if<c10::is_complex<T>::value, int>::type = 0>
Vec256<T> inline clamp_min(const Vec256<T> &a, const Vec256<T> &min_vec) { Vec256<T> inline clamp_min(const Vec256<T> &a, const Vec256<T> &min_vec) {
Vec256<T> c = Vec256<T>(); Vec256<T> c = Vec256<T>();
for (int i = 0; i != Vec256<T>::size(); i++) { for (int i = 0; i != Vec256<T>::size(); i++) {

View File

@ -183,7 +183,7 @@ inline c10::complex<double> trunc_impl (c10::complex<double> z) {
return c10::complex<double>(std::trunc(z.real()), std::trunc(z.imag())); return c10::complex<double>(std::trunc(z.real()), std::trunc(z.imag()));
} }
template <typename TYPE, std::enable_if_t<!c10::is_complex_t<TYPE>::value, int> = 0> template <typename TYPE, std::enable_if_t<!c10::is_complex<TYPE>::value, int> = 0>
inline TYPE max_impl (TYPE a, TYPE b) { inline TYPE max_impl (TYPE a, TYPE b) {
if (_isnan<TYPE>(a) || _isnan<TYPE>(b)) { if (_isnan<TYPE>(a) || _isnan<TYPE>(b)) {
return std::numeric_limits<TYPE>::quiet_NaN(); return std::numeric_limits<TYPE>::quiet_NaN();
@ -192,7 +192,7 @@ inline TYPE max_impl (TYPE a, TYPE b) {
} }
} }
template <typename TYPE, std::enable_if_t<c10::is_complex_t<TYPE>::value, int> = 0> template <typename TYPE, std::enable_if_t<c10::is_complex<TYPE>::value, int> = 0>
inline TYPE max_impl (TYPE a, TYPE b) { inline TYPE max_impl (TYPE a, TYPE b) {
if (_isnan<TYPE>(a)) { if (_isnan<TYPE>(a)) {
return a; return a;
@ -203,7 +203,7 @@ inline TYPE max_impl (TYPE a, TYPE b) {
} }
} }
template <typename TYPE, std::enable_if_t<!c10::is_complex_t<TYPE>::value, int> = 0> template <typename TYPE, std::enable_if_t<!c10::is_complex<TYPE>::value, int> = 0>
inline TYPE min_impl (TYPE a, TYPE b) { inline TYPE min_impl (TYPE a, TYPE b) {
if (_isnan<TYPE>(a) || _isnan<TYPE>(b)) { if (_isnan<TYPE>(a) || _isnan<TYPE>(b)) {
return std::numeric_limits<TYPE>::quiet_NaN(); return std::numeric_limits<TYPE>::quiet_NaN();
@ -212,7 +212,7 @@ inline TYPE min_impl (TYPE a, TYPE b) {
} }
} }
template <typename TYPE, std::enable_if_t<c10::is_complex_t<TYPE>::value, int> = 0> template <typename TYPE, std::enable_if_t<c10::is_complex<TYPE>::value, int> = 0>
inline TYPE min_impl (TYPE a, TYPE b) { inline TYPE min_impl (TYPE a, TYPE b) {
if (_isnan<TYPE>(a)) { if (_isnan<TYPE>(a)) {
return a; return a;

View File

@ -361,7 +361,7 @@ template <
int num_threads_x, int num_threads_x,
int num_threads_y, int num_threads_y,
class BinaryFunction> class BinaryFunction>
__global__ typename std::enable_if<!c10::is_complex_t<T>::value, void>::type __global__ typename std::enable_if<!c10::is_complex<T>::value, void>::type
tensor_kernel_scan_innermost_dim( tensor_kernel_scan_innermost_dim(
T* tgt_, T* tgt_,
T* src_, T* src_,
@ -381,7 +381,7 @@ template <
int num_threads_x, int num_threads_x,
int num_threads_y, int num_threads_y,
class BinaryFunction> class BinaryFunction>
__global__ typename std::enable_if<c10::is_complex_t<T>::value, void>::type __global__ typename std::enable_if<c10::is_complex<T>::value, void>::type
tensor_kernel_scan_innermost_dim( tensor_kernel_scan_innermost_dim(
T* tgt_, T* tgt_,
T* src_, T* src_,

View File

@ -111,14 +111,14 @@ class C10_API Scalar {
} }
template<typename T, template<typename T,
typename std::enable_if<!std::is_integral<T>::value && !c10::is_complex_t<T>::value, bool>::type* = typename std::enable_if<!std::is_integral<T>::value && !c10::is_complex<T>::value, bool>::type* =
nullptr> nullptr>
Scalar(T vv, bool) : tag(Tag::HAS_d) { Scalar(T vv, bool) : tag(Tag::HAS_d) {
v.d = convert<decltype(v.d), T>(vv); v.d = convert<decltype(v.d), T>(vv);
} }
template<typename T, template<typename T,
typename std::enable_if<c10::is_complex_t<T>::value, bool>::type* = typename std::enable_if<c10::is_complex<T>::value, bool>::type* =
nullptr> nullptr>
Scalar(T vv, bool) : tag(Tag::HAS_z) { Scalar(T vv, bool) : tag(Tag::HAS_z) {
v.z = convert<decltype(v.z), T>(vv); v.z = convert<decltype(v.z), T>(vv);

View File

@ -449,16 +449,16 @@ overflows(From f) {
#endif #endif
template <typename To, typename From> template <typename To, typename From>
typename std::enable_if<is_complex_t<From>::value, bool>::type overflows( typename std::enable_if<is_complex<From>::value, bool>::type overflows(
From f) { From f) {
// casts from complex to real are considered to overflow if the // casts from complex to real are considered to overflow if the
// imaginary component is non-zero // imaginary component is non-zero
if (!is_complex_t<To>::value && f.imag() != 0) { if (!is_complex<To>::value && f.imag() != 0) {
return true; return true;
} }
// Check for overflow componentwise // Check for overflow componentwise
// (Technically, the imag overflow check is guaranteed to be false // (Technically, the imag overflow check is guaranteed to be false
// when !is_complex_t<To>, but any optimizer worth its salt will be // when !is_complex<To>, but any optimizer worth its salt will be
// able to figure it out.) // able to figure it out.)
return overflows< return overflows<
typename scalar_value_type<To>::type, typename scalar_value_type<To>::type,

View File

@ -11,7 +11,7 @@ namespace c10 {
template<typename dest_t, typename src_t> template<typename dest_t, typename src_t>
struct needs_real { struct needs_real {
constexpr static bool value = (is_complex_t<src_t>::value && !is_complex_t<dest_t>::value); constexpr static bool value = (is_complex<src_t>::value && !is_complex<dest_t>::value);
}; };
template<bool, typename src_t> template<bool, typename src_t>

View File

@ -8,13 +8,13 @@
namespace c10 { namespace c10 {
template <typename T> template <typename T>
struct is_complex_t : public std::false_type {}; struct is_complex : public std::false_type {};
template <typename T> template <typename T>
struct is_complex_t<std::complex<T>> : public std::true_type {}; struct is_complex<std::complex<T>> : public std::true_type {};
template <typename T> template <typename T>
struct is_complex_t<c10::complex<T>> : public std::true_type {}; struct is_complex<c10::complex<T>> : public std::true_type {};
// Extract double from std::complex<double>; is identity otherwise // Extract double from std::complex<double>; is identity otherwise