Boost logo

Ublas :

From: Peter Melchior (pmelchior_at_[hidden])
Date: 2006-01-26 09:17:01


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::matrix<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,

-- 
Peter Melchior
Institut fuer Theoretische Astrophysik
Albert-Ueberle-Str. 3-5
69120 Heidelberg, Germany
Mail: pmelchior_at_[hidden]