Boost logo

Ublas :

From: Kresimir Fresl (fresl_at_[hidden])
Date: 2005-05-27 01:23:29


Hi Jack,

you wrote:

> I use g++ an got a bunch of errors. I think I m not including proper
> libs or I m not linking the correct libs. Any help is appreciated.

> #include <iostream>
> #include <boost/numeric/bindings/lapack/gesdd.hpp>
> #include<boost/numeric/bindings/traits/ublas_matrix.hpp>
> #include<boost/numeric/bindings/traits/ublas_vector.hpp>
> #include <boost/numeric/ublas/matrix.hpp>
> #include <boost/numeric/ublas/vector.hpp>
> #include "printmatrix.hpp"
>
> using namespace boost::numeric::bindings::lapack;
> using namespace boost::numeric::ublas;
> // using namespace std;
> using namespace print;
> int main () {
>
> matrix<double> A (4,2);

To use Lapack routines your matrices must be column major:

     matrix<double, column_major> A (4,2);

> A(0,0)=2;
> A(0,1)=4;
> A(1,0)=1;
> A(1,1)=3;
> A(2,0)=0;
> A(2,1)=0;
> A(3,0)=0;
> A(3,1)=0;
> print_matrix(A);
>
> matrix<double> U(4,4);
> matrix<double> V(2,2);

     matrix<double, column_major> U (4,4);
     matrix<double, column_major> V (2,2);

> vector<double> S(8);
> gesdd(&A,&S,&U,&V);

There's no need for dereferencing (bindings do it for you ;o):

     gesdd (A, S, U, V);

> // print_matrix(S);
> // print_matrix(U);
> // print_matrix(V);
>
> return 0;
> }

For more info see examples in

     http://tinyurl.com/ccmwa

and docs in

     http://tinyurl.com/6acht

(BTW, I didn't update ublas and bindings on my machine for
some time. I think that in the meantime interface of ublas
slightly changed, so there may be some more errors, but I
hope that this helps.)

Regards,

fres