Skip to content

Commit

Permalink
Merge pull request #233 from Jake-Moss/main
Browse files Browse the repository at this point in the history
Fix build error in fmpz_mod_mpoly when using flint HEAD
  • Loading branch information
oscarbenjamin authored Oct 4, 2024
2 parents 71cab5c + a4a242a commit e8fa5b2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
17 changes: 17 additions & 0 deletions src/flint/flintlib/functions/compat.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from flint.flintlib.types.flint cimport slong
from flint.flintlib.types.fmpz_mod cimport fmpz_mod_mpoly_ctx_t, fmpz_mod_mpoly_t


cdef extern from *:
"""
#if __FLINT_RELEASE < 30200 /* Flint < 3.2.0 */
#define compat_fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(...) (void)0
#else
#define compat_fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(...) fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(__VA_ARGS__)
#endif
"""
void compat_fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(fmpz_mod_mpoly_t A, const fmpz_mod_mpoly_t B, const slong * c, const fmpz_mod_mpoly_ctx_t ctxB, const fmpz_mod_mpoly_ctx_t ctxAC)
4 changes: 0 additions & 4 deletions src/flint/flintlib/types/flint.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ cdef extern from *:
#define flint_rand_clear flint_randclear
#endif
/* FIXME: add version guard when https://github.com/flintlib/flint/pull/2068 */
/* is resolved */
#define fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(...) (void)0
"""

cdef extern from "flint/flint.h":
Expand Down
32 changes: 18 additions & 14 deletions src/flint/types/fmpz_mod_mpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from flint.flint_base.flint_base cimport (
ordering_c_to_py,
)

from flint.flint_base.flint_base import FLINT_RELEASE

from flint.utils.typecheck cimport typecheck
from flint.utils.flint_exceptions import DomainError, IncompatibleContextError

Expand All @@ -19,7 +21,6 @@ from flint.flintlib.functions.fmpz_mod_mpoly cimport (
fmpz_mod_mpoly_add_fmpz,
fmpz_mod_mpoly_clear,
fmpz_mod_mpoly_compose_fmpz_mod_mpoly,
# fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen,
fmpz_mod_mpoly_ctx_get_modulus,
fmpz_mod_mpoly_ctx_init,
fmpz_mod_mpoly_deflate,
Expand Down Expand Up @@ -69,9 +70,11 @@ from flint.flintlib.functions.fmpz_mod_mpoly_factor cimport (
fmpz_mod_mpoly_factor_squarefree,
fmpz_mod_mpoly_factor_t,
)
from flint.flintlib.functions.compat cimport compat_fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen

from flint.types.fmpz_mpoly cimport fmpz_mpoly_ctx, fmpz_mpoly


from cpython.object cimport Py_EQ, Py_NE
cimport libc.stdlib

Expand Down Expand Up @@ -1093,26 +1096,27 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
return list(stride), list(shift)

cdef _compose_gens_(self, ctx, slong *mapping):
# FIXME: Remove this when https://github.com/flintlib/flint/pull/2068 is
# resolved

# cdef fmpz_mod_mpoly res = create_fmpz_mod_mpoly(ctx)
# fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(
# res.val,
# self.val,
# mapping,
# self.ctx.val,
# (<fmpz_mod_mpoly_ctx>ctx).val
# )
# FIXME: Remove this when FLINT < 3.2 is dropped
cdef fmpz_mod_mpoly res
if FLINT_RELEASE >= 30200:
res = create_fmpz_mod_mpoly(ctx)
compat_fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(
res.val,
self.val,
mapping,
self.ctx.val,
(<fmpz_mod_mpoly_ctx>ctx).val
)
return res

cdef:
fmpz_mpoly_ctx mpoly_ctx = fmpz_mpoly_ctx.from_context(self.context())
fmpz_mpoly_ctx res_ctx = fmpz_mpoly_ctx.from_context(ctx)

fmpz_mpoly poly = mpoly_ctx.from_dict(self.to_dict())
fmpz_mpoly res = poly._compose_gens_(res_ctx, mapping)
fmpz_mpoly res1 = poly._compose_gens_(res_ctx, mapping)

return ctx.from_dict(res.to_dict())
return ctx.from_dict(res1.to_dict())


cdef class fmpz_mod_mpoly_vec:
Expand Down

0 comments on commit e8fa5b2

Please sign in to comment.