/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
* Adapted for PyCUDA by Andreas Kloeckner 2009.
*/
#ifndef PYCUDA_COMPLEX_HPP_SEEN
#define PYCUDA_COMPLEX_HPP_SEEN
extern "C++" {
namespace pycuda {
#define _STLP_USE_NO_IOSTREAMS
#define _STLP_DECLSPEC /* empty */
#define _STLP_CLASS_DECLSPEC /* empty */
#define _STLP_FUNCTION_TMPL_PARTIAL_ORDER
#define _STLP_TEMPLATE_NULL template<>
template <class _Tp>
struct complex {
typedef _Tp value_type;
typedef complex<_Tp> _Self;
// Constructors, destructor, assignment operator.
__device__
complex() : _M_re(0), _M_im(0) {}
__device__
complex(const value_type& __x)
: _M_re(__x), _M_im(0) {}
__device__
complex(const value_type& __x, const value_type& __y)
: _M_re(__x), _M_im(__y) {}
__device__
complex(const _Self& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
__device__
_Self& operator=(const _Self& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
__device__
volatile _Self& operator=(const _Self& __z) volatile {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
template <class _Tp2>
__device__
explicit complex(const complex<_Tp2>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
template <class _Tp2>
__device__
_Self& operator=(const complex<_Tp2>& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
template <class _Tp2>
__device__
volatile _Self& operator=(const complex<_Tp2>& __z) volatile {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
// Element access.
__device__
value_type real() const { return _M_re; }
__device__
value_type imag() const { return _M_im; }
__device__
void real(value_type val) { _M_re = val; }
__device__
void imag(value_type val) { _M_im = val; }
// Arithmetic op= operations involving one real argument.
__device__
_Self& operator= (const value_type& __x) {
_M_re = __x;
_M_im = 0;
return *this;
}
__device__
volatile _Self& operator= (const value_type& __x) volatile {
_M_re = __x;
_M_im = 0;
return *this;
}
__device__
_Self& operator+= (const value_type& __x) {
_M_re += __x;
return *this;
}
__device__
_Self& operator-= (const value_type& __x) {
_M_re -= __x;
return *this;
}
__device__
_Self& operator*= (const value_type& __x) {
_M_re *= __x;
_M_im *= __x;
return *this;
}
__device__
_Self& operator/= (const value_type& __x) {
_M_re /= __x;
_M_im /= __x;
return *this;
}
// Arithmetic op= operations involving two complex arguments.
static void __device__ _div(const value_type& __z1_r, const value_type& __z1_i,
const value_type& __z2_r, const value_type& __z2_i,
value_type& __res_r, value_type& __res_i);
static void __device__ _div(const value_type& __z1_r,
const value_type& __z2_r, const value_type& __z2_i,
value_type& __res_r, value_type& __res_i);
template <class _Tp2> __device__ _Self& operator+= (const complex<_Tp2>& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
template <class _Tp2> __device__ _Self& operator-= (const complex<_Tp2>& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
template <class _Tp2> __device__ _Self& operator*= (const complex<_Tp2>& __z) {
value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
template <class _Tp2> __device__ _Self& operator/= (const complex<_Tp2>& __z) {
value_type __r;
value_type __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
__device__
_Self& operator+= (const _Self& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
__device__
_Self& operator-= (const _Self& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
__device__
_Self& operator*= (const _Self& __z) {
value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
__device__
_Self& operator/= (const _Self& __z) {
value_type __r;
value_type __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
// Data members.
value_type _M_re;
value_type _M_im;
};
// Explicit specializations for float, double, long double. The only
// reason for these specializations is to enable automatic conversions
// from complex<float> to complex<double>, and complex<double> to
// complex<long double>.
_STLP_TEMPLATE_NULL
struct _STLP_CLASS_DECLSPEC complex<float> {
typedef float value_type;
typedef complex<float> _Self;
// Constructors, destructor, assignment operator.
__device__ complex(value_type __x = 0.0f, value_type __y = 0.0f)
: _M_re(__x), _M_im(__y) {}
__device__ complex(const complex<float>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
inline explicit __device__ complex(const complex<double>& __z);
// Element access.
value_type __device__ real() const { return _M_re; }
value_type __device__ imag() const { return _M_im; }
void __device__ real(value_type val) { _M_re = val; }
void __device__ imag(value_type val) { _M_im = val; }
// Arithmetic op= operations involving one real argument.
__device__ _Self& operator= (value_type __x) {
_M_re = __x;
_M_im = 0.0f;
return *this;
}
volatile __device__ _Self& operator= (value_type __x) volatile {
_M_re = __x;
_M_im = 0.0f;
return *this;
}
__device__ _Self& operator+= (value_type __x) {
_M_re += __x;
return *this;
}
__device__ _Self& operator-= (value_type __x) {
_M_re -= __x;
return *this;
}
__device__ _Self& operator*= (value_type __x) {
_M_re *= __x;
_M_im *= __x;
return *this;
}
__device__ _Self& operator/= (value_type __x) {
_M_re /= __x;
_M_im /= __x;
return *this;
}
// Arithmetic op= operations involving two complex arguments.
static __device__ void _div(const float& __z1_r, const float& __z1_i,
const float& __z2_r, const float& __z2_i,
float& __res_r, float& __res_i);
static __device__ void _div(const float& __z1_r,
const float& __z2_r, const float& __z2_i,
float& __res_r, float& __res_i);
template <class _Tp2>
__device__
complex<float>& operator=(const complex<_Tp2>& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
template <class _Tp2>
__device__
volatile complex<float>& operator=(const complex<_Tp2>& __z) volatile {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
template <class _Tp2>
__device__
complex<float>& operator+= (const complex<_Tp2>& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
template <class _Tp2>
__device__
complex<float>& operator-= (const complex<_Tp2>& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
template <class _Tp2>
__device__
complex<float>& operator*= (const complex<_Tp2>& __z) {
float __r = _M_re * __z._M_re - _M_im * __z._M_im;
float __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
template <class _Tp2>
__device__
complex<float>& operator/= (const complex<_Tp2>& __z) {
float __r;
float __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
__device__
_Self& operator=(const _Self& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
__device__
volatile _Self& operator=(const _Self& __z) volatile {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
__device__
_Self& operator+= (const _Self& __z) {
_M_re += __z._M_re;
Loading ...