Skip to content

Instantly share code, notes, and snippets.

@embed
Created December 6, 2009 13:00
Show Gist options
  • Save embed/250210 to your computer and use it in GitHub Desktop.
Save embed/250210 to your computer and use it in GitHub Desktop.
float* matrixmul(float* fst, int frows, int fcols, float* sec, int srows, int scols)
{
if(fcols != srows)
{
printf("dimensions %d x %d to %d x %d\n",frows, fcols, srows, scols);
throw "Matrix dimension mismatch error";
}
float *result=new float[frows*scols];
for(int i=0 ; i<frows*scols ; i++)
result[i]=0.0;
int times=fcols;
for(int i=0; i<frows ; i++)
{
for(int j=0; j<scols ; j++)
{
for(int k=0; k<times; k++)
{
float temp=fst[i*fcols+k]*sec[j+scols*k];
result[j+i*times]+=temp;
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment