Created
August 5, 2015 14:27
-
-
Save wlevine/e0ee4a9a0f527b666c65 to your computer and use it in GitHub Desktop.
clapack_dgesv test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <atlas/clapack.h> | |
#include <stdio.h> | |
int main() { | |
double a[9] = { 1,0,0, | |
-1,0,1, | |
2,1,1}; | |
double b[6] = {1,0, | |
1,2, | |
4,2}; | |
int n = 3; | |
int nrhs = 2; | |
int ipiv[3]; | |
clapack_dgesv(CblasRowMajor, n, nrhs, a, n, ipiv, b, n); | |
int i,j; | |
for (i=0; i<n; i++) { | |
for (j=0; j<nrhs; j++) { | |
printf("%f ",b[j+i*nrhs]); | |
} | |
printf("\n"); | |
} | |
printf("\n"); | |
/* | |
b should be equal to: | |
1 0 | |
0 0 | |
2 2 | |
but is actually equal to: | |
1 -2 | |
1 2 | |
-8 6 | |
*/ | |
//try again with b stored in column-major form | |
double a2[9] = { 1,0,0, | |
-1,0,1, | |
2,1,1}; | |
double bt[6] = {1,1,4,0,2,2}; | |
clapack_dgesv(CblasRowMajor, n, nrhs, a2, n, ipiv, bt, n); | |
//column-major print | |
for (i=0; i<n; i++) { | |
for (j=0; j<nrhs; j++) { | |
printf("%f ",bt[i+j*n]); | |
} | |
printf("\n"); | |
} | |
//this time it gives the correct answer | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment