Created
January 27, 2013 16:34
-
-
Save alphaville/4649140 to your computer and use it in GitHub Desktop.
Matrix-vector multiplication using BLAS.
This file contains hidden or 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
| void doStuff(void) { | |
| // Les data: | |
| float A[4][4] = // the matrix to be multiplied | |
| { | |
| {1.0f, 1.0f, 1.0f, 1.0f}, | |
| {0.0f, 1.0f, 1.0f, 4.0f}, | |
| {1.0f, 1.0f, 1.0f, 4.0f}, | |
| {6.0f, 2.0f, 1.0f, 1.0f} | |
| }; | |
| float a = 0.5f; | |
| float x[4] = {1.0f, 2.0f, 4.0f, 8.0f}; | |
| float y[4] = {0.f, 0.f, 0.f, 0.f}; //result y = a*A*x | |
| // Le command: | |
| cblas_sgemv(CblasRowMajor, CblasNoTrans, 4, 4, a, (float*) A, 4, x, 1, 1.0f, y, 1); | |
| ptrdiff_t i; | |
| for (i = 0; i < 4; i++) { | |
| printf("y[%d]=%.4f\n", i, y[i]); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also http://ideone.com/s5Pl4r