diff --git a/bench/benchFFT.cpp b/bench/benchFFT.cpp index 4b6cabb55..fccc02a6c 100644 --- a/bench/benchFFT.cpp +++ b/bench/benchFFT.cpp @@ -26,9 +26,6 @@ #include #include #include -#ifdef USE_FFTW -#include -#endif #include diff --git a/unsupported/Eigen/Complex b/unsupported/Eigen/Complex index e1c41ab38..065c0305d 100644 --- a/unsupported/Eigen/Complex +++ b/unsupported/Eigen/Complex @@ -33,14 +33,26 @@ namespace Eigen { -template +template struct castable_pointer { - castable_pointer(_NativePtr ptr) : _ptr(ptr) {} - operator _NativePtr () {return _ptr;} - operator _PunnedPtr () {return reinterpret_cast<_PunnedPtr>(_ptr);} + castable_pointer(_NativeData * ptr) : _ptr(ptr) { } + operator _NativeData * () {return _ptr;} + operator _PunnedData * () {return reinterpret_cast<_PunnedData*>(_ptr);} + operator const _NativeData * () const {return _ptr;} + operator const _PunnedData * () const {return reinterpret_cast<_PunnedData*>(_ptr);} private: - _NativePtr _ptr; + _NativeData * _ptr; +}; + +template +struct const_castable_pointer +{ + const_castable_pointer(_NativeData * ptr) : _ptr(ptr) { } + operator const _NativeData * () const {return _ptr;} + operator const _PunnedData * () const {return reinterpret_cast<_PunnedData*>(_ptr);} + private: + _NativeData * _ptr; }; template @@ -50,7 +62,8 @@ struct Complex typedef T value_type; // constructors - Complex(const T& re = T(), const T& im = T()) : _re(re),_im(im) { } + Complex() {} + Complex(const T& re, const T& im = T()) : _re(re),_im(im) { } Complex(const Complex&other ): _re(other.real()) ,_im(other.imag()) {} template @@ -58,40 +71,63 @@ struct Complex template Complex(const std::complex&other): _re(other.real()) ,_im(other.imag()) {} - // allow binary access to the object as a std::complex - typedef castable_pointer< Complex*, StandardComplex* > pointer_type; - typedef castable_pointer< const Complex*, const StandardComplex* > const_pointer_type; + typedef castable_pointer< Complex, StandardComplex > pointer_type; + typedef const_castable_pointer< Complex, StandardComplex > const_pointer_type; + + inline pointer_type operator & () {return pointer_type(this);} + + inline const_pointer_type operator & () const {return const_pointer_type(this);} + inline operator StandardComplex () const {return std_type();} + inline operator StandardComplex & () {return std_type();} - StandardComplex std_type() const {return StandardComplex(real(),imag());} + inline + const StandardComplex & std_type() const {return *reinterpret_cast(this);} + + inline StandardComplex & std_type() {return *reinterpret_cast(this);} // every sort of accessor and mutator that has ever been in fashion. // For a brief history, search for "std::complex over-encapsulated" // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#387 + inline const T & real() const {return _re;} + inline const T & imag() const {return _im;} + inline T & real() {return _re;} + inline T & imag() {return _im;} + inline T & real(const T & x) {return _re=x;} + inline T & imag(const T & x) {return _im=x;} + inline void set_real(const T & x) {_re = x;} + inline void set_imag(const T & x) {_im = x;} // *** complex member functions: *** + inline Complex& operator= (const T& val) { _re=val;_im=0;return *this; } + inline Complex& operator+= (const T& val) {_re+=val;return *this;} + inline Complex& operator-= (const T& val) {_re-=val;return *this;} + inline Complex& operator*= (const T& val) {_re*=val;_im*=val;return *this; } + inline Complex& operator/= (const T& val) {_re/=val;_im/=val;return *this; } + inline Complex& operator= (const Complex& rhs) {_re=rhs._re;_im=rhs._im;return *this;} + inline Complex& operator= (const StandardComplex& rhs) {_re=rhs.real();_im=rhs.imag();return *this;} template Complex& operator= (const Complex& rhs) { _re=rhs._re;_im=rhs._im;return *this;} @@ -105,8 +141,7 @@ struct Complex T _im; }; -template -T ei_to_std( const T & x) {return x;} +//template T ei_to_std( const T & x) {return x;} template std::complex ei_to_std( const Complex & x) {return x.std_type();} @@ -165,7 +200,7 @@ operator<< (std::basic_ostream& ostr, const Complex& rhs) template Complex log (const Complex&x){return log(ei_to_std(x));} template Complex log10 (const Complex&x){return log10(ei_to_std(x));} - template Complex pow(const Complex&x, int p) {return pow(ei_to_std(x),ei_to_std(p));} + template Complex pow(const Complex&x, int p) {return pow(ei_to_std(x),p);} template Complex pow(const Complex&x, const T&p) {return pow(ei_to_std(x),ei_to_std(p));} template Complex pow(const Complex&x, const Complex&p) {return pow(ei_to_std(x),ei_to_std(p));} template Complex pow(const T&x, const Complex&p) {return pow(ei_to_std(x),ei_to_std(p));} diff --git a/unsupported/test/CMakeLists.txt b/unsupported/test/CMakeLists.txt index d182c9abf..c75d5eb0b 100644 --- a/unsupported/test/CMakeLists.txt +++ b/unsupported/test/CMakeLists.txt @@ -26,3 +26,4 @@ if(FFTW_FOUND) ei_add_test(FFTW "-DEIGEN_FFTW_DEFAULT " "-lfftw3 -lfftw3f -lfftw3l" ) endif(FFTW_FOUND) +ei_add_test(Complex)