<?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 Least squares, QR and pivoting in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-QR-and-pivoting/m-p/823026#M4927</link>
    <description>I am trying to solve an overdetermined system in least squares sense with QR decomposition with pivoting.&lt;BR /&gt;&lt;PRE&gt;[cpp]#include &lt;STDLIB.H&gt;
#include "mkl_lapacke.h"
#include "mkl_cblas.h"
#include "mkl_types.h"
#include "least_squares.h"

void solve_least_squares(double *A, double *b, double *result, int m, int n) {

  int i;
  int *jpvt = calloc(n, sizeof(int));
  double *tau = calloc(n, sizeof(double));

  LAPACKE_dgeqp3(LAPACK_ROW_MAJOR, m, n, A, n, jpvt, tau);
  LAPACKE_dormqr(LAPACK_ROW_MAJOR, 'L', 'T', m, 1, n, A, n, tau, b, 1);
  cblas_dtrsm(CblasRowMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, n, 1, 1.0, A, n, b, 1);

  for ( i = 0 ; i &amp;lt; n ; i++ ) {
    result&lt;I&gt; = b[jpvt&lt;I&gt;-1];
  }

  free(jpvt);
  free(tau);

}
[/cpp]&lt;/I&gt;&lt;/I&gt;&lt;/STDLIB.H&gt;&lt;/PRE&gt; The result is correct, but sometimes in wrong order. Am I doing anything wrong when mapping the result?&lt;BR /&gt;&lt;BR /&gt;It is related to pivoting. When I add to the beggining of the function:&lt;BR /&gt;&lt;PRE&gt;[cpp]  for ( i = 0 ; i &amp;lt; n ; i++ ) {
    jpvt&lt;I&gt; = i+1;
  }
[/cpp]&lt;/I&gt;&lt;/PRE&gt; This prevents pivoting and yields the correct result in the correct order.</description>
    <pubDate>Fri, 13 May 2011 06:23:22 GMT</pubDate>
    <dc:creator>italo1337</dc:creator>
    <dc:date>2011-05-13T06:23:22Z</dc:date>
    <item>
      <title>Least squares, QR and pivoting</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-QR-and-pivoting/m-p/823026#M4927</link>
      <description>I am trying to solve an overdetermined system in least squares sense with QR decomposition with pivoting.&lt;BR /&gt;&lt;PRE&gt;[cpp]#include &lt;STDLIB.H&gt;
#include "mkl_lapacke.h"
#include "mkl_cblas.h"
#include "mkl_types.h"
#include "least_squares.h"

void solve_least_squares(double *A, double *b, double *result, int m, int n) {

  int i;
  int *jpvt = calloc(n, sizeof(int));
  double *tau = calloc(n, sizeof(double));

  LAPACKE_dgeqp3(LAPACK_ROW_MAJOR, m, n, A, n, jpvt, tau);
  LAPACKE_dormqr(LAPACK_ROW_MAJOR, 'L', 'T', m, 1, n, A, n, tau, b, 1);
  cblas_dtrsm(CblasRowMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, n, 1, 1.0, A, n, b, 1);

  for ( i = 0 ; i &amp;lt; n ; i++ ) {
    result&lt;I&gt; = b[jpvt&lt;I&gt;-1];
  }

  free(jpvt);
  free(tau);

}
[/cpp]&lt;/I&gt;&lt;/I&gt;&lt;/STDLIB.H&gt;&lt;/PRE&gt; The result is correct, but sometimes in wrong order. Am I doing anything wrong when mapping the result?&lt;BR /&gt;&lt;BR /&gt;It is related to pivoting. When I add to the beggining of the function:&lt;BR /&gt;&lt;PRE&gt;[cpp]  for ( i = 0 ; i &amp;lt; n ; i++ ) {
    jpvt&lt;I&gt; = i+1;
  }
[/cpp]&lt;/I&gt;&lt;/PRE&gt; This prevents pivoting and yields the correct result in the correct order.</description>
      <pubDate>Fri, 13 May 2011 06:23:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-QR-and-pivoting/m-p/823026#M4927</guid>
      <dc:creator>italo1337</dc:creator>
      <dc:date>2011-05-13T06:23:22Z</dc:date>
    </item>
    <item>
      <title>Least squares, QR and pivoting</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-QR-and-pivoting/m-p/823027#M4928</link>
      <description>See this example:&lt;BR /&gt;&lt;BR /&gt;     &lt;A href="http://www.nag.co.uk/numeric/fl/nagdoc_fl22/examples/source/f08bffe.f"&gt;f08bffe.f&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;In particular, see how the permutation is undone for the solution in the DO 100 loop. More generally, undoing a sequence of permutations requires that the individual permutations be undone in &lt;I&gt;reverse &lt;/I&gt;order.&lt;BR /&gt;</description>
      <pubDate>Fri, 13 May 2011 10:28:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-QR-and-pivoting/m-p/823027#M4928</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2011-05-13T10:28:12Z</dc:date>
    </item>
  </channel>
</rss>

