Re: [eigen] Re: Getting a new number-type to work with Eigen |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Re: Getting a new number-type to work with Eigen
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Tue, 25 May 2010 16:36:09 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=Bzi/UwC+iWx6jJZyPAS5mRMYF4tTJiDO2cUqQZExI7w=; b=IGPv5kaKqqKJep3SaVy3cOyBJ4A0JbqXMbGOQ70n0D8+UsJX1C42HJbmVaDMOFoBEu OTEC9eZ/F+n0IBSgaUlX1scyE8b/ekxbSVSjgcqZeQ2k7BJ0gp7zMvMi+z/OSiT0FCMe ry7z4uC8iOt7u54rjHw5h5so06JNB5kmn/m80=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=Op1/x73aPgunnBnYuxU8sjLTY5dOesoYHF/qYzJv6OjPqbXDS0BEGD/woJjhRkNCmX 49Z1QaJ/Itv04f1jXg/fqJTJRSLiG7/aDBoQmxMpnVeZsoZY+a9tDjvi58VAPQu92NPj v61Mxlxo33CUQvVym275JKTxM0UDy4spKenWA=
Right, In the 2.0 branch, you have to implement conj even if your type
is real. Just implement it as the identity function: conj(x) returns
x.
In the development branch, this should be done automatically for you.
Benoit
2010/5/25 Manoj Rajagopalan <rmanoj@xxxxxxxxx>:
>
> 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;
>> }
>
>
>
>