Skip to content

Instantly share code, notes, and snippets.

@malb
Created January 24, 2026 10:08
Show Gist options
  • Select an option

  • Save malb/163f1acf92305e7951e887e50b82a931 to your computer and use it in GitHub Desktop.

Select an option

Save malb/163f1acf92305e7951e887e50b82a931 to your computer and use it in GitHub Desktop.
M4RIE test
#include <m4rie/m4rie.h>
const size_t d = 3;
const size_t m = 1024;
const size_t n = 1024;
const size_t l = 1024;
/*
compile with:
gcc test.c -I. -L. -lm4rie -lm4ri -lm -o test
*/
int mzed_test(const size_t d, const size_t m, const size_t n, const size_t l) {
gf2e *ff = gf2e_init(irreducible_polynomials[d][1]);
mzed_t *A = mzed_init(ff, m, n);
mzed_randomize(A);
mzed_t *B = mzed_init(ff, m, n);
mzed_randomize(B);
mzed_t *C = mzed_init(ff, n, l);
mzed_randomize(C);
// AC + BC = (A+B)C
mzed_t *R0 = mzed_mul(NULL, A, C);
mzed_addmul(R0, B, C);
mzed_t *T0 = mzed_add(NULL, A, B);
mzed_t *R1 = mzed_mul(NULL, T0, C);
int r = mzed_cmp(R0, R1);
mzed_free(R1);
mzed_free(T0);
mzed_free(R0);
mzed_free(C);
mzed_free(B);
mzed_free(A);
return r;
};
int mzd_slice_test(const size_t d, const size_t m, const size_t n,
const size_t l) {
gf2e *ff = gf2e_init(irreducible_polynomials[d][1]);
mzd_slice_t *A = mzd_slice_init(ff, m, n);
mzd_slice_randomize(A);
mzd_slice_t *B = mzd_slice_init(ff, m, n);
mzd_slice_randomize(B);
mzd_slice_t *C = mzd_slice_init(ff, n, l);
mzd_slice_randomize(C);
// AC + BC = (A+B)C
mzd_slice_t *R0 = mzd_slice_mul(NULL, A, C);
mzd_slice_addmul(R0, B, C);
mzd_slice_t *T0 = mzd_slice_add(NULL, A, B);
mzd_slice_t *R1 = mzd_slice_mul(NULL, T0, C);
int r = mzd_slice_cmp(R0, R1);
mzd_slice_free(R1);
mzd_slice_free(T0);
mzd_slice_free(R0);
mzd_slice_free(C);
mzd_slice_free(B);
mzd_slice_free(A);
return r;
};
int main(int argc, char *argv[]) {
int r0 = mzed_test(d, m, n, l);
int r1 = mzd_slice_test(d, m, n, l);
if (r0 | r1) {
fprintf(stderr, "M4RIE test failed.");
return -1;
} else {
fprintf(stderr, "M4RIE test passed.");
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment