Update complex from thrust master branch
MODIFY
thrust/detail/complex/complex.inl
thrust/detail/complex/complex.inl
#include <thrust/complex.h>
+// TODO: Uncomment after the thrust update
+//#include <thrust/type_traits/is_trivially_relocatable.h>
+
namespace thrust
{
/* --- Constructors --- */
+#if THRUST_CPP_DIALECT < 2011
template <typename T>
__host__ __device__
complex<T>::complex()
-#if __cplusplus >= 201103L
- // Initialize the storage in the member initializer list using C++ unicorn
- // initialization. This allows `complex<T const>` to work.
- // We do a functional-style cast here to suppress conversion warnings.
- : data{T(), T()}
-{}
-#else
{
real(T());
imag(T());
@@ -41,7 +38,7 @@ complex<T>::complex()
template <typename T>
__host__ __device__
complex<T>::complex(const T& re)
-#if __cplusplus >= 201103L
+#if THRUST_CPP_DIALECT >= 2011
// Initialize the storage in the member initializer list using C++ unicorn
// initialization. This allows `complex<T const>` to work.
: data{re, T()}
@@ -53,27 +50,11 @@ complex<T>::complex(const T& re)
}
#endif
-template <typename T>
-template <typename R>
-__host__ __device__
-complex<T>::complex(const R& re)
-#if __cplusplus >= 201103L
- // Initialize the storage in the member initializer list using C++ unicorn
- // initialization. This allows `complex<T const>` to work.
- // We do a functional-style cast here to suppress conversion warnings.
- : data{T(re), T()}
-{}
-#else
-{
- real(T(re));
- imag(T());
-}
-#endif
template <typename T>
__host__ __device__
complex<T>::complex(const T& re, const T& im)
-#if __cplusplus >= 201103L
+#if THRUST_CPP_DIALECT >= 2011
// Initialize the storage in the member initializer list using C++ unicorn
// initialization. This allows `complex<T const>` to work.
: data{re, im}
@@ -85,32 +66,10 @@ complex<T>::complex(const T& re, const T& im)
}
#endif
-template <typename T>
-template <typename R, typename I>
-__host__ __device__
-complex<T>::complex(const R& re, const I& im)
-#if __cplusplus >= 201103L
- // Initialize the storage in the member initializer list using C++ unicorn
- // initialization. This allows `complex<T const>` to work.
- // We do a functional-style cast here to suppress conversion warnings.
- : data{T(re), T(im)}
-{}
-#else
-{
- real(T(re));
- imag(T(im));
-}
-#endif
-
+#if THRUST_CPP_DIALECT < 2011
template <typename T>
__host__ __device__
complex<T>::complex(const complex<T>& z)
-#if __cplusplus >= 201103L
- // Initialize the storage in the member initializer list using C++ unicorn
- // initialization. This allows `complex<T const>` to work.
- : data{z.real(), z.imag()}
-{}
-#else
{
real(z.real());
imag(z.imag());
@@ -121,7 +80,7 @@ template <typename T>
template <typename U>
__host__ __device__
complex<T>::complex(const complex<U>& z)
-#if __cplusplus >= 201103L
+#if THRUST_CPP_DIALECT >= 2011
// Initialize the storage in the member initializer list using C++ unicorn
// initialization. This allows `complex<T const>` to work.
// We do a functional-style cast here to suppress conversion warnings.
@@ -135,34 +94,34 @@ complex<T>::complex(const complex<U>& z)
#endif
template <typename T>
-__host__
+__host__ THRUST_STD_COMPLEX_DEVICE
complex<T>::complex(const std::complex<T>& z)
-#if __cplusplus >= 201103L
+#if THRUST_CPP_DIALECT >= 2011
// Initialize the storage in the member initializer list using C++ unicorn
// initialization. This allows `complex<T const>` to work.
- : data{z.real(), z.imag()}
+ : data{THRUST_STD_COMPLEX_REAL(z), THRUST_STD_COMPLEX_IMAG(z)}
{}
#else
{
- real(z.real());
- imag(z.imag());
+ real(THRUST_STD_COMPLEX_REAL(z));
+ imag(THRUST_STD_COMPLEX_IMAG(z));
}
#endif
template <typename T>
template <typename U>
-__host__
+__host__ THRUST_STD_COMPLEX_DEVICE
complex<T>::complex(const std::complex<U>& z)
-#if __cplusplus >= 201103L
+#if THRUST_CPP_DIALECT >= 2011
// Initialize the storage in the member initializer list using C++ unicorn
// initialization. This allows `complex<T const>` to work.
// We do a functional-style cast here to suppress conversion warnings.
- : data{T(z.real()), T(z.imag())}
+ : data{T(THRUST_STD_COMPLEX_REAL(z)), T(THRUST_STD_COMPLEX_IMAG(z))}
{}
#else
{
- real(T(z.real()));
- imag(T(z.imag()));
+ real(T(THRUST_STD_COMPLEX_REAL(z)));
+ imag(T(THRUST_STD_COMPLEX_IMAG(z)));
}
#endif
@@ -179,23 +138,16 @@ complex<T>& complex<T>::operator=(const T& re)
return *this;
}
+#if THRUST_CPP_DIALECT < 2011
template <typename T>
-template <typename R>
__host__ __device__
-complex<T>& complex<T>::operator=(const R& re)
-{
- real(re);
- imag(T());
- return *this;
-}
-
-template <typename T>
complex<T>& complex<T>::operator=(const complex<T>& z)
{
real(z.real());
imag(z.imag());
return *this;
}
+#endif
template <typename T>
template <typename U>
@@ -208,21 +160,21 @@ complex<T>& complex<T>::operator=(const complex<U>& z)
}
template <typename T>
-__host__
+__host__ THRUST_STD_COMPLEX_DEVICE
complex<T>& complex<T>::operator=(const std::complex<T>& z)
{
- real(z.real());
- imag(z.imag());
+ real(THRUST_STD_COMPLEX_REAL(z));
+ imag(THRUST_STD_COMPLEX_IMAG(z));
return *this;
}
template <typename T>
template <typename U>
-__host__
+__host__ THRUST_STD_COMPLEX_DEVICE
complex<T>& complex<T>::operator=(const std::complex<U>& z)
{
- real(T(z.real()));
- imag(T(z.imag()));
+ real(T(THRUST_STD_COMPLEX_REAL(z)));
+ imag(T(THRUST_STD_COMPLEX_IMAG(z)));
return *this;
}
@@ -314,17 +266,17 @@ bool operator==(const complex<T0>& x, const complex<T1>& y)
}
template <typename T0, typename T1>
-__host__
+__host__ THRUST_STD_COMPLEX_DEVICE
bool operator==(const complex<T0>& x, const std::complex<T1>& y)
{
- return x.real() == y.real() && x.imag() == y.imag();
+ return x.real() == THRUST_STD_COMPLEX_REAL(y) && x.imag() == THRUST_STD_COMPLEX_IMAG(y);
}
template <typename T0, typename T1>
-__host__
+__host__ THRUST_STD_COMPLEX_DEVICE
bool operator==(const std::complex<T0>& x, const complex<T1>& y)
{
- return x.real() == y.real() && x.imag() == y.imag();
+ return THRUST_STD_COMPLEX_REAL(x) == y.real() && THRUST_STD_COMPLEX_IMAG(x) == y.imag();
}
template <typename T0, typename T1>
@@ -349,14 +301,14 @@ bool operator!=(const complex<T0>& x, const complex<T1>& y)
}
template <typename T0, typename T1>
-__host__
+__host__ THRUST_STD_COMPLEX_DEVICE
bool operator!=(const complex<T0>& x, const std::complex<T1>& y)
{
return !(x == y);
}
template <typename T0, typename T1>
-__host__
+__host__ THRUST_STD_COMPLEX_DEVICE
bool operator!=(const std::complex<T0>& x, const complex<T1>& y)
{
return !(x == y);
@@ -376,6 +328,10 @@ bool operator!=(const complex<T0>& x, const T1& y)
return !(x == y);
}
+// TODO: Uncomment after the thrust update
+//template <typename T>
+//struct proclaim_trivially_relocatable<complex<T> > : thrust::true_type {};
+
} // end namespace thrust
#include <thrust/detail/complex/arithmetic.h>

ADD
thrust/detail/config/cpp_dialect.h
+/*
+ * Copyright 2018 NVIDIA Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#if __cplusplus < 201103L
+ #define THRUST_CPP03
+ #define THRUST_CPP_DIALECT 2003
+#elif __cplusplus < 201402L
+ #define THRUST_CPP11
+ #define THRUST_CPP_DIALECT 2011
+#elif __cplusplus < 201703L
+ #define THRUST_CPP14
+ #define THRUST_CPP_DIALECT 2014
+#else
+ #define THRUST_CPP17
+ #define THRUST_CPP_DIALECT 2017
+#endif
+

Update complex from thrust master branch