Skip to content

Instantly share code, notes, and snippets.

@dagit
Last active December 19, 2015 05:48
Show Gist options
  • Save dagit/5906345 to your computer and use it in GitHub Desktop.
Save dagit/5906345 to your computer and use it in GitHub Desktop.
Fast matrix mult for boolean matrices.
/*
From Section 11.2: http://www.jn.inf.ethz.ch/education/script/P3_C11.pdf
a, b, and c, are meant to be square matrices of booleans. We couldn't use bool from stdbool.h because
haskell doesn't have a CBool type
*/
void mult(char * a, char * b, char * c, int sz) {
int i,j,k,ij,ik,kj;
for(i = 0; i < sz; i++){
for(j = 0; j < sz; j++){
ij = i * sz + j;
c[ij] = 0;
for(k = 0; k < sz; k++){
ik = i * sz + k;
kj = k * sz + j;
c[ij] = c[ij] || (a[ik] && b[kj]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment