[Trilinos-Users] Possible Epetra_SerialDenseSVD bug?

Bertagna, Luca lbertag at emory.edu
Mon Mar 11 15:39:10 MDT 2013


Hi all,

I was doing some tests with some Epetra_SerialDenseMatricx, using Epetra_SerialDenseSVD to compute their SVD decomposition. If the matrix is square, no problem, everything works fine; but in the case of a rectangular matrix I kept getting an error from GESVD, saying that one parameter was not valid. Looking over the code, I ran into this piece:

  if(U_==0)
  {
    U_ = new double[M_*N_];
    S_ = new double[M_];
    Vt_ = new double[M_*N_];
  }
  else //zero them out
  {
    for( int i = 0; i < M_; ++i ) S_[i]=0.0;
    for( int i = 0; i < M_*N_; ++i )
    {
      U_[i]=0.0;
      Vt_[i]=0.0;
    }
  }

where M_ is the row dimension of A and N_ the col dimension of A. Then there is the call

  GESVD( job, job, M_, N_, tempMat.A(), LDA_, S_, U_, N_, Vt_, M_, work, &lwork, &INFO_ );

where the signature of GESVD is

GESVD(const char JOBU, const char JOBVT, const int M, const int N, double * A,
              const int LDA, double * S, double * U,
              const int LDU, double * VT, const int LDVT, double * WORK,
              const int * LWORK, int * INFO)

and the invalid parameter i kept getting was the 9th (LDU). Here it looks like U is a N_xM_ matrix (its leading dimension is passed as N_), Vt an M_xN_ matrix (its leading dimension is passed as M_) and S has length M_. I believe the sizes of these matrices are wrong and in particular they should be

U: M_xM_ (square, with dimension equal to row dimension of A)
Vt: N_xN_ (square, with dimension equal to col dimension of A)
S: min (M_,N_) (cause at most we have min(m,n) singular values)

I did these changes and then the SVD started to work again also for rectangular matrices.

I'm not sure I 100% understood how Epetra_SerialDenseSVD and Epetra_SerialDenseMatrix work, but I have the feeling that something is badly dimensioned there and the sizes here above should be the correct ones. Am I right?

Thanks for your help!
----
Luca Bertagna
Math&CS, Emory University, Atlanta
www.mathcs.emory.edu/~lbertag




More information about the Trilinos-Users mailing list