Reply to topic

multi precision floatingpoint datatype

nomism
Registered Member
Posts
2
Karma
0
what must be satisfied, that an arbitrary datatype can be used with eigen? i want to use the mpreal type provided by the mpfrc++ wrapper for mpfr, but it seems to be incomplete.

thanks,
simon
User avatar ggael
Moderator
Posts
3447
Karma
19
OS
see http://eigen.tuxfamily.org/dox/Customiz ... ScalarType

once it works for you, please send us the relevant support code such that we can add it on the svn. I think this can be very useful to many other people.
nomism
Registered Member
Posts
2
Karma
0
code straight forward:

Code: Select all
#ifndef MPREALSUPPORT_H
#define MPREALSUPPORT_H

#include
#include

namespace Eigen {

template struct NumTraits
{
  typedef mpfr::mpreal Real;
  typedef mpfr::mpreal FloatingPoint;
  enum {
    IsComplex = 0,
    HasFloatingPoint = 1,
    ReadCost = 1,
    AddCost = 1,
    MulCost = 1
  };
};

}

// the mpfrc++'s type mpreal is defined in the mpfr namespace
// therefore, the following ei_* functions *must* be defined
// in the same namespace
namespace mpfr {

  inline const mpreal& ei_conj(const mpreal& x)  { return x; }
  inline const mpreal& ei_real(const mpreal& x)  { return x; }
  inline mpreal ei_imag(const mpreal&)    { return 0.; }
  inline mpreal ei_abs(const mpreal&  x)  { return fabs(x); }
  inline mpreal ei_abs2(const mpreal& x)  { return x*x; }
  inline mpreal ei_sqrt(const mpreal& x)  { return sqrt(x); }
  inline mpreal ei_exp(const mpreal&  x)  { return exp(x); }
  inline mpreal ei_log(const mpreal&  x)  { return log(x); }
  inline mpreal ei_sin(const mpreal&  x)  { return sin(x); }
  inline mpreal ei_cos(const mpreal&  x)  { return cos(x); }
  inline mpreal ei_pow(const mpreal& x, mpreal y)  { return pow(x, y); }

}

#endif // MPREALSUPPORT_H


seems to work like charm. still testing.

thanks!
__HRB__
Registered Member
Posts
1
Karma
0
I had to add

Code: Select all
inline bool ei_isMuchSmallerThan(const mpreal& a, mpreal& b ){ return false; }


to make matrix-inversion work.

IOformat permanently sets precision(4) which is nonsense. If anything, IO needs to be determined by traits.
JamesHH
Registered Member
Posts
1
Karma
0
I tried to add support to Eigen but did not get very far:

I find that if I use dynamic matrices/vectors, the program crashes as soon as the ~Matrix() destructor is called.

Does anyone have multiprecision working with dynamic matrices?

 
Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], BigaAl, Bing [Bot], dcihon, Google [Bot], Sogou [Bot], sorcerer, stnowell, Yahoo [Bot]