Skip to content

Commit d1a1438

Browse files
committed
Add fmpz_mod_mpoly workaround
1 parent f0ca650 commit d1a1438

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

src/flint/test/test_all.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,29 +2894,24 @@ def quick_poly():
28942894
assert ctx1.infer_generator_mapping(ctx) == {0: 0, 1: 1}
28952895
assert ctx1.drop_gens(ctx.names()).infer_generator_mapping(ctx) == {}
28962896

2897-
# FIXME: Remove this guard when https://github.com/flintlib/flint/pull/2068 is
2898-
# resolved
2899-
if P is not flint.fmpz_mod_mpoly:
2900-
assert quick_poly().project_to_context(ctx1) == \
2901-
ctx1.from_dict(
2902-
{(0, 0, 0, 0): 1, (0, 1, 0, 0): 2, (1, 0, 0, 0): 3, (2, 2, 0, 0): 4}
2903-
)
2904-
new_poly = quick_poly().project_to_context(ctx1)
2905-
assert ctx1.drop_gens(new_poly.unused_gens()) == ctx
2906-
assert new_poly.project_to_context(ctx) == quick_poly()
2907-
2908-
new_poly = quick_poly().project_to_context(ctx2)
2909-
new_ctx = ctx2.drop_gens(new_poly.unused_gens())
2910-
assert new_ctx != ctx
2911-
assert new_poly != quick_poly()
2912-
2913-
new_ctx = new_ctx.from_context(new_ctx, ordering=ctx.ordering())
2914-
assert new_ctx == ctx
2915-
assert new_poly.project_to_context(new_ctx) == quick_poly()
2916-
2917-
assert ctx.append_gens(*ctx1.names()[-2:]) == ctx1
2918-
else:
2919-
assert raises(lambda: quick_poly().project_to_context(ctx1), NotImplementedError)
2897+
assert quick_poly().project_to_context(ctx1) == \
2898+
ctx1.from_dict(
2899+
{(0, 0, 0, 0): 1, (0, 1, 0, 0): 2, (1, 0, 0, 0): 3, (2, 2, 0, 0): 4}
2900+
)
2901+
new_poly = quick_poly().project_to_context(ctx1)
2902+
assert ctx1.drop_gens(new_poly.unused_gens()) == ctx
2903+
assert new_poly.project_to_context(ctx) == quick_poly()
2904+
2905+
new_poly = quick_poly().project_to_context(ctx2)
2906+
new_ctx = ctx2.drop_gens(new_poly.unused_gens())
2907+
assert new_ctx != ctx
2908+
assert new_poly != quick_poly()
2909+
2910+
new_ctx = new_ctx.from_context(new_ctx, ordering=ctx.ordering())
2911+
assert new_ctx == ctx
2912+
assert new_poly.project_to_context(new_ctx) == quick_poly()
2913+
2914+
assert ctx.append_gens(*ctx1.names()[-2:]) == ctx1
29202915

29212916
assert P(val={(0, 0): 1}, ctx=ctx) == ctx.from_dict({(0, 0): 1})
29222917
assert P(ctx=ctx).context() == ctx

src/flint/types/fmpz_mod_mpoly.pyx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ from flint.flint_base.flint_base cimport (
44
ordering_py_to_c,
55
ordering_c_to_py,
66
)
7-
from flint.flint_base.flint_base import FLINT_VERSION
87

98
from flint.utils.typecheck cimport typecheck
109
from flint.utils.flint_exceptions import DomainError, IncompatibleContextError
@@ -20,7 +19,7 @@ from flint.flintlib.functions.fmpz_mod_mpoly cimport (
2019
fmpz_mod_mpoly_add_fmpz,
2120
fmpz_mod_mpoly_clear,
2221
fmpz_mod_mpoly_compose_fmpz_mod_mpoly,
23-
fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen,
22+
# fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen,
2423
fmpz_mod_mpoly_ctx_get_modulus,
2524
fmpz_mod_mpoly_ctx_init,
2625
fmpz_mod_mpoly_deflate,
@@ -71,6 +70,8 @@ from flint.flintlib.functions.fmpz_mod_mpoly_factor cimport (
7170
fmpz_mod_mpoly_factor_t,
7271
)
7372

73+
from flint.types.fmpz_mpoly cimport fmpz_mpoly_ctx, fmpz_mpoly
74+
7475
from cpython.object cimport Py_EQ, Py_NE
7576
cimport libc.stdlib
7677

@@ -1092,21 +1093,26 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
10921093
return list(stride), list(shift)
10931094

10941095
cdef _compose_gens_(self, ctx, slong *mapping):
1095-
raise NotImplementedError(
1096-
"this function is not supported below FLINT 3.2.0, "
1097-
f"current version is {FLINT_VERSION}"
1098-
)
1099-
1100-
cdef fmpz_mod_mpoly res = create_fmpz_mod_mpoly(ctx)
1101-
fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(
1102-
res.val,
1103-
self.val,
1104-
mapping,
1105-
self.ctx.val,
1106-
(<fmpz_mod_mpoly_ctx>ctx).val
1107-
)
1096+
# FIXME: Remove this when https://github.com/flintlib/flint/pull/2068 is
1097+
# resolved
1098+
1099+
# cdef fmpz_mod_mpoly res = create_fmpz_mod_mpoly(ctx)
1100+
# fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(
1101+
# res.val,
1102+
# self.val,
1103+
# mapping,
1104+
# self.ctx.val,
1105+
# (<fmpz_mod_mpoly_ctx>ctx).val
1106+
# )
11081107

1109-
return res
1108+
cdef:
1109+
fmpz_mpoly_ctx mpoly_ctx = fmpz_mpoly_ctx.from_context(self.context())
1110+
fmpz_mpoly_ctx res_ctx = fmpz_mpoly_ctx.from_context(ctx)
1111+
1112+
fmpz_mpoly poly = mpoly_ctx.from_dict(self.to_dict())
1113+
fmpz_mpoly res = poly._compose_gens_(res_ctx, mapping)
1114+
1115+
return ctx.from_dict(res.to_dict())
11101116

11111117

11121118
cdef class fmpz_mod_mpoly_vec:

0 commit comments

Comments
 (0)