From adb2170eb8df76117ec1f0cd6e7c01a672d1866f Mon Sep 17 00:00:00 2001 From: Mark Borgerding Date: Mon, 18 Jan 2010 19:39:22 -0500 Subject: [PATCH] removed Eigen::Complex class since it offered insufficient advantage over std::complex when sane real,imag structure packing is assumed. for more info see: http://www.cpptalk.net/portable-complex-numbers-between-c-c--vt46432.html --- unsupported/Eigen/Complex | 240 -------------------------------- unsupported/test/CMakeLists.txt | 1 - unsupported/test/Complex.cpp | 78 ----------- 3 files changed, 319 deletions(-) delete mode 100644 unsupported/Eigen/Complex delete mode 100644 unsupported/test/Complex.cpp diff --git a/unsupported/Eigen/Complex b/unsupported/Eigen/Complex deleted file mode 100644 index 1232782ad..000000000 --- a/unsupported/Eigen/Complex +++ /dev/null @@ -1,240 +0,0 @@ -#ifndef EIGEN_COMPLEX_H -#define EIGEN_COMPLEX_H - -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Mark Borgerding mark a borgerding net -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see . - -// Eigen::Complex reuses as much as possible from std::complex -// and allows easy conversion to and from, even at the pointer level. - -/** \ingroup Unsupported_modules - * \defgroup Complex_Module Complex module - * - * \code - * #include - * \endcode - * - * The C++ complex type has some severe limitations that prevent an - * optimal use within Eigen. This (still unsupported) module is an attempt - * to fix this. - */ - -#include - -namespace Eigen { - -template -struct castable_pointer -{ - 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: - _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 -struct Complex -{ - typedef typename std::complex StandardComplex; - typedef T value_type; - - // constructors - Complex() {} - Complex(const T& re, const T& im = T()) : _re(re),_im(im) { } - Complex(const Complex&other ): _re(other.real()) ,_im(other.imag()) {} - - template - Complex(const Complex&other): _re(other.real()) ,_im(other.imag()) {} - 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 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();} - - 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;} - template Complex& operator+= (const Complex& rhs) { _re+=rhs._re;_im+=rhs._im;return *this;} - template Complex& operator-= (const Complex& rhs) { _re-=rhs._re;_im-=rhs._im;return *this;} - template Complex& operator*= (const Complex& rhs) { this->std_type() *= rhs.std_type(); return *this; } - template Complex& operator/= (const Complex& rhs) { this->std_type() /= rhs.std_type(); return *this; } - - private: - T _re; - T _im; -}; - -//template T ei_to_std( const T & x) {return x;} - -template -std::complex ei_to_std( const Complex & x) {return x.std_type();} - -// 26.2.6 operators -template Complex operator+(const Complex& rhs) {return rhs;} -template Complex operator-(const Complex& rhs) {return -ei_to_std(rhs);} - -template Complex operator+(const Complex& lhs, const Complex& rhs) { return ei_to_std(lhs) + ei_to_std(rhs);} -template Complex operator-(const Complex& lhs, const Complex& rhs) { return ei_to_std(lhs) - ei_to_std(rhs);} -template Complex operator*(const Complex& lhs, const Complex& rhs) { return ei_to_std(lhs) * ei_to_std(rhs);} -template Complex operator/(const Complex& lhs, const Complex& rhs) { return ei_to_std(lhs) / ei_to_std(rhs);} -template bool operator==(const Complex& lhs, const Complex& rhs) { return ei_to_std(lhs) == ei_to_std(rhs);} -template bool operator!=(const Complex& lhs, const Complex& rhs) { return ei_to_std(lhs) != ei_to_std(rhs);} - -template Complex operator+(const Complex& lhs, const T& rhs) {return ei_to_std(lhs) + ei_to_std(rhs); } -template Complex operator-(const Complex& lhs, const T& rhs) {return ei_to_std(lhs) - ei_to_std(rhs); } -template Complex operator*(const Complex& lhs, const T& rhs) {return ei_to_std(lhs) * ei_to_std(rhs); } -template Complex operator/(const Complex& lhs, const T& rhs) {return ei_to_std(lhs) / ei_to_std(rhs); } -template bool operator==(const Complex& lhs, const T& rhs) {return ei_to_std(lhs) == ei_to_std(rhs); } -template bool operator!=(const Complex& lhs, const T& rhs) {return ei_to_std(lhs) != ei_to_std(rhs); } - -template Complex operator+(const T& lhs, const Complex& rhs) {return ei_to_std(lhs) + ei_to_std(rhs); } -template Complex operator-(const T& lhs, const Complex& rhs) {return ei_to_std(lhs) - ei_to_std(rhs); } -template Complex operator*(const T& lhs, const Complex& rhs) {return ei_to_std(lhs) * ei_to_std(rhs); } -template Complex operator/(const T& lhs, const Complex& rhs) {return ei_to_std(lhs) / ei_to_std(rhs); } -template bool operator==(const T& lhs, const Complex& rhs) {return ei_to_std(lhs) == ei_to_std(rhs); } -template bool operator!=(const T& lhs, const Complex& rhs) {return ei_to_std(lhs) != ei_to_std(rhs); } - -template -std::basic_istream& - operator>> (std::basic_istream& istr, Complex& rhs) -{ - return istr >> rhs.std_type(); -} - -template -std::basic_ostream& -operator<< (std::basic_ostream& ostr, const Complex& rhs) -{ - return ostr << rhs.std_type(); -} - - // 26.2.7 values: - template T real(const Complex&x) {return real(ei_to_std(x));} - template T abs(const Complex&x) {return abs(ei_to_std(x));} - template T arg(const Complex&x) {return arg(ei_to_std(x));} - template T norm(const Complex&x) {return norm(ei_to_std(x));} - - template Complex conj(const Complex&x) { return conj(ei_to_std(x));} - template Complex polar(const T& x, const T&y) {return polar(ei_to_std(x),ei_to_std(y));} - // 26.2.8 transcendentals: - template Complex cos (const Complex&x){return cos(ei_to_std(x));} - template Complex cosh (const Complex&x){return cosh(ei_to_std(x));} - template Complex exp (const Complex&x){return exp(ei_to_std(x));} - 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),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));} - - template Complex sin (const Complex&x){return sin(ei_to_std(x));} - template Complex sinh (const Complex&x){return sinh(ei_to_std(x));} - template Complex sqrt (const Complex&x){return sqrt(ei_to_std(x));} - template Complex tan (const Complex&x){return tan(ei_to_std(x));} - template Complex tanh (const Complex&x){return tanh(ei_to_std(x));} - - template struct NumTraits > - { - typedef _Real Real; - typedef Complex<_Real> FloatingPoint; - enum { - IsComplex = 1, - HasFloatingPoint = NumTraits::HasFloatingPoint, - ReadCost = 2, - AddCost = 2 * NumTraits::AddCost, - MulCost = 4 * NumTraits::MulCost + 2 * NumTraits::AddCost - }; - }; -} -#endif -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ - diff --git a/unsupported/test/CMakeLists.txt b/unsupported/test/CMakeLists.txt index 339fba7cc..9618a5a56 100644 --- a/unsupported/test/CMakeLists.txt +++ b/unsupported/test/CMakeLists.txt @@ -24,4 +24,3 @@ if(FFTW_FOUND) ei_add_test(FFTW "-DEIGEN_FFTW_DEFAULT " "-lfftw3 -lfftw3f -lfftw3l" ) endif(FFTW_FOUND) -ei_add_test(Complex) diff --git a/unsupported/test/Complex.cpp b/unsupported/test/Complex.cpp deleted file mode 100644 index 9ea91cf42..000000000 --- a/unsupported/test/Complex.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. Eigen itself is part of the KDE project. -// -// Copyright (C) 2009 Mark Borgerding mark a borgerding net -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see . -#ifdef EIGEN_TEST_FUNC -# include "main.h" -#else -# include -# define CALL_SUBTEST(x) x -# define VERIFY(x) x -# define test_Complex main -#endif - -#include -#include - -using namespace std; -using namespace Eigen; - -template -void take_std( std::complex * dst, int n ) -{ - for (int i=0;i(static_cast(i),static_cast(i)); - cout << dst[n-1] << endl; -} - -template -void syntax() -{ - // this works fine - Matrix< Complex, 9, 1> a; - std::complex * pa = &a[0]; - //Complex * pa2 = &a[0]; - take_std( pa,9); - - // this does not work, but I wish it would - // take_std(&a[0];) - // this does - take_std( (std::complex *)&a[0],9); - - // this does not work, but it would be really nice - //vector< Complex > a; - // (on my gcc 4.4.1 ) - // std::vector assumes operator& returns a POD pointer - - // this works fine - Complex b[9]; - std::complex * pb = &b[0]; // this works fine - - take_std( pb,9); -} - -void test_Complex() -{ - CALL_SUBTEST( syntax() ); - CALL_SUBTEST( syntax() ); - CALL_SUBTEST( syntax() ); -}