<?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 Re: Looking for SVD example. in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Looking-for-SVD-example/m-p/918158#M12769</link>
    <description>&lt;DIV&gt;There is a very good site &lt;BR /&gt;&lt;A href="http://www.netlib.org/lapack/" target="_blank"&gt;http://www.netlib.org/lapack/&lt;/A&gt;&lt;BR /&gt;where you can find samples and all the information. &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;In fact, your code doesn't solve your problem and the call &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;sorgbr ( "P", &amp;amp;cols, &amp;amp;cols, &amp;amp;rows, a, &amp;amp;lda, taup , work, &amp;amp;worksize, &amp;amp;info );&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;is wrong. This is because SORGBR generatesoneof the real orthogonal matrices Q or P**T determined by SGEBRD when reducing a real matrix A to bidiagonal form: A = Q * B * P**T. Q and P**T are defined as products of&lt;BR /&gt;elementary reflectors H(i) or G(i) respectively. And if you call&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;sgebrd(&amp;amp;rows, &amp;amp;cols,....)&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;then the correct call to sorgbr MUST be the following &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;sorgbr ( "P", &amp;amp;rows, &amp;amp;cols, &amp;amp;k,... &lt;/DIV&gt;
&lt;DIV&gt;&lt;BR /&gt;where k&amp;lt; = rows. &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;It's qite important that you will not obtain the kernel vectors by you using sorgbr becausem &amp;lt; n and according to the sorgbr manual &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;" If VECT = 'P', A is assumed to have been a K-by-N matrix, and P**T&lt;BR /&gt; is of order N:&lt;BR /&gt; if k &amp;lt; n, P**T = G(k) . . . G(2) G(1) and SORGBR returns the first m&lt;BR /&gt; rows of P**T, where n &amp;gt;= m &amp;gt;= k. "&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;This means you can obtain the first m rows of the matrix P**T but the whole P**T can not be obtained, and these m rows form the basis which is the orthogonal compliment to the kernel vectors if rank A=m. &lt;BR /&gt;So your code doesn't produce the kernel vectors.&lt;/DIV&gt;
&lt;DIV&gt;&lt;BR /&gt;There exist several ways to compute the kernel vectors using LAPACK routines. Let's us give an example. For example, it can be done through the LQ decomposition of the initial matrix A. If we have m by n matrix A andm &amp;lt; n, rank A = m, then Q**T Z give us the kernel vectors where Z is cols by n-m matrix which non-zero elements are defined as follows &lt;BR /&gt; a(j+m, j)=1. j=1,... n-m&lt;BR /&gt; &lt;BR /&gt;Then A Z= L Q * (Q**T *Z)= 0. So if you replacethecalls to sgebrd and sorgbr with &lt;/DIV&gt;
&lt;DIV&gt; &lt;BR /&gt;vt[0]=0.;&lt;BR /&gt;vt[1]=0.;&lt;BR /&gt;vt[2]=1.;&lt;/DIV&gt;
&lt;DIV&gt;sgelqf(&amp;amp;rows, &amp;amp;cols, a, &amp;amp;rows, taup, work, &amp;amp;worksize,&amp;amp;info);&lt;/DIV&gt;
&lt;DIV&gt;sormlq("L", "T", &amp;amp;rows, &amp;amp;cols, &amp;amp;rows, a, &amp;amp;rows, taup, vt, &amp;amp;cols, work,&amp;amp;worksize,&amp;amp;info);&lt;/DIV&gt;
&lt;DIV&gt;for (i=0; i&amp;lt;3; i++) { &lt;BR /&gt; printf("%f 
 ", vt&lt;I&gt;);&lt;BR /&gt; };&lt;BR /&gt; &lt;BR /&gt;you obtain what you are looking for. &lt;/I&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 14 Feb 2005 13:16:51 GMT</pubDate>
    <dc:creator>Sergey_K_Intel1</dc:creator>
    <dc:date>2005-02-14T13:16:51Z</dc:date>
    <item>
      <title>Looking for SVD example.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Looking-for-SVD-example/m-p/918157#M12768</link>
      <description>&lt;DIV&gt;Hi,&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;I try to calculate the kernel of am(rows) and n(columns) matrix. (n&amp;gt;m)&lt;/DIV&gt;
&lt;DIV&gt;Therefore I wanted to decompose it with svd.&lt;/DIV&gt;
&lt;DIV&gt;Unfortunately I do not really understand the description in the manual.&lt;/DIV&gt;
&lt;DIV&gt;Has anyone a sample code?&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Isn't it sufficient to call or sgebrd and then sorgbr?&lt;/DIV&gt;
&lt;DIV&gt;The matrix P should then contain the kernel vectors in the last two columns.&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Thank you very much.&lt;/DIV&gt;
&lt;DIV&gt;I apologize asking this question, but I am trying to figure this out for quite some time now...&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;This is my sample code:&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;int&lt;/FONT&gt; &lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;=2;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;int&lt;/FONT&gt; &lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;=3;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#009900"&gt;//matrix a little bigger to save result&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt; * &lt;FONT color="#808080"&gt;a&lt;/FONT&gt;=&lt;FONT color="#0000ff"&gt;new&lt;/FONT&gt; &lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt;[&lt;FONT color="#808080"&gt;cols*cols&lt;/FONT&gt;];&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#808080"&gt;a&lt;/FONT&gt;[0]=1; &lt;FONT color="#808080"&gt;a&lt;/FONT&gt;[1]=0; &lt;FONT color="#808080"&gt;a&lt;/FONT&gt;[2]=0;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#808080"&gt;a&lt;/FONT&gt;[3]=0; &lt;FONT color="#808080"&gt;a&lt;/FONT&gt;[4]=1; &lt;FONT color="#808080"&gt;a&lt;/FONT&gt;[5]=0;&lt;/P&gt;
&lt;P&gt;//any values for the rest(not used for matrix)&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#808080"&gt;a&lt;/FONT&gt;[6]=-2; &lt;FONT color="#808080"&gt;a&lt;/FONT&gt;[7]=-2; &lt;FONT color="#808080"&gt;a&lt;/FONT&gt;[8]=-2;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;//create values as described in manual&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#009900"&gt;//first dimension of a&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;int&lt;/FONT&gt; &lt;FONT color="#808080"&gt;lda&lt;/FONT&gt;= &lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#009900"&gt;//diagonal B&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt; * &lt;FONT color="#808080"&gt;d&lt;/FONT&gt;=&lt;FONT color="#0000ff"&gt;new&lt;/FONT&gt; &lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt; [&lt;FONT color="#880000"&gt;min&lt;/FONT&gt;(&lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;)];&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#009900"&gt;//details of Q and P&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt; * &lt;FONT color="#808080"&gt;tauq&lt;/FONT&gt;= &lt;FONT color="#0000ff"&gt;new&lt;/FONT&gt; &lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt;[&lt;FONT color="#880000"&gt;min&lt;/FONT&gt;(&lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;)];&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt; * &lt;FONT color="#808080"&gt;taup&lt;/FONT&gt;= &lt;FONT color="#0000ff"&gt;new&lt;/FONT&gt; &lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt;[&lt;FONT color="#880000"&gt;min&lt;/FONT&gt;(&lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;)];&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#009900"&gt;//off diagonal of B &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt; * &lt;FONT color="#808080"&gt;e&lt;/FONT&gt;=&lt;FONT color="#0000ff"&gt;new&lt;/FONT&gt; &lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt;[&lt;FONT color="#880000"&gt;max&lt;/FONT&gt;(1,&lt;FONT color="#880000"&gt;min&lt;/FONT&gt;(&lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;)-1)];&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#009900"&gt;//temp&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt; * &lt;FONT color="#808080"&gt;work&lt;/FONT&gt;=&lt;FONT color="#0000ff"&gt;new&lt;/FONT&gt; &lt;FONT color="#0000ff"&gt;float&lt;/FONT&gt;[64*(&lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;+&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;)];&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;int&lt;/FONT&gt; &lt;FONT color="#808080"&gt;worksize&lt;/FONT&gt;=64*(&lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;+&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;);&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;int&lt;/FONT&gt; &lt;FONT color="#808080"&gt;info&lt;/FONT&gt;;&lt;/P&gt;&lt;FONT color="#009900"&gt;
&lt;P&gt;//void sgebrd(int *m,int *n,float *a,int *lda,float *d,float *e,float *tauq,float *taup,float *work,int *lwork,int *info);&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT color="#880000"&gt;
sgebrd&lt;/FONT&gt;(&amp;amp;&lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;,&amp;amp;&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;a&lt;/FONT&gt;,&amp;amp;&lt;FONT color="#808080"&gt;lda&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;d&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;e&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;tauq&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;taup&lt;/FONT&gt;,&lt;FONT color="#808080"&gt;work&lt;/FONT&gt;,&amp;amp;&lt;FONT color="#808080"&gt;worksize&lt;/FONT&gt;,&amp;amp;&lt;FONT color="#808080"&gt;info&lt;/FONT&gt;);&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;if&lt;/FONT&gt; (&lt;FONT color="#808080"&gt;info&lt;/FONT&gt;&amp;lt;0)&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;return&lt;/FONT&gt; &lt;FONT color="#808080"&gt;info&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#009900"&gt;//lda=rows did not work either&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#808080"&gt;lda&lt;/FONT&gt;=&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;; &lt;/P&gt;
&lt;P&gt;&lt;FONT color="#009900"&gt;//read P &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#880000"&gt;sorgbr&lt;/FONT&gt; ( &lt;FONT color="#000077"&gt;"P"&lt;/FONT&gt;, &amp;amp;&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;, &amp;amp;&lt;FONT color="#808080"&gt;cols&lt;/FONT&gt;, &amp;amp;&lt;FONT color="#808080"&gt;rows&lt;/FONT&gt;, &lt;FONT color="#808080"&gt;a&lt;/FONT&gt;, &amp;amp;&lt;FONT color="#808080"&gt;lda&lt;/FONT&gt;, &lt;FONT color="#808080"&gt;taup&lt;/FONT&gt; , &lt;FONT color="#808080"&gt;work&lt;/FONT&gt;, &amp;amp;&lt;FONT color="#808080"&gt;worksize&lt;/FONT&gt;, &amp;amp;&lt;FONT color="#808080"&gt;info&lt;/FONT&gt; );&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;if&lt;/FONT&gt; (&lt;FONT color="#808080"&gt;info&lt;/FONT&gt;&amp;lt;0)&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;return&lt;/FONT&gt; &lt;FONT color="#808080"&gt;info&lt;/FONT&gt;;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV&gt;//the last column is not (0,0,1)&lt;/DIV&gt;</description>
      <pubDate>Fri, 21 Jan 2005 09:10:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Looking-for-SVD-example/m-p/918157#M12768</guid>
      <dc:creator>eeisemann</dc:creator>
      <dc:date>2005-01-21T09:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for SVD example.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Looking-for-SVD-example/m-p/918158#M12769</link>
      <description>&lt;DIV&gt;There is a very good site &lt;BR /&gt;&lt;A href="http://www.netlib.org/lapack/" target="_blank"&gt;http://www.netlib.org/lapack/&lt;/A&gt;&lt;BR /&gt;where you can find samples and all the information. &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;In fact, your code doesn't solve your problem and the call &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;sorgbr ( "P", &amp;amp;cols, &amp;amp;cols, &amp;amp;rows, a, &amp;amp;lda, taup , work, &amp;amp;worksize, &amp;amp;info );&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;is wrong. This is because SORGBR generatesoneof the real orthogonal matrices Q or P**T determined by SGEBRD when reducing a real matrix A to bidiagonal form: A = Q * B * P**T. Q and P**T are defined as products of&lt;BR /&gt;elementary reflectors H(i) or G(i) respectively. And if you call&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;sgebrd(&amp;amp;rows, &amp;amp;cols,....)&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;then the correct call to sorgbr MUST be the following &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;sorgbr ( "P", &amp;amp;rows, &amp;amp;cols, &amp;amp;k,... &lt;/DIV&gt;
&lt;DIV&gt;&lt;BR /&gt;where k&amp;lt; = rows. &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;It's qite important that you will not obtain the kernel vectors by you using sorgbr becausem &amp;lt; n and according to the sorgbr manual &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;" If VECT = 'P', A is assumed to have been a K-by-N matrix, and P**T&lt;BR /&gt; is of order N:&lt;BR /&gt; if k &amp;lt; n, P**T = G(k) . . . G(2) G(1) and SORGBR returns the first m&lt;BR /&gt; rows of P**T, where n &amp;gt;= m &amp;gt;= k. "&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;This means you can obtain the first m rows of the matrix P**T but the whole P**T can not be obtained, and these m rows form the basis which is the orthogonal compliment to the kernel vectors if rank A=m. &lt;BR /&gt;So your code doesn't produce the kernel vectors.&lt;/DIV&gt;
&lt;DIV&gt;&lt;BR /&gt;There exist several ways to compute the kernel vectors using LAPACK routines. Let's us give an example. For example, it can be done through the LQ decomposition of the initial matrix A. If we have m by n matrix A andm &amp;lt; n, rank A = m, then Q**T Z give us the kernel vectors where Z is cols by n-m matrix which non-zero elements are defined as follows &lt;BR /&gt; a(j+m, j)=1. j=1,... n-m&lt;BR /&gt; &lt;BR /&gt;Then A Z= L Q * (Q**T *Z)= 0. So if you replacethecalls to sgebrd and sorgbr with &lt;/DIV&gt;
&lt;DIV&gt; &lt;BR /&gt;vt[0]=0.;&lt;BR /&gt;vt[1]=0.;&lt;BR /&gt;vt[2]=1.;&lt;/DIV&gt;
&lt;DIV&gt;sgelqf(&amp;amp;rows, &amp;amp;cols, a, &amp;amp;rows, taup, work, &amp;amp;worksize,&amp;amp;info);&lt;/DIV&gt;
&lt;DIV&gt;sormlq("L", "T", &amp;amp;rows, &amp;amp;cols, &amp;amp;rows, a, &amp;amp;rows, taup, vt, &amp;amp;cols, work,&amp;amp;worksize,&amp;amp;info);&lt;/DIV&gt;
&lt;DIV&gt;for (i=0; i&amp;lt;3; i++) { &lt;BR /&gt; printf("%f 
 ", vt&lt;I&gt;);&lt;BR /&gt; };&lt;BR /&gt; &lt;BR /&gt;you obtain what you are looking for. &lt;/I&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 14 Feb 2005 13:16:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Looking-for-SVD-example/m-p/918158#M12769</guid>
      <dc:creator>Sergey_K_Intel1</dc:creator>
      <dc:date>2005-02-14T13:16:51Z</dc:date>
    </item>
  </channel>
</rss>

