Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

SVD Wrong answer.

ysyoo
Beginner
480 Views
Hi.
I'm using MKL 6.1 on VC++.
When I use SVD(singular value decomposion) in MKL with function "dgebrd",
I get the wrong answer.
Source code is like this.
#include
#include "include/mkl_lapack.h"
#include "include/mkl_example.h"
#define M 4
#define N 3
int main() {
CBLAS_ORDER order = CblasColMajor;
int m = M;
int n = N;
double aTrans[M*N] = { 1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12 };

int lda = m;
double work[64*(M+N)];
int lwork = 64*(M+N);
double q;
double p;
double d;
double e[N-1];
int info;
PrintArrayD(&order, 0, 0, &m, &n, aTrans, &m, "a");
//SVD
dgebrd ( &m, &n, aTrans, &lda,
d, e, q, p, work, &lwork, &info );
if (info !=0) {
printf("Error : %d", info);
return(info);
}
int one=1;
int nminusone=n-1;
PrintArrayD(&order, 1, 0, &m, &n, aTrans, &lda, "a");
PrintArrayD(&order, 1, 0, &one, &n, d, &n, "d");
PrintArrayD(&order, 1, 0, &one, &nminusone, e, &nminusone, "e");
PrintArrayD(&order, 1, 0, &one, &one, work, &one, "work");
return 1;
}
Sigular value calculate by MATLAB is
25.4368 1.7226 0.0000
But,the solution of MKL is
-5.477 1.537 1.183
Why do I get the wrong answer?

0 Kudos
1 Reply
Todd_R_Intel
Employee
480 Views

The function dgebrd reduces a general matrix to bidiagonal form. The function bdsqr computes the singular value decomposition of a general matrix that has been reduced to bidiagonal form. So you are not getting what you expect because you are only doing half the problem. You've reduced the general matrix to bidiagonal form, but not yet called bdsqr to compute the SVD.

I believe that dgesvd function will do all this workfor you in one function call.

-Todd

0 Kudos
Reply