Boost logo

Ublas :

From: Karl Meerbergen (Karl.Meerbergen_at_[hidden])
Date: 2006-02-08 11:23:29


On Wednesday 08 February 2006 14:47, Peter Melchior wrote:
> Hello,
>
> On Thu, 2006-01-26 at 15:36 +0100, Karl Meerbergen wrote:
> > All I can say is that the bindings are written for column major matrices.
> > Your matrix is row_major. I do not believe it is sufficient to transpose
> > it, since for a row_major matrix the leading dimension corresponds to the
> > number of columns. Lapack assumes it corresponds to the number of rows.
>
> It should be sufficient. At least this is sufficient when you call fortran
> routine with a ordinary C 2D-array. For sure, the information about the
> ublas matrix dimensions is updated when transposing it.
> The LAPACK routine DGESVD takes both dimensions of the matrix as
> arguments. They should be passed correctly from the bindings.
> So, if I transpose the matrix, and pass LAPACK the correct values for N
> and M, where is the problem?

As I said, in the bindings the leading dimension is the number of columns for
a row major matrix. If you transpose your matrix, you should store it in a
column major matrix and all is fine. If the matrix is square, there is no
problem.

Karl

>
> Peter
>
> > You could pass trans(M) as an argument to lapack. trans(M) creates an
> > object of type matrix_unary2<M,scalar_identity<typename M::value_type> >.
> > There are no bindings for this kind of object. These should be written.
> > This would be the clean way of doing it.
> >
> > Karl
> >
> > On Thursday 26 January 2006 15:17, Peter Melchior wrote:
> > > Hello,
> > >
> > > I want to do a SVD for non-square real matrices.
> > > When I have a Matrix with more columns than rows, I get this runtime
> > > error:
> > > ** On entry to DGESVD parameter number 6 had an illegal value
> > >
> > > When I have a matrix with more rows than columns I get a wrong result
> > > (checked against Mathematica and IDL).
> > > But when using a square matrix, everything works fine.
> > > I'm definitely sure, that the U, S and V matrix have the correct sizes.
> > >
> > > This is the code I use:
> > >
> > > template <class T>
> > > inline void svd(boost::numeric::ublas::matrix<T>& M,
> > > boost::numeric::ublas::matrix<T>& U, boost::numeric::ublas::matrix<T>&
> > > S, boost::numeric::ublas::matrix<T>& Vt) {
> > > // dimensions of matrices
> > > int n = matrix.size1();
> > > int m = matrix.size2();
> > > int length = min(n,m);
> > >
> > > // since LAPACK works on column-major matrices, transpose it.
> > > boost::numeric::ublas::matrix<T> transpose =
> > > boost::numeric::ublas::trans(M);
> > > boost::numeric::ublas::vector<T> s(length);
> > > boost::numeric::bindings::lapack::gesvd('A','A',transpose,s,U,Vt);
> > >
> > > // transpose U and Vt
> > > U = boost::numeric::ublas::trans(U);
> > > Vt = boost::numeric::ublas::trans(Vt);
> > >
> > > // addressing the diagonal elements of S to store singular values
> > >
> > > boost::numeric::ublas::matrix_vector_range<boost::numeric::ublas::matri
> > >x<T>
> > >
> > > > (S, boost::numeric::ublas::range (0, length),
> > >
> > > boost::numeric::ublas::range (0, length)) = s; }
> > >
> > >
> > >
> > > Does anybody have a clue what is going on here?
> > >
> > >
> > > Best regards,
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas

-- 
==============================================
Look at our unique training program and
Register on-line at http://www.fft.be/?id=35
----------------------------------------------
Karl Meerbergen
Free Field Technologies
Axis Park Louvain-la-Neuve
rue Emile Francqui, 1
B-1435 Mont-Saint Guibert - BELGIUM
Company Phone:  +32 10 45 12 26
Company Fax:    +32 10 45 46 26
Mobile Phone:   +32 474 26 66 59
Home Phone:     +32 2 306 38 10
mailto:Karl.Meerbergen_at_[hidden]
http://www.fft.be
==========================================================================================