[eigen] Re: Getting a new number-type to work with Eigen

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I should add that I have read the documentation on extending Eigen with custom 
scalar types. After I do this I am getting the error in resolving a call to 
ei_conj(dd_real&).

My test program compiles when I replace matrix multiplication with addition.

Also, my matrices are real-valued and I am not transposing or conjugating 
either yet the instantiated code seems to succeed in a test for 
conjugate-ness in src/Core/products/GeneralMatrixMatrix.h:75


Thanks,
Manoj


On Tuesday 25 May 2010 03:00:06 pm Manoj Rajagopalan wrote:
> Hi eigen developers,
>
>    What will it take to get a new number-class to work with Eigen?
>
>   I was experimenting with using using the qd library (multicomponent
> quad-double precision numbers), written in C++, to work with Eigen. This
> library provides two new numeric types named dd_real and qd_real and uses
> operator overloading etc. to give quad-double numbers the look and feel of
> primitive types like float and double.
>
>    Since Eigen is templated I figured it might be possible to get it
> running with these number-classes but I have run into one issue.
>
>    I included a modified ei_*() functions for dd_real from
> src/Core/MathFunctions.h into my program and also extended NumTraits for
> dd_real (test program given below) but I keep getting the following error
> message (g++ 4.2.4):
>
> /usr/local/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h:75:
> error: call of overloaded ‘ei_conj(dd_real&)’ is ambiguous
> /usr/local/include/eigen3/Eigen/src/Core/MathFunctions.h:71: note:
> candidates are: int Eigen::ei_conj(int)
> /usr/local/include/eigen3/Eigen/src/Core/MathFunctions.h:124: note:
> float Eigen::ei_conj(float)
> /usr/local/include/eigen3/Eigen/src/Core/MathFunctions.h:171: note:
> double Eigen::ei_conj(double)
> /usr/local/include/eigen3/Eigen/src/Core/MathFunctions.h:293: note:
> long double Eigen::ei_conj(long double)
> /usr/local/include/eigen3/Eigen/src/Core/MathFunctions.h:332: note:
> bool Eigen::ei_conj(bool)
>
>     The templates are not seeing the declaration of the dd_real type and
> the associated NumTraits and ei_****() helpers. My program structures is as
> follows. Could someone help me identify what it will take to get Eigen to
> compile with this new number type?
>
>    I am also attaching dd_real.h but to get any program compiling, you will
> need the full qd library which is available at:
>
>     http://www.cs.berkeley.edu/~yozo/software/qd-2.3.7.tar.gz
>
>    My question above can also be extended to other number class libraries
> like CLN, GMP, MPFR, ARPREC etc. that supply arbitrary-precision numbers.
>
> Thanks,
> Manoj
>
> ...........................................................................
>.....
>
> #include <qd/dd_real.h>
> #include <Eigen/Core>
>
> namespace Eigen {
>
> template<> struct NumTraits<dd_real>
> {
> 	typedef dd_real Real;
> 	typedef dd_real FloatingPoint;
> 	typedef dd_real Nested;
> 	enum {
> 		IsComplex = 0,
> 		HasFloatingPoint = 1,
> 		ReadCost = 2,
> 		AddCost = 2,
> 		MulCost = 7 // guess, for testing
> 	};
> };
>
> // from MathFunctions.h
> /**************
> *** dd_real  ***
> **************/
>
> inline dd_real ei_real(dd_real x)  { return x; }
> inline dd_real& ei_real_ref(dd_real& x)  { return x; }
> inline dd_real ei_imag(dd_real)    { return 0.; }
> inline dd_real ei_conj(dd_real x)  { return x; }
> inline dd_real ei_abs(dd_real x)   { return abs(x); }
> inline dd_real ei_abs2(dd_real x)  { return x*x; }
> inline dd_real ei_norm1(dd_real x) { return ei_abs(x); }
> inline dd_real ei_sqrt(dd_real x)  { return sqrt(x); }
> inline dd_real ei_exp(dd_real x)   { return exp(x); }
> inline dd_real ei_log(dd_real x)   { return log(x); }
> inline dd_real ei_sin(dd_real x)   { return sin(x); }
> inline dd_real ei_cos(dd_real x)   { return cos(x); }
> inline dd_real ei_atan2(dd_real y, dd_real x) { return atan2(y,x); }
> inline dd_real ei_pow(dd_real x, dd_real y) { return pow(x, y); }
>
> } // namespace eigen
>
> // program follows but dies with undeclared ei_conj(dd_real&) error
>
> #include <iostream>
> #include <cstdlib>
>
> using namespace Eigen;
> using namespace std;
>
> typedef Matrix<dd_real,Dynamic,1> dd_real_vector;
> typedef Matrix<dd_real,Dynamic,Dynamic> dd_real_matrix;
>
> int main(void)
> {
> 	int const N = 5;
> 	dd_real_matrix A(N,N), B(N,N), C(N,N);
> 	for(int j=0; j<N; ++j) {
> 		for(int i=0; i<N; ++i) {
> 			A(i,j) = dd_real(drand48());
> 			B(i,j) = dd_real(drand48());
> 		}
> 	}
> 	C = A*B; // <<===== ERROR during template instantiation
> 	return 0;
> }




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/