I'm trying to calculate the svd of a matrix, to no avail.

I'm calling into the ACML libraries using DllImport from C#. My function call is the following:

dgesvd('A', 'A', nr, nc, mm.Values, lda, s, u.Values, ldu, v.Values, ldvt, ref info);

where *.Values is a double[,]. The problem is I don't get the correct solution. So far I've been testing on very simple matrices all of which produce garbage solutions.

Ex: [[-4.0 2.0][3.0 -5.0]]

nr = 2, nc = 2, lda = 2, ldu = 2, ldvt = 2, mm.Values is the above matrix, u and v are empty double[2,2] and s is an empty double[2]

The eigenvalues should be -7 and -2, but I don't see that coming out.

The solution coming out though does have the correct property of A = U*Sigma*Vt, with incorrect values in Sigma. U and Vt contain orthogonal vectors. Any insight would be welcomed into this problem.

Not sure if it will be helpful, but this older post has a C# example for zgemm.

http://forums.amd.com/devforum/messageview.cfm?catid=217&threadid=122614&enterthread=y

Another post asked about sgesvd, they had only provided a single integer for the pivot array, instead of an array of integers. I can't tell from your post is this is happening in your case.

Finally, ACML expects column major fortran matrix ordering, even when using the C interfaces. Can that explain the problem?