<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic proper use of dgesvd? in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/proper-use-of-dgesvd/m-p/820840#M4707</link>
    <description>that's right.&lt;DIV&gt;Benson - please see C based &lt;A href="http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/index.htm"&gt;DGESVD examples&lt;/A&gt;.&lt;/DIV&gt;&lt;DIV&gt;--Gennady&lt;/DIV&gt;</description>
    <pubDate>Sat, 18 Sep 2010 17:41:31 GMT</pubDate>
    <dc:creator>Gennady_F_Intel</dc:creator>
    <dc:date>2010-09-18T17:41:31Z</dc:date>
    <item>
      <title>proper use of dgesvd?</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/proper-use-of-dgesvd/m-p/820838#M4705</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I'm trying to compute an SVD, but I'm not sure if I'm using dgesvd properly. I copied the example code from here:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/dgesvd_ex.c.htm" target="_blank"&gt;http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/dgesvd_ex.c.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;and modified a few things to use the array from Wikipedia to try to verify the numbers (I verified the numbers in Wikipedia with Matlab):&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://en.wikipedia.org/wiki/Singular_value_decomposition#Example" target="_blank"&gt;http://en.wikipedia.org/wiki/Singular_value_decomposition#Example&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Here is the code I used (I note below the code the changes I made):&lt;BR /&gt;&lt;BR /&gt;#define M 5&lt;BR /&gt;#define N 4&lt;BR /&gt;#define LDA M&lt;BR /&gt;#define LDU M&lt;BR /&gt;#define LDVT N&lt;BR /&gt; &lt;BR /&gt;...&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt; int m = M, n = N, lda = LDA, ldu = LDU, ldvt = LDVT, info, lwork;&lt;BR /&gt; double wkopt;&lt;BR /&gt; double* work;&lt;BR /&gt; /* Local arrays */&lt;BR /&gt; double s&lt;N&gt;, u[LDU*M], vt[LDVT*N];&lt;BR /&gt; double a[LDA*N] = {&lt;BR /&gt; 1, 0, 0, 0, 2,&lt;BR /&gt; 0, 0, 3, 0, 0,&lt;BR /&gt; 0, 0, 0, 0, 0,&lt;BR /&gt; 0, 4, 0, 0, 0&lt;BR /&gt; };&lt;BR /&gt; // Executable statements */&lt;BR /&gt; printf( " DGESVD Example Program Results\\n" );&lt;BR /&gt; /* Query and allocate the optimal workspace */&lt;BR /&gt; lwork = -1;&lt;BR /&gt; dgesvd( "All", "All", &amp;amp;m, &amp;amp;n, a, &amp;amp;lda, s, u, &amp;amp;ldu, vt, &amp;amp;ldvt, &amp;amp;wkopt, &amp;amp;lwork,&lt;BR /&gt; &amp;amp;info );&lt;BR /&gt; lwork = (int)wkopt;&lt;BR /&gt; work = (double*)malloc( lwork*sizeof(double) );&lt;BR /&gt; /* Compute SVD */&lt;BR /&gt; dgesvd( "All", "All", &amp;amp;m, &amp;amp;n, a, &amp;amp;lda, s, u, &amp;amp;ldu, vt, &amp;amp;ldvt, work, &amp;amp;lwork,&lt;BR /&gt; &amp;amp;info );&lt;BR /&gt; /* Check for convergence */&lt;BR /&gt; if( info &amp;gt; 0 ) {&lt;BR /&gt; printf( "The algorithm computing SVD failed to converge.\\n" );&lt;BR /&gt; exit( 1 );&lt;BR /&gt; }&lt;BR /&gt; /* Print singular values */&lt;BR /&gt; print_matrix( "Singular values", 1, n, s, 1 );&lt;BR /&gt; /* Print left singular vectors */&lt;BR /&gt; print_matrix( "Left singular vectors (stored columnwise)", m, m, u, ldu );&lt;BR /&gt; /* Print right singular vectors */&lt;BR /&gt; print_matrix( "Right singular vectors (stored rowwise)", n, n, vt, ldvt );&lt;BR /&gt; /* Free workspace */&lt;BR /&gt; free( (void*)work );&lt;BR /&gt;&lt;BR /&gt;CHANGES:&lt;BR /&gt;* I changed the array to be the Wikipedia example&lt;BR /&gt;* I changed the print range of the "Left singular vectors" to be m, m (instead of m, n) [is that an error in the example?]&lt;BR /&gt;* I changed the #define to be M == 5 and N == 4&lt;BR /&gt;&lt;BR /&gt;Here are my results:&lt;BR /&gt;&lt;BR /&gt;Singular values&lt;BR /&gt; 4.00 3.00 2.24 0.00&lt;BR /&gt;&lt;BR /&gt;Left singular vectors (stored columnwise)&lt;BR /&gt; 0.00 0.00 -0.45 0.00 -0.89&lt;BR /&gt; -1.00 0.00 -0.00 0.00 0.00&lt;BR /&gt; 0.00 -1.00 -0.00 0.00 0.00&lt;BR /&gt; -0.00 -0.00 -0.00 1.00 0.00&lt;BR /&gt; 0.00 -0.00 -0.89 -0.00 0.45&lt;BR /&gt;&lt;BR /&gt;Right singular vectors (stored rowwise)&lt;BR /&gt; -0.00 -0.00 -0.00 -1.00&lt;BR /&gt; -0.00 -1.00 0.00 0.00&lt;BR /&gt; -1.00 -0.00 -0.00 -0.00&lt;BR /&gt; -0.00 -0.00 -1.00 0.00&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The singular values are fine. The left and right singular vectors appear to be swapped from U and V on the Wikipedia entry. But here's my main problem: Notice the #define for M and N. The matrix on Wikipedia is a 4 x 5 matrix. The documentation for 'm' and 'n' from:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/cpp/win/mkl/refman/lse/functn_gesvd.html" target="_blank"&gt;http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/cpp/win/mkl/refman/lse/functn_gesvd.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;says:&lt;BR /&gt;&lt;BR /&gt;&lt;DL&gt;&lt;DT class="dlterm"&gt;m INTEGER. The number of rows of the matrix &lt;VAR class="varname"&gt;A&lt;/VAR&gt; (&lt;SAMP class="codeph"&gt;&lt;VAR class="varname"&gt;m&lt;/VAR&gt;  0&lt;/SAMP&gt;). &lt;/DT&gt;&lt;DD&gt;&lt;DL&gt;&lt;DT class="dlterm"&gt;n INTEGER. The number of columns in &lt;VAR class="varname"&gt;A&lt;/VAR&gt; (&lt;SAMP class="codeph"&gt;&lt;VAR class="varname"&gt;n&lt;/VAR&gt; 0&lt;/SAMP&gt;). &lt;/DT&gt;&lt;DD&gt;
&lt;BR /&gt;&lt;/DD&gt;&lt;/DL&gt;&lt;/DD&gt;&lt;DD&gt;
BUT&lt;/DD&gt;&lt;/DL&gt;&lt;BR /&gt;if I put the "right" values for M and N and change the #define to M == 4 and N == 5, then here are my results for the singular values:&lt;BR /&gt;&lt;BR /&gt;Singular values&lt;BR /&gt; 4.85 2.55 0.00 0.00 2.36&lt;BR /&gt;&lt;BR /&gt;(which does not match Wikipedia)&lt;BR /&gt;&lt;BR /&gt;What's going on?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;Benson&lt;BR /&gt;&lt;BR /&gt;&lt;/N&gt;</description>
      <pubDate>Sat, 18 Sep 2010 02:24:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/proper-use-of-dgesvd/m-p/820838#M4705</guid>
      <dc:creator>aicoder</dc:creator>
      <dc:date>2010-09-18T02:24:18Z</dc:date>
    </item>
    <item>
      <title>proper use of dgesvd?</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/proper-use-of-dgesvd/m-p/820839#M4706</link>
      <description>Please read the MKL documentation and observe that Lapack routines with dense matrix arguments (such as xGESVD) expect arrays of rank-2 (and higher, if needed) to be stored in column-major order (Fortran convention) instead of row-major order (C convention).&lt;BR /&gt;&lt;BR /&gt;As a result of the mismatched storage order, you are passing M^T rather than M, and misinterpreting the matrices U and V^T after they are returned to you.</description>
      <pubDate>Sat, 18 Sep 2010 11:42:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/proper-use-of-dgesvd/m-p/820839#M4706</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2010-09-18T11:42:45Z</dc:date>
    </item>
    <item>
      <title>proper use of dgesvd?</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/proper-use-of-dgesvd/m-p/820840#M4707</link>
      <description>that's right.&lt;DIV&gt;Benson - please see C based &lt;A href="http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/index.htm"&gt;DGESVD examples&lt;/A&gt;.&lt;/DIV&gt;&lt;DIV&gt;--Gennady&lt;/DIV&gt;</description>
      <pubDate>Sat, 18 Sep 2010 17:41:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/proper-use-of-dgesvd/m-p/820840#M4707</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2010-09-18T17:41:31Z</dc:date>
    </item>
  </channel>
</rss>

