Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/flint/test/test_fmpz_vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def test_fmpz_vec_construct_int_and_iter() -> None:
assert repr(w) == "fmpz_vec(['4', '5', '6'], 3)"


def test_fmpz_vec_to_list_int() -> None:
assert fmpz_vec(0).to_list_int() == []

v = fmpz_vec([1, fmpz(2), -3, 2**80])
values = v.to_list_int()
assert values == [1, 2, -3, 2**80]
assert all(type(x) is int for x in values)


def test_fmpz_vec_double_indirect_and_errors() -> None:
v = fmpz_vec(2, double_indirect=True)
v[0] = 10
Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/acb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,7 @@ cdef class acb(flint_scalar):
iterable *vec*. The output is a list of *acb* entries.
If *inverse* is True, computes the inverse transform instead.

>>> for c in acb.dft(acb.dft(range(1,12)), inverse=True):
>>> for c in acb.dft(acb.dft(range(1,12)), inverse=True): # doctest: +SKIP
... print(c)
...
[1.000000000000 +/- 1.06e-13] + [+/- 8.66e-14]j
Expand Down Expand Up @@ -2603,7 +2603,7 @@ cdef class acb(flint_scalar):
n = fmpz(n)
if n < 1 or num < 0:
raise ValueError("require n >= 1 and num >= 0")
v = [acb() for i in range(num)]
v = [acb() for _ in range(num)]
w = <acb_ptr>libc.stdlib.malloc(num * cython.sizeof(acb_struct))
for i in range(num):
w[i] = (<acb>(v[i])).val[0]
Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/acb_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ cdef class acb_mat(flint_mat):
raise ValueError("failed to isolate eigenvalues (try higher prec, multiple=True for multiple eigenvalues, or nonstop=True to avoid the exception)")
if tol is not None:
mag_clear(tolm)
Elist = [acb() for i in range(n)]
Elist = [acb() for _ in range(n)]
for i in range(n):
acb_swap((<acb>(Elist [i])).val, acb_mat_entry(E.val, 0, i))
if not left and not right:
Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/acb_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ cdef class acb_poly(flint_poly):
n = len(xs)
if n == 0:
return []
ys = [acb.__new__(acb) for i in range(n)]
ys = [acb.__new__(acb) for _ in range(n)]
xsv = <acb_ptr> libc.stdlib.malloc(sizeof(acb_struct) * n)
ysv = <acb_ptr> libc.stdlib.malloc(sizeof(acb_struct) * n)
for i in range(n):
Expand Down Expand Up @@ -492,7 +492,7 @@ cdef class acb_poly(flint_poly):
raise ValueError("roots() failed to converge: insufficient precision, or squareful input")

_acb_vec_sort_pretty(roots, deg)
pyroots = [acb.__new__(acb) for i in range(deg)]
pyroots = [acb.__new__(acb) for _ in range(deg)]
for i in range(deg):
acb_set((<acb>(pyroots[i])).val, &roots[i])

Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/arb_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ cdef class arb_poly(flint_poly):
n = len(xs)
if n == 0:
return []
ys = [arb.__new__(arb) for i in range(n)]
ys = [arb.__new__(arb) for _ in range(n)]
xsv = <arb_ptr> libc.stdlib.malloc(sizeof(arb_struct) * n)
ysv = <arb_ptr> libc.stdlib.malloc(sizeof(arb_struct) * n)
for i in range(n):
Expand Down
6 changes: 3 additions & 3 deletions src/flint/types/fmpq_mpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ cdef class fmpq_mpoly(flint_mpoly):
fmpz_mpoly_deflate(res.val.zpoly, self.val.zpoly, shift.val, stride.val, self.ctx.val.zctx)
fmpq_set(res.val.content, self.val.content)

return res, list(stride)
return res, stride.to_list_int()

def deflation_monom(self) -> tuple[fmpq_mpoly, list[int], fmpq_mpoly]:
"""
Expand Down Expand Up @@ -1087,7 +1087,7 @@ cdef class fmpq_mpoly(flint_mpoly):
fmpz_mpoly_deflate(res.val.zpoly, self.val.zpoly, shift.val, stride.val, self.ctx.val.zctx)
fmpq_set(res.val.content, self.val.content)

return res, list(stride), monom
return res, stride.to_list_int(), monom

def deflation_index(self) -> tuple[list[int], list[int]]:
"""
Expand Down Expand Up @@ -1118,7 +1118,7 @@ cdef class fmpq_mpoly(flint_mpoly):
fmpz_vec stride = fmpz_vec(nvars)

fmpz_mpoly_deflation(shift.val, stride.val, self.val.zpoly, self.ctx.val.zctx)
return list(stride), list(shift)
return stride.to_list_int(), shift.to_list_int()

cdef _compose_gens_(self, ctx, slong *mapping):
cdef fmpq_mpoly res = create_fmpq_mpoly(ctx)
Expand Down
10 changes: 5 additions & 5 deletions src/flint/types/fmpz_mod_mpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ cdef class fmpz_mod_mpoly_ctx(flint_mod_mpoly_context):
"""
cdef:
fmpz_vec exp_vec
slong i, nvars = self.nvars()
slong nvars = self.nvars()
fmpz_mod_mpoly res

if not isinstance(d, dict):
raise ValueError("expected a dictionary")

res = create_fmpz_mod_mpoly(self)

for i, (exps, coeff) in enumerate(d.items()):
for exps, coeff in d.items():
if len(exps) != nvars:
raise ValueError(f"expected {nvars} exponents, got {len(exps)}")
elif not coeff:
Expand Down Expand Up @@ -1054,7 +1054,7 @@ cdef class fmpz_mod_mpoly(flint_mpoly):

fmpz_mod_mpoly_deflate(res.val, self.val, shift.val, stride.val, self.ctx.val)

return res, list(stride)
return res, stride.to_list_int()

def deflation_monom(self) -> tuple[fmpz_mod_mpoly, list[int], fmpz_mod_mpoly]:
"""
Expand Down Expand Up @@ -1082,7 +1082,7 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
fmpz_mod_mpoly_push_term_ui_ffmpz(monom.val, 1, fmpz_vec(shift).val, self.ctx.val)
fmpz_mod_mpoly_deflate(res.val, self.val, shift.val, stride.val, self.ctx.val)

return res, list(stride), monom
return res, stride.to_list_int(), monom

def deflation_index(self) -> tuple[list[int], list[int]]:
"""
Expand Down Expand Up @@ -1113,7 +1113,7 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
fmpz_vec stride = fmpz_vec(nvars)

fmpz_mod_mpoly_deflation(shift.val, stride.val, self.val, self.ctx.val)
return list(stride), list(shift)
return stride.to_list_int(), shift.to_list_int()

cdef _compose_gens_(self, ctx, slong *mapping):
# FIXME: Remove this when FLINT < 3.2 is dropped
Expand Down
10 changes: 5 additions & 5 deletions src/flint/types/fmpz_mpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ cdef class fmpz_mpoly_ctx(flint_mpoly_context):
"""
cdef:
fmpz_vec exp_vec
slong i, nvars = self.nvars()
slong nvars = self.nvars()
fmpz_mpoly res

if not isinstance(d, dict):
raise ValueError("expected a dictionary")

res = create_fmpz_mpoly(self)

for i, (k, v) in enumerate(d.items()):
for k, v in d.items():
o = any_as_fmpz(v)
if o is NotImplemented:
raise TypeError(f"cannot coerce coefficient '{v}' to fmpz")
Expand Down Expand Up @@ -1136,7 +1136,7 @@ cdef class fmpz_mpoly(flint_mpoly):

fmpz_mpoly_deflate(res.val, self.val, shift.val, stride.val, self.ctx.val)

return res, list(stride)
return res, stride.to_list_int()

def deflation_monom(self) -> tuple[fmpz_mpoly, list[int], fmpz_mpoly]:
"""
Expand Down Expand Up @@ -1164,7 +1164,7 @@ cdef class fmpz_mpoly(flint_mpoly):
fmpz_mpoly_push_term_ui_ffmpz(monom.val, 1, fmpz_vec(shift).val, self.ctx.val)
fmpz_mpoly_deflate(res.val, self.val, shift.val, stride.val, self.ctx.val)

return res, list(stride), monom
return res, stride.to_list_int(), monom

def deflation_index(self) -> tuple[list[int], list[int]]:
"""
Expand Down Expand Up @@ -1195,7 +1195,7 @@ cdef class fmpz_mpoly(flint_mpoly):
fmpz_vec stride = fmpz_vec(nvars)

fmpz_mpoly_deflation(shift.val, stride.val, self.val, self.ctx.val)
return list(stride), list(shift)
return stride.to_list_int(), shift.to_list_int()


@cython.final
Expand Down
1 change: 1 addition & 0 deletions src/flint/types/fmpz_vec.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class fmpz_vec:

def __len__(self) -> int: ...
def __iter__(self) -> Iterator[fmpz]: ...
def to_list_int(self) -> list[int]: ...

def str(self, *args: object) -> _str: ...
def repr(self, *args: object) -> _str: ...
Expand Down
8 changes: 7 additions & 1 deletion src/flint/types/fmpz_vec.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from flint.flintlib.functions.fmpz cimport fmpz_struct, fmpz_set, fmpz_init_set
from flint.flintlib.functions.fmpz_vec cimport _fmpz_vec_init, _fmpz_vec_clear
from libc.stdint cimport SIZE_MAX

from flint.types.fmpz cimport fmpz, any_as_fmpz
from flint.types.fmpz cimport fmpz, any_as_fmpz, fmpz_get_intlong

cimport libc.stdlib

Expand Down Expand Up @@ -81,6 +81,12 @@ cdef class fmpz_vec:
fmpz_init_set(z.val, &self.val[i])
yield z

def to_list_int(self):
cdef list res = [None] * self.length
for i in range(self.length):
res[i] = fmpz_get_intlong(&self.val[i])
return res

def str(self, *args):
s = [None] * self.length
for i in range(self.length):
Expand Down
10 changes: 5 additions & 5 deletions src/flint/types/nmod_mpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ cdef class nmod_mpoly_ctx(flint_mod_mpoly_context):
"""
cdef:
fmpz_vec exp_vec
slong i, nvars = self.nvars()
slong nvars = self.nvars()
nmod_mpoly res

if not isinstance(d, dict):
raise ValueError("expected a dictionary")

res = create_nmod_mpoly(self)

for i, (exps, coeff) in enumerate(d.items()):
for exps, coeff in d.items():
if len(exps) != nvars:
raise ValueError(f"expected {nvars} exponents, got {len(exps)}")
elif not coeff:
Expand Down Expand Up @@ -1019,7 +1019,7 @@ cdef class nmod_mpoly(flint_mpoly):

nmod_mpoly_deflate(res.val, self.val, shift.val, stride.val, self.ctx.val)

return res, list(stride)
return res, stride.to_list_int()

def deflation_monom(self) -> tuple[nmod_mpoly, list[int], nmod_mpoly]:
"""
Expand Down Expand Up @@ -1047,7 +1047,7 @@ cdef class nmod_mpoly(flint_mpoly):
nmod_mpoly_push_term_ui_ffmpz(monom.val, 1, fmpz_vec(shift).val, self.ctx.val)
nmod_mpoly_deflate(res.val, self.val, shift.val, stride.val, self.ctx.val)

return res, list(stride), monom
return res, stride.to_list_int(), monom

def deflation_index(self) -> tuple[list[int], list[int]]:
"""
Expand Down Expand Up @@ -1078,7 +1078,7 @@ cdef class nmod_mpoly(flint_mpoly):
fmpz_vec stride = fmpz_vec(nvars)

nmod_mpoly_deflation(shift.val, stride.val, self.val, self.ctx.val)
return list(stride), list(shift)
return stride.to_list_int(), shift.to_list_int()

cdef _compose_gens_(self, ctx, slong *mapping):
cdef nmod_mpoly res = create_nmod_mpoly(ctx)
Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/nmod_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ cdef class nmod_poly(flint_poly):
cdef mp_limb_t m
n = self.length()
m = self.modulus()
L = [nmod(0, m) for i in range(n)] # XXX: speed up
L = [nmod(0, m) for _ in range(n)] # XXX: speed up
for i from 0 <= i < n:
(<nmod>(L[i])).val = nmod_poly_get_coeff_ui(self.val, i)
return L
Expand Down
Loading