Skip to content

Commit 4465036

Browse files
committed
Add flint version guard to fmpz_mod_mpoly._compose_gen
1 parent 33f3eeb commit 4465036

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

src/flint/flint_base/flint_base.pyx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ cdef class flint_mpoly(flint_elem):
950950
)
951951
return new_ctx, self.coerce_to_context(new_ctx)
952952

953-
def coerce_to_context(self, ctx, mapping: dict[str | int, str | int] = None):
953+
def coerce_to_context(self, other_ctx, mapping: dict[str | int, str | int] = None):
954954
"""
955955
Coerce this polynomial to a different context.
956956
@@ -975,23 +975,24 @@ cdef class flint_mpoly(flint_elem):
975975
slong *c_mapping
976976
slong i
977977

978-
if not typecheck(ctx, type(self.ctx)):
978+
ctx = self.context()
979+
if not typecheck(other_ctx, type(ctx)):
979980
raise ValueError(
980-
f"provided context is not a {self.ctx.__class__.__name__}"
981+
f"provided context is not a {ctx.__class__.__name__}"
981982
)
982-
elif self.ctx is ctx:
983+
elif ctx is other_ctx:
983984
return self
984985

985986
if mapping is None:
986-
mapping = self.ctx.infer_generator_mapping(ctx)
987+
mapping = ctx.infer_generator_mapping(other_ctx)
987988
else:
988989
mapping = {
989-
self.ctx.variable_to_index(k): ctx.variable_to_index(v)
990+
ctx.variable_to_index(k): ctx.variable_to_index(v)
990991
for k, v in mapping.items()
991992
}
992993

993994
try:
994-
c_mapping = <slong *> libc.stdlib.malloc(self.ctx.nvars() * sizeof(slong *))
995+
c_mapping = <slong *> libc.stdlib.malloc(ctx.nvars() * sizeof(slong *))
995996
if c_mapping is NULL:
996997
raise MemoryError("malloc returned a null pointer")
997998

@@ -1001,11 +1002,11 @@ cdef class flint_mpoly(flint_elem):
10011002
for k, v in mapping.items():
10021003
c_mapping[k] = <slong>v
10031004

1004-
return self._compose_gens_(ctx, c_mapping)
1005+
return self._compose_gens_(other_ctx, c_mapping)
10051006
finally:
10061007
libc.stdlib.free(c_mapping)
10071008

1008-
cdef _compose_gens_(self, ctx, slong *mapping):
1009+
cdef _compose_gens_(self, other_ctx, slong *mapping):
10091010
raise NotImplementedError("abstract method")
10101011

10111012

src/flint/flintlib/types/flint.pxd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ cdef extern from "flint/fmpz.h":
4545

4646
cdef extern from *:
4747
"""
48-
/*
49-
* Functions renamed in Flint 3.2.0
50-
*/
5148
#if __FLINT_RELEASE < 30200 /* Flint < 3.2.0 */
5249
50+
/* Functions renamed in Flint 3.2.0 */
5351
#define flint_rand_init flint_randinit
5452
#define flint_rand_clear flint_randclear
5553
54+
/* Functions added in Flint 3.2.0 */
55+
#define fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(...) (void)0
56+
5657
#endif
5758
"""
5859

src/flint/types/fmpz_mod_mpoly.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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_RELEASE, FLINT_VERSION
78

89
from flint.utils.typecheck cimport typecheck
910
from flint.utils.flint_exceptions import DomainError, IncompatibleContextError
@@ -1140,6 +1141,12 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
11401141
return list(stride), list(shift)
11411142

11421143
cdef _compose_gens_(self, ctx, slong *mapping):
1144+
if FLINT_RELEASE < 30200:
1145+
raise NotImplementedError(
1146+
"this function is not supported below FLINT 3.2.0, "
1147+
f"current version is {FLINT_VERSION}"
1148+
)
1149+
11431150
cdef fmpz_mod_mpoly res = create_fmpz_mod_mpoly(ctx)
11441151
fmpz_mod_mpoly_compose_fmpz_mod_mpoly_gen(
11451152
res.val,

0 commit comments

Comments
 (0)