|
Ublas : |
Subject: Re: [ublas] Floating point exceptions and unexpected call to sqrt with sparse integer vectors
From: Michael Stevens (mail_at_[hidden])
Date: 2009-08-11 07:06:19
Hello Mark
On Monday 10 August 2009, Mark Johnson wrote:
> Thanks Jesse for your answer to my previous question.
>
> A lot of my work involves statistics of sparse vectors of positive
> integers, so it seems ublas sparse vectors and matrices are going to be
> very useful for me.
>
> However, I find that sparse vectors of integers produce strange floating
> point exceptions (they work great with floats and doubles). When I use
> gdb to trace these exceptions I find unexplained calls to sqrt(), even
> though my program doesn't involve sqrt() at all. I'd appreciate any
> advice!
I took a look at this in gdb (with Eclipse CDT as a front end). In your example code the problem is actually due to the use of
'int' as the element type. uBLAS's matrix and vector type are defined only for real types. Even in simple assignments uBLAS checks
(in DEBUG build) the assignment by performing it two different ways and then checking the difference. The difference check has to
be approximate and uses the flowing macro to determine an error bound.
#define BOOST_UBLAS_TYPE_CHECK_MIN (type_traits<real_type>::type_sqrt ( (std::numeric_limits<real_type>::min) ()))
Obviously for 'int' this fails! The definition of numeric_limits::min is different for int and real types which is rather nasty.
You can disable all this checking by either setting
disable_type_check<bool>::value = true;
in you main.
OR
#define BOOST_UBLAS_TYPE_CHECK 0
Hope that helps,
Michael
-- ___________________________________ Michael Stevens Systems Engineering 34128 Kassel, Germany Navigation Systems, Estimation and Bayesian Filtering http://bayesclasses.sf.net ___________________________________