- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

[cpp]#includeThe result is correct, but sometimes in wrong order. Am I doing anything wrong when mapping the result?#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 < n ; i++ ) { result = b[jpvt-1]; } free(jpvt); free(tau); } [/cpp]

It is related to pivoting. When I add to the beggining of the function:

[cpp] for ( i = 0 ; i < n ; i++ ) { jpvtThis prevents pivoting and yields the correct result in the correct order.= i+1; } [/cpp]

Link Copied

1 Reply

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

f08bffe.f

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

*reverse*order.

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page