Skip to content

Instantly share code, notes, and snippets.

@malb
Last active January 24, 2026 10:05
Show Gist options
  • Select an option

  • Save malb/5afc443d6ca3e212eb28db5c17522ceb to your computer and use it in GitHub Desktop.

Select an option

Save malb/5afc443d6ca3e212eb28db5c17522ceb to your computer and use it in GitHub Desktop.
M4RI Test
#include <m4ri/m4ri.h>
/*
compile with:
gcc test.c -lm4ri -lm -o test
*/
const size_t m = 1024;
const size_t n = 1024;
const size_t l = 1024;
int main(int argc, char *argv[]) {
mzd_t *A = mzd_init(m, n);
mzd_randomize(A);
mzd_t *B = mzd_init(m, n);
mzd_randomize(B);
mzd_t *C = mzd_init(n, l);
mzd_randomize(C);
// AC + BC = (A+B)C
mzd_t *R0 = mzd_mul(NULL, A, C, 0);
mzd_addmul(R0, B, C, 0);
mzd_t *T0 = mzd_add(NULL, A, B);
mzd_t *R1 = mzd_mul(NULL, T0, C, 0);
int r = mzd_equal(R0, R1);
FILE *fh = tmpfile();
mzd_to_png_fh(A, fh, 1, NULL, 0);
fflush(fh);
fseek(fh, 0, SEEK_SET);
mzd_t *AA = mzd_from_png_fh(fh, 0);
fclose(fh);
r &= mzd_equal(A, AA);
mzd_free(AA);
mzd_free(T0);
mzd_free(R1);
mzd_free(R0);
mzd_free(C);
mzd_free(B);
mzd_free(A);
if (r == TRUE) {
fprintf(stderr, "M4RI test passed.");
return 0;
} else {
fprintf(stderr, "M4RI test failed.");
return -1;
}
}
/* Local Variables: */
/* gist-id: "5afc443d6ca3e212eb28db5c17522ceb" */
/* End: */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment