$include_dir="/home/hyper-archives/ublas/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [ublas] numeric bindings nrm2 differences
From: Bogdan Burlacu (froz3nshade_at_[hidden])
Date: 2011-11-29 18:22:30
On Tue, 29 Nov 2011 18:23:32 +0100
Kraus Philipp <philipp.kraus_at_[hidden]> wrote:
> 
> 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
Hi Philipp, 
I also compiled your example and boost::numeric::ublas computes the
correct result. Using gentoo as well and boost 1.47 (sorry the system
is not so up-to-date). 
Regards,
Bogdan