Last active
December 19, 2015 05:48
-
-
Save dagit/5906345 to your computer and use it in GitHub Desktop.
Fast matrix mult for boolean matrices.
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
/* | |
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