1

I'm trying to combine uBLAS' sparse matrices with GMP's multi-precision float numbers. I've reduced my complex source into the following test-case snippet, which for some reason refuses to compile:

#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <gmpxx.h>
#include <iostream>

using namespace std;

int main() {
  namespace ublas = boost::numeric::ublas;

  ublas::mapped_matrix<mpf_class> A(1,1);
  mpf_class f(1, 64);

  A(0,0) = f;
  cout << A(0,0) / 2 << endl;
}

The compilation command is as simple as:

g++ -lgmpxx -lgmp test.cpp
test.cpp: In function 'int main()':
test.cpp:15:20: error: no match for 'operator/' in  boost::numeric::ublas::mapped_matrix<T, L, A>::operator()(boost::numeric::ublas::mapped_matrix<T, L, A>::size_type, boost::numeric::ublas::mapped_matrix<T, L, A>::size_type) [with T = __gmp_expr<__mpf_struct [1], __mpf_struct [1]>; L = boost::numeric::ublas::basic_row_major<>; A = boost::numeric::ublas::map_std<unsigned int, __gmp_expr<__mpf_struct [1], __mpf_struct [1]>, std::allocator<std::pair<const unsigned int, __gmp_expr<__mpf_struct [1], __mpf_struct [1]> > > >; boost::numeric::ublas::mapped_matrix<T, L, A>::reference = boost::numeric::ublas::sparse_matrix_element<boost::numeric::ublas::mapped_matrix<__gmp_expr<__mpf_struct [1], __mpf_struct [1]> > >; boost::numeric::ublas::mapped_matrix<T, L, A>::size_type = unsigned int](0u, 0u) / 2'

From what I understand by GCC's error, the operator() applied to A(0,0) is unable to return a reference to the multi-precision f of type mpf_class, and in turn apply the operator/ between the referenced f and 2. Instead, it seems that uBLAS treats operator/ as an operator of its own, thus being unable to apply operator/ to f

davide
  • 2,082
  • 3
  • 21
  • 30
  • 1
    I wonder if A(0,0) actually returns an `mpf_class` instance... Could you try to print `typeof(A(0,0))`? On the other hand, you might consider going for [boost::multiprecision](http://www.boost.org/doc/libs/1_55_0/libs/multiprecision/doc/html/boost_multiprecision/intro.html) instead of `mpf_class`, since it should be more boost-friendly. – Mihai Todor May 04 '14 at 22:38

0 Answers0