Skip to content

Conversation

@fredrik-johansson
Copy link
Collaborator

@fredrik-johansson fredrik-johansson commented Jan 28, 2024

Plus miscellaneous cleanup and optimizations.

@oscarbenjamin
Copy link
Contributor

To anyone looking to adapt their code for this change it is mostly just a case of changing e.g. fmpz_mod_mat_add(A, B) to fmpz_mod_mat_add(A, B, ctx) but there are a few notable exceptions:

  1. fmpz_mod_mat_init needs a fmpz_mod_ctx rather than an fmpz_mod.
  2. The undocumented fmpz_mod_mat_equal(A, B) is not quite equivalent to fmpz_mod_mat_equal(A, B, ctx) because the former compares the moduli whereas the latter does not.
  3. The fmpz_mod_mat_rref function is changed from previously fmpz_mod_mat_rref(perm, A) to fmpz_mod_mat_rref(B, A, ctx). Previously it could be used like fmpz_mod_mat_rref(NULL, A). Changing that to fmpz_mod_mat_rref(NULL, A, ctx) will compile but will segfault at runtime. The proper equivalent is fmpz_mod_mat_rref(A, A, ctx).

I ended up with these cross-version compatible macros:

    /*
     * fmpz_mod_mat function signatures were changed in FLINT 3.1.0
     */
    #if __FLINT_RELEASE >= 30100 /* Flint 3.1.0 or later */
    #define compat_fmpz_mod_mat_init(mat, rows, cols, ctx) fmpz_mod_mat_init(mat, rows, cols, ctx)
    #define compat_fmpz_mod_mat_init_set(mat, src, ctx) fmpz_mod_mat_init_set(mat, src, ctx)
    #define compat_fmpz_mod_mat_clear(mat, ctx) fmpz_mod_mat_clear(mat, ctx)
    #define compat_fmpz_mod_mat_set(A, B, ctx) fmpz_mod_mat_set(A, B, ctx)
    #define compat_fmpz_mod_mat_nrows(mat, ctx) fmpz_mod_mat_nrows(mat, ctx)
    #define compat_fmpz_mod_mat_ncols(mat, ctx) fmpz_mod_mat_ncols(mat, ctx)
    #define compat_fmpz_mod_mat_entry(mat, i, j) fmpz_mod_mat_entry(mat, i, j)
    #define compat_fmpz_mod_mat_set_entry(mat, i, j, val, ctx) fmpz_mod_mat_set_entry(mat, i, j, val, ctx)
    #define compat_fmpz_mod_mat_one(mat, ctx) fmpz_mod_mat_one(mat, ctx)
    #define compat_fmpz_mod_mat_equal(mat1, mat2, ctx) fmpz_mod_mat_equal(mat1, mat2, ctx)
    #define compat_fmpz_mod_mat_is_zero(mat, ctx) fmpz_mod_mat_is_zero(mat, ctx)
    #define compat_fmpz_mod_mat_neg(B, A, ctx) fmpz_mod_mat_neg(B, A, ctx)
    #define compat_fmpz_mod_mat_add(C, A, B, ctx) fmpz_mod_mat_add(C, A, B, ctx)
    #define compat_fmpz_mod_mat_sub(C, A, B, ctx) fmpz_mod_mat_sub(C, A, B, ctx)
    #define compat_fmpz_mod_mat_scalar_mul_fmpz(B, A, c, ctx) fmpz_mod_mat_scalar_mul_fmpz(B, A, c, ctx)
    #define compat_fmpz_mod_mat_mul(C, A, B, ctx) fmpz_mod_mat_mul(C, A, B, ctx)
    #define compat_fmpz_mod_mat_inv(B, A, ctx) fmpz_mod_mat_inv(B, A, ctx)
    #define compat_fmpz_mod_mat_transpose(B, A, ctx) fmpz_mod_mat_transpose(B, A, ctx)
    #define compat_fmpz_mod_mat_solve(X, A, B, ctx) fmpz_mod_mat_solve(X, A, B, ctx)
    #define compat_fmpz_mod_mat_rref(mat, ctx) fmpz_mod_mat_rref(mat, mat, ctx)
    #define compat_fmpz_mod_mat_charpoly(p, M, ctx) fmpz_mod_mat_charpoly(p, M, ctx)
    #define compat_fmpz_mod_mat_minpoly(p, M, ctx) fmpz_mod_mat_minpoly(p, M, ctx)
    #else /* Flint 3.0.0 or 3.0.1 */
    #define compat_fmpz_mod_mat_init(mat, rows, cols, ctx) fmpz_mod_mat_init(mat, rows, cols, ctx->n)
    #define compat_fmpz_mod_mat_init_set(mat, src, ctx) fmpz_mod_mat_init_set(mat, src)
    #define compat_fmpz_mod_mat_clear(mat, ctx) fmpz_mod_mat_clear(mat)
    #define compat_fmpz_mod_mat_set(A, B, ctx) fmpz_mod_mat_set(A, B)
    #define compat_fmpz_mod_mat_nrows(mat, ctx) fmpz_mod_mat_nrows(mat)
    #define compat_fmpz_mod_mat_ncols(mat, ctx) fmpz_mod_mat_ncols(mat)
    #define compat_fmpz_mod_mat_entry(mat, i, j) fmpz_mod_mat_entry(mat, i, j)
    #define compat_fmpz_mod_mat_set_entry(mat, i, j, val, ctx) fmpz_mod_mat_set_entry(mat, i, j, val)
    #define compat_fmpz_mod_mat_one(mat, ctx) fmpz_mod_mat_one(mat)
    #define compat_fmpz_mod_mat_equal(mat1, mat2, ctx) fmpz_mod_mat_equal(mat1, mat2)
    #define compat_fmpz_mod_mat_is_zero(mat, ctx) fmpz_mod_mat_is_zero(mat)
    #define compat_fmpz_mod_mat_neg(B, A, ctx) fmpz_mod_mat_neg(B, A)
    #define compat_fmpz_mod_mat_add(C, A, B, ctx) fmpz_mod_mat_add(C, A, B)
    #define compat_fmpz_mod_mat_sub(C, A, B, ctx) fmpz_mod_mat_sub(C, A, B)
    #define compat_fmpz_mod_mat_scalar_mul_fmpz(B, A, c, ctx) fmpz_mod_mat_scalar_mul_fmpz(B, A, c)
    #define compat_fmpz_mod_mat_mul(C, A, B, ctx) fmpz_mod_mat_mul(C, A, B)
    #define compat_fmpz_mod_mat_inv(B, A, ctx) fmpz_mod_mat_inv(B, A)
    #define compat_fmpz_mod_mat_transpose(B, A, ctx) fmpz_mod_mat_transpose(B, A)
    #define compat_fmpz_mod_mat_solve(X, A, B, ctx) fmpz_mod_mat_solve(X, A, B)
    #define compat_fmpz_mod_mat_rref(mat, ctx) fmpz_mod_mat_rref(NULL, mat)
    #define compat_fmpz_mod_mat_charpoly(p, M, ctx) fmpz_mod_mat_charpoly(p, M, ctx)
    #define compat_fmpz_mod_mat_minpoly(p, M, ctx) fmpz_mod_mat_minpoly(p, M, ctx)
    #endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants