I'd like to use the variable-precision mpfr_float type offered by the Boost.Multiprecision library, with the templated Eigen linear algebra library. I observe that if I make an identity matrix created with dynamically-allocated variable-precision mpfr_floats, and multiply it against itself, every other row is populated with nan's. Here is some code:
int main(){
int size = 9;
typedef boost::multiprecision::mpfr_float_backend<0, boost::multiprecision::allocate_dynamic> mybackend;
typedef boost::multiprecision::number<mybackend, boost::multiprecision::et_on> mynumtype;
typedef Eigen::Matrix<mynumtype, Eigen::Dynamic, Eigen::Dynamic> mp_matrix;
mp_matrix A = mp_matrix::Identity(size, size);
mp_matrix B = A*A;
std::cout << B << std::endl;
return 0;
}
output:
1 0 0 0 0 0 0 0 0
nan nan nan nan nan nan nan nan nan
0 0 1 0 0 0 0 0 0
nan nan nan nan nan nan nan nan nan
0 0 0 0 1 0 0 0 0
nan nan nan nan nan nan nan nan nan
0 0 0 0 0 0 1 0 0
nan nan nan nan nan nan nan nan nan
nan nan nan nan nan nan nan nan nan
I have been able to pin it down to the allocate_dynamic switch; if I select allocate_stack, the product computes correctly; allocate_dynamic reliably generates nans. Fixed-precision numbers work just fine, and expression templates on/off make no difference. I'd like to use the dynamic allocation, as I expect to use thousands of digits at times.
I am using clang++, with c++11, on OSX, Boost 1.57.0, Eigen 3.2.4. Same behaviour in 1.56 / 3.2.3.
It seems like maybe an offset issue, but I just can't get there by myself. I've also played with defining the NumTraits in Eigen various ways, but nothing affects the nan behaviour. Does anyone have any ideas?
Daniel Brake
Postdoctoral Research Scholar
University of Notre Dame