/* * Copyright 2008-2021 NVIDIA Corporation * Copyright 2013 Filipe RNC Maia * * 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 #include #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) # pragma GCC system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) # pragma clang system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) # pragma system_header #endif // no system header #include #include THRUST_NAMESPACE_BEGIN /* --- Constructors --- */ #if THRUST_CPP_DIALECT < 2011 template __host__ __device__ complex::complex() { real(T()); imag(T()); } #endif template __host__ __device__ complex::complex(const T& re) #if THRUST_CPP_DIALECT >= 2011 // Initialize the storage in the member initializer list using C++ unicorn // initialization. This allows `complex` to work. : data{re, T()} {} #else { real(re); imag(T()); } #endif template __host__ __device__ complex::complex(const T& re, const T& im) #if THRUST_CPP_DIALECT >= 2011 // Initialize the storage in the member initializer list using C++ unicorn // initialization. This allows `complex` to work. : data{re, im} {} #else { real(re); imag(im); } #endif #if THRUST_CPP_DIALECT < 2011 template __host__ __device__ complex::complex(const complex& z) { real(z.real()); imag(z.imag()); } #endif template template __host__ __device__ complex::complex(const complex& z) #if THRUST_CPP_DIALECT >= 2011 // Initialize the storage in the member initializer list using C++ unicorn // initialization. This allows `complex` to work. // We do a functional-style cast here to suppress conversion warnings. : data{T(z.real()), T(z.imag())} {} #else { real(T(z.real())); imag(T(z.imag())); } #endif template __host__ THRUST_STD_COMPLEX_DEVICE complex::complex(const std::complex& z) #if THRUST_CPP_DIALECT >= 2011 // Initialize the storage in the member initializer list using C++ unicorn // initialization. This allows `complex` to work. : data{THRUST_STD_COMPLEX_REAL(z), THRUST_STD_COMPLEX_IMAG(z)} {} #else { real(THRUST_STD_COMPLEX_REAL(z)); imag(THRUST_STD_COMPLEX_IMAG(z)); } #endif template template __host__ THRUST_STD_COMPLEX_DEVICE complex::complex(const std::complex& z) #if THRUST_CPP_DIALECT >= 2011 // Initialize the storage in the member initializer list using C++ unicorn // initialization. This allows `complex` to work. // We do a functional-style cast here to suppress conversion warnings. : data{T(THRUST_STD_COMPLEX_REAL(z)), T(THRUST_STD_COMPLEX_IMAG(z))} {} #else { real(T(THRUST_STD_COMPLEX_REAL(z))); imag(T(THRUST_STD_COMPLEX_IMAG(z))); } #endif /* --- Assignment Operators --- */ template __host__ __device__ complex& complex::operator=(const T& re) { real(re); imag(T()); return *this; } #if THRUST_CPP_DIALECT < 2011 template __host__ __device__ complex& complex::operator=(const complex& z) { real(z.real()); imag(z.imag()); return *this; } #endif template template __host__ __device__ complex& complex::operator=(const complex& z) { real(T(z.real())); imag(T(z.imag())); return *this; } template __host__ THRUST_STD_COMPLEX_DEVICE complex& complex::operator=(const std::complex& z) { real(THRUST_STD_COMPLEX_REAL(z)); imag(THRUST_STD_COMPLEX_IMAG(z)); return *this; } template template __host__ THRUST_STD_COMPLEX_DEVICE complex& complex::operator=(const std::complex& z) { real(T(THRUST_STD_COMPLEX_REAL(z))); imag(T(THRUST_STD_COMPLEX_IMAG(z))); return *this; } /* --- Compound Assignment Operators --- */ template template __host__ __device__ complex& complex::operator+=(const complex& z) { *this = *this + z; return *this; } template template __host__ __device__ complex& complex::operator-=(const complex& z) { *this = *this - z; return *this; } template template __host__ __device__ complex& complex::operator*=(const complex& z) { *this = *this * z; return *this; } template template __host__ __device__ complex& complex::operator/=(const complex& z) { *this = *this / z; return *this; } template template __host__ __device__ complex& complex::operator+=(const U& z) { *this = *this + z; return *this; } template template __host__ __device__ complex& complex::operator-=(const U& z) { *this = *this - z; return *this; } template template __host__ __device__ complex& complex::operator*=(const U& z) { *this = *this * z; return *this; } template template __host__ __device__ complex& complex::operator/=(const U& z) { *this = *this / z; return *this; } /* --- Equality Operators --- */ template __host__ __device__ bool operator==(const complex& x, const complex& y) { return x.real() == y.real() && x.imag() == y.imag(); } template __host__ THRUST_STD_COMPLEX_DEVICE bool operator==(const complex& x, const std::complex& y) { return x.real() == THRUST_STD_COMPLEX_REAL(y) && x.imag() == THRUST_STD_COMPLEX_IMAG(y); } template __host__ THRUST_STD_COMPLEX_DEVICE bool operator==(const std::complex& x, const complex& y) { return THRUST_STD_COMPLEX_REAL(x) == y.real() && THRUST_STD_COMPLEX_IMAG(x) == y.imag(); } template __host__ __device__ bool operator==(const T0& x, const complex& y) { return x == y.real() && y.imag() == T1(); } template __host__ __device__ bool operator==(const complex& x, const T1& y) { return x.real() == y && x.imag() == T1(); } template __host__ __device__ bool operator!=(const complex& x, const complex& y) { return !(x == y); } template __host__ THRUST_STD_COMPLEX_DEVICE bool operator!=(const complex& x, const std::complex& y) { return !(x == y); } template __host__ THRUST_STD_COMPLEX_DEVICE bool operator!=(const std::complex& x, const complex& y) { return !(x == y); } template __host__ __device__ bool operator!=(const T0& x, const complex& y) { return !(x == y); } template __host__ __device__ bool operator!=(const complex& x, const T1& y) { return !(x == y); } template struct proclaim_trivially_relocatable > : thrust::true_type {}; THRUST_NAMESPACE_END #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include