Skip to content

Commit

Permalink
Add fmpz_mod_mpoly workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Moss committed Sep 22, 2024
1 parent f0ca650 commit d1a1438
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
41 changes: 18 additions & 23 deletions src/flint/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2894,29 +2894,24 @@ def quick_poly():
assert ctx1.infer_generator_mapping(ctx) == {0: 0, 1: 1}
assert ctx1.drop_gens(ctx.names()).infer_generator_mapping(ctx) == {}

# FIXME: Remove this guard when https://github.com/flintlib/flint/pull/2068 is
# resolved
if P is not flint.fmpz_mod_mpoly:
assert quick_poly().project_to_context(ctx1) == \
ctx1.from_dict(
{(0, 0, 0, 0): 1, (0, 1, 0, 0): 2, (1, 0, 0, 0): 3, (2, 2, 0, 0): 4}
)
new_poly = quick_poly().project_to_context(ctx1)
assert ctx1.drop_gens(new_poly.unused_gens()) == ctx
assert new_poly.project_to_context(ctx) == quick_poly()

new_poly = quick_poly().project_to_context(ctx2)
new_ctx = ctx2.drop_gens(new_poly.unused_gens())
assert new_ctx != ctx
assert new_poly != quick_poly()

new_ctx = new_ctx.from_context(new_ctx, ordering=ctx.ordering())
assert new_ctx == ctx
assert new_poly.project_to_context(new_ctx) == quick_poly()

assert ctx.append_gens(*ctx1.names()[-2:]) == ctx1
else:
assert raises(lambda: quick_poly().project_to_context(ctx1), NotImplementedError)
assert quick_poly().project_to_context(ctx1) == \
ctx1.from_dict(
{(0, 0, 0, 0): 1, (0, 1, 0, 0): 2, (1, 0, 0, 0): 3, (2, 2, 0, 0): 4}
)
new_poly = quick_poly().project_to_context(ctx1)
assert ctx1.drop_gens(new_poly.unused_gens()) == ctx
assert new_poly.project_to_context(ctx) == quick_poly()

new_poly = quick_poly().project_to_context(ctx2)
new_ctx = ctx2.drop_gens(new_poly.unused_gens())
assert new_ctx != ctx
assert new_poly != quick_poly()

new_ctx = new_ctx.from_context(new_ctx, ordering=ctx.ordering())
assert new_ctx == ctx
assert new_poly.project_to_context(new_ctx) == quick_poly()

assert ctx.append_gens(*ctx1.names()[-2:]) == ctx1

assert P(val={(0, 0): 1}, ctx=ctx) == ctx.from_dict({(0, 0): 1})
assert P(ctx=ctx).context() == ctx
Expand Down
38 changes: 22 additions & 16 deletions src/flint/types/fmpz_mod_mpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from flint.flint_base.flint_base cimport (
ordering_py_to_c,
ordering_c_to_py,
)
from flint.flint_base.flint_base import FLINT_VERSION

from flint.utils.typecheck cimport typecheck
from flint.utils.flint_exceptions import DomainError, IncompatibleContextError
Expand All @@ -20,7 +19,7 @@ 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_compose_fmpz_mod_mpoly_gen,
fmpz_mod_mpoly_ctx_get_modulus,
fmpz_mod_mpoly_ctx_init,
fmpz_mod_mpoly_deflate,
Expand Down Expand Up @@ -71,6 +70,8 @@ from flint.flintlib.functions.fmpz_mod_mpoly_factor cimport (
fmpz_mod_mpoly_factor_t,
)

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 @@ -1092,21 +1093,26 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
return list(stride), list(shift)

cdef _compose_gens_(self, ctx, slong *mapping):
raise NotImplementedError(
"this function is not supported below FLINT 3.2.0, "
f"current version is {FLINT_VERSION}"
)

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 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
# )

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)

return ctx.from_dict(res.to_dict())


cdef class fmpz_mod_mpoly_vec:
Expand Down

0 comments on commit d1a1438

Please sign in to comment.