aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported
diff options
context:
space:
mode:
authorGravatar Mark Borgerding <mark@borgerding.net>2009-10-22 23:06:19 -0400
committerGravatar Mark Borgerding <mark@borgerding.net>2009-10-22 23:06:19 -0400
commit0167f5ef434eaeee42b9be10b0150b5f0f983b93 (patch)
treec93512ac0ae590c7598a82b2d94c500ae7e45a28 /unsupported
parente3d08443dc272f740447de0147efc69cf7de1c93 (diff)
added inline to many functions
Diffstat (limited to 'unsupported')
-rw-r--r--unsupported/Eigen/Complex61
-rw-r--r--unsupported/test/CMakeLists.txt1
2 files changed, 49 insertions, 13 deletions
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 <typename _NativePtr,typename _PunnedPtr>
+template <typename _NativeData,typename _PunnedData>
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 <typename _NativeData,typename _PunnedData>
+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 <typename T>
@@ -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<class X>
@@ -58,40 +71,63 @@ struct Complex
template<class X>
Complex(const std::complex<X>&other): _re(other.real()) ,_im(other.imag()) {}
-
// allow binary access to the object as a std::complex
- typedef castable_pointer< Complex<T>*, StandardComplex* > pointer_type;
- typedef castable_pointer< const Complex<T>*, const StandardComplex* > const_pointer_type;
+ typedef castable_pointer< Complex<T>, StandardComplex > pointer_type;
+ typedef const_castable_pointer< Complex<T>, 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<const StandardComplex*>(this);}
+
+ inline
StandardComplex & std_type() {return *reinterpret_cast<StandardComplex*>(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<T>& operator= (const T& val) { _re=val;_im=0;return *this; }
+ inline
Complex<T>& operator+= (const T& val) {_re+=val;return *this;}
+ inline
Complex<T>& operator-= (const T& val) {_re-=val;return *this;}
+ inline
Complex<T>& operator*= (const T& val) {_re*=val;_im*=val;return *this; }
+ inline
Complex<T>& 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<class X> Complex<T>& operator= (const Complex<X>& rhs) { _re=rhs._re;_im=rhs._im;return *this;}
@@ -105,8 +141,7 @@ struct Complex
T _im;
};
-template <typename T>
-T ei_to_std( const T & x) {return x;}
+//template <typename T> T ei_to_std( const T & x) {return x;}
template <typename T>
std::complex<T> ei_to_std( const Complex<T> & x) {return x.std_type();}
@@ -165,7 +200,7 @@ operator<< (std::basic_ostream<charT,traits>& ostr, const Complex<T>& rhs)
template<class T> Complex<T> log (const Complex<T>&x){return log(ei_to_std(x));}
template<class T> Complex<T> log10 (const Complex<T>&x){return log10(ei_to_std(x));}
- template<class T> Complex<T> pow(const Complex<T>&x, int p) {return pow(ei_to_std(x),ei_to_std(p));}
+ template<class T> Complex<T> pow(const Complex<T>&x, int p) {return pow(ei_to_std(x),p);}
template<class T> Complex<T> pow(const Complex<T>&x, const T&p) {return pow(ei_to_std(x),ei_to_std(p));}
template<class T> Complex<T> pow(const Complex<T>&x, const Complex<T>&p) {return pow(ei_to_std(x),ei_to_std(p));}
template<class T> Complex<T> pow(const T&x, const Complex<T>&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)