Skip to content

Instantly share code, notes, and snippets.

@alphaville
Created January 27, 2013 16:34
Show Gist options
  • Select an option

  • Save alphaville/4649140 to your computer and use it in GitHub Desktop.

Select an option

Save alphaville/4649140 to your computer and use it in GitHub Desktop.
Matrix-vector multiplication using BLAS.
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]);
}
}
@alphaville
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment