|
Ublas : |
Subject: Re: [ublas] numeric bindings nrm2 differences
From: Kraus Philipp (philipp.kraus_at_[hidden])
Date: 2011-11-29 12:23:32
Am 29.11.2011 um 16:39 schrieb Thomas Klimpel:
> Kraus Philipp wrote:
>>> double norm2 = boost::numeric::bindings::blas::nrm2( v );
>>> by
>>> double norm2 = norm_2( v );
>>>
>>> and see whether this gives you the expected results.
>>
>> no changing if I use the nrm2 or norm2 call. The values are always wrong.
>> 2.3281 is the wrong value and 1.768592181649873 the correct. The value
>> with norm_2 and nrm2 is equal, but wrong
>
> Very good. This means that the problem is completely unrelated to nrm2, and that the input data to nrm2 is already "wrong". Explanation: "norm_2" is the function provided by uBlas itself, and it definitively has no accuracy problems.
>
> So you should compare the input data to "nrm2" in the Matlab and in the uBlas case. (In the worst case you can save them line by line to two different files and compare these files with a diff-viewer.) When you have established that they are indeed different, you can start investigating why they are different.
Thomas, you do not know how grateful I am :-)
I have create a little example:
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/bindings/ublas/vector.hpp>
#include <boost/numeric/bindings/blas.hpp>
#include <iostream>
namespace ublas = boost::numeric::ublas;
namespace blas = boost::numeric::bindings::blas;
int main(int argc, char* argv[])
{
ublas::vector<double> vec1(2);
ublas::vector<double> vec2(2);
vec1(0) = 0.1062;
vec1(1) = 0.3395;
vec2(0) = 1.579227019958533;
vec2(1) = 1.534907654618793;
ublas::vector<double> vec3 = vec1 - vec2;
std::cout << "blas:\t" << blas::nrm2(vec3) << std::endl;
std::cout << "ublas:\t" << ublas::norm_2(vec3) << std::endl;
return 0;
}
and the Matlab code:
function x= test()
vec1 = [0.1062 0.3395];
vec2 = [1.579227019958533 1.534907654618793];
vec3 = vec1 - vec2;
x = sqrt(vec3 * vec3');
The C++ Code ist build with
g++ text.cpp -I/Developer/opt/Boost/1.48.0/include -I/Developer/opt/Boost/sandbox/numeric_bindings -latlas -lf77blas -lcblas
Matlab result: 1.897052466920491
C++ result: blas: 1.46849
ublas: 1.46849
If I compile it with -D BOOST_NUMERIC_BINDINGS_BLAS_CBLAS flag, I get errors eg:
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:26: error: CBLAS_ORDER does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:31: error: CBLAS_ORDER does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:36: error: CBLAS_TRANSPOSE does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:41: error: CBLAS_TRANSPOSE does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:46: error: CBLAS_TRANSPOSE does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:51: error: CBLAS_UPLO does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:56: error: CBLAS_UPLO does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:61: error: CBLAS_DIAG does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:66: error: CBLAS_DIAG does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:71: error: CBLAS_SIDE does not name a type
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/detail/cblas_option.hpp:76: error: CBLAS_SIDE does not name a type
....
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/level1/asum.hpp: In function float boost::numeric::bindings::blas::detail::asum(int, const float*, int):
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/level1/asum.hpp:64: error: cblas_sasum was not declared in this scope
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/level1/asum.hpp: In function double boost::numeric::bindings::blas::detail::asum(int, const double*, int):
/Developer/opt/Boost/sandbox/numeric_bindings/boost/numeric/bindings/blas/level1/asum.hpp:73: error: cblas_dasum was not declared in this scope
.....
Thanks a lot