2 Replies Latest reply on Aug 8, 2011 3:27 PM by csmith

    dgesvd - errors in solution

    csmith

      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.

        • dgesvd - errors in solution
          chipf

          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?

            • dgesvd - errors in solution
              csmith

              Here's a sample example of the function call I'm making.  I'm calling the ACML 4.4.0 version of the libraries.

              CS

              double[,] trial = new double[2,2] { { -4.0, 2.0 } , {3.0, -5.0 } }; var info = new IntPtr(); double[,] u = new double[2,2]; double[,] v = new double[2,2]; double[] s = new double[2]{0.0, 0.0}; int n = 2; ACML.ACMLCalls.dgesvd('A', 'A', n, n, trial, n, s, u, n, v, n, ref info); // located in ACML.ACMLCalls [DllImport(DllName32, EntryPoint = "dgesvd", CharSet = CharSet.Ansi)] private static extern void dgesvd32(char jobu, char jobvt, int m, int n, double[,] a, int lda, double[] sing, double[,] u, int ldu, double[,] vt, int ldvt, ref IntPtr info); public static void dgesvd(char jobu, char jobvt, int m, int n, double[,] a, int lda, double[] sing, double[,] u, int ldu, double[,] vt, int ldvt, ref IntPtr info) { dgesvd32(jobu, jobvt, m, n, a, lda, sing, u, ldu, vt, ldvt, ref info); }