Skip to content

Commit 3ab97f6

Browse files
committed
Make flint_poly a global until issue #62 is resolved
1 parent 38c9ffd commit 3ab97f6

File tree

3 files changed

+131
-60
lines changed

3 files changed

+131
-60
lines changed

src/flint/flint_base/flint_base.pxd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ cdef class flint_elem:
44
cdef class flint_scalar(flint_elem):
55
pass
66

7-
cdef class flint_poly(flint_elem):
8-
pass
7+
# TODO:
8+
# See .pyx file
9+
# cdef class flint_poly(flint_elem):
10+
# pass
911

1012
cdef class flint_mpoly(flint_elem):
1113
pass

src/flint/flint_base/flint_base.pyx

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,70 @@ cdef class flint_elem:
1212

1313
cdef class flint_scalar(flint_elem):
1414
pass
15-
16-
cdef class flint_poly(flint_elem):
17-
"""
18-
Base class for polynomials.
19-
"""
20-
21-
def __iter__(self):
22-
cdef long i, n
23-
n = self.length()
24-
for i in range(n):
25-
yield self[i]
26-
27-
def coeffs(self):
28-
return list(self)
29-
30-
def str(self, bint ascending=False):
31-
"""
32-
Convert to a human-readable string (generic implementation for
33-
all polynomial types).
34-
35-
If *ascending* is *True*, the monomials are output from low degree to
36-
high, otherwise from high to low.
37-
"""
38-
coeffs = [str(c) for c in self]
39-
if not coeffs:
40-
return "0"
41-
s = []
42-
coeffs = enumerate(coeffs)
43-
if not ascending:
44-
coeffs = reversed(list(coeffs))
45-
for i, c in coeffs:
46-
if c == "0":
47-
continue
48-
else:
49-
if c.startswith("-") or (" " in c):
50-
c = "(" + c + ")"
51-
if i == 0:
52-
s.append("%s" % c)
53-
elif i == 1:
54-
if c == "1":
55-
s.append("x")
56-
else:
57-
s.append("%s*x" % c)
58-
else:
59-
if c == "1":
60-
s.append("x^%s" % i)
61-
else:
62-
s.append("%s*x^%s" % (c, i))
63-
return " + ".join(s)
64-
65-
# TODO: why is this template class defining something for
66-
# acb_poly??
67-
# def roots(self, **kwargs):
68-
# """
69-
# Isolates the complex roots of *self*. See :meth:`.acb_poly.roots`
70-
# for details.
71-
# """
72-
# return acb_poly(self).roots(**kwargs)
15+
16+
# TODO:
17+
# We cannot include this class until we can import
18+
# acb_poly, so for now we leave this class as a global
19+
# inside pyflint.pyx
20+
#
21+
# cdef class flint_poly(flint_elem):
22+
# """
23+
# Base class for polynomials.
24+
# """
25+
26+
# def __iter__(self):
27+
# cdef long i, n
28+
# n = self.length()
29+
# for i in range(n):
30+
# yield self[i]
31+
32+
# def coeffs(self):
33+
# return list(self)
34+
35+
# def str(self, bint ascending=False):
36+
# """
37+
# Convert to a human-readable string (generic implementation for
38+
# all polynomial types).
39+
40+
# If *ascending* is *True*, the monomials are output from low degree to
41+
# high, otherwise from high to low.
42+
# """
43+
# coeffs = [str(c) for c in self]
44+
# if not coeffs:
45+
# return "0"
46+
# s = []
47+
# coeffs = enumerate(coeffs)
48+
# if not ascending:
49+
# coeffs = reversed(list(coeffs))
50+
# for i, c in coeffs:
51+
# if c == "0":
52+
# continue
53+
# else:
54+
# if c.startswith("-") or (" " in c):
55+
# c = "(" + c + ")"
56+
# if i == 0:
57+
# s.append("%s" % c)
58+
# elif i == 1:
59+
# if c == "1":
60+
# s.append("x")
61+
# else:
62+
# s.append("%s*x" % c)
63+
# else:
64+
# if c == "1":
65+
# s.append("x^%s" % i)
66+
# else:
67+
# s.append("%s*x^%s" % (c, i))
68+
# return " + ".join(s)
69+
70+
# def roots(self, **kwargs):
71+
# """
72+
# Isolates the complex roots of *self*. See :meth:`.acb_poly.roots`
73+
# for details.
74+
# """
75+
# # TODO:
76+
# # To avoid circular imports, we import within the method
77+
# from XXX.XXX.acb_poly import acb_poly
78+
# return acb_poly(self).roots(**kwargs)
7379

7480
cdef class flint_mpoly(flint_elem):
7581
"""

src/flint/pyflint.pyx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,69 @@ DEF FMPZ_TMP = 2
3333

3434
ctx = thectx
3535

36+
# TODO:
37+
# This should be factored out into flint_base
38+
# but we cannot do this until we can import
39+
# acb_poly to allow the roots() method to remain
40+
41+
from flint.flint_base.flint_base cimport flint_elem
42+
43+
cdef class flint_poly(flint_elem):
44+
"""
45+
Base class for polynomials.
46+
"""
47+
48+
def __iter__(self):
49+
cdef long i, n
50+
n = self.length()
51+
for i in range(n):
52+
yield self[i]
53+
54+
def coeffs(self):
55+
return list(self)
56+
57+
def str(self, bint ascending=False):
58+
"""
59+
Convert to a human-readable string (generic implementation for
60+
all polynomial types).
61+
62+
If *ascending* is *True*, the monomials are output from low degree to
63+
high, otherwise from high to low.
64+
"""
65+
coeffs = [str(c) for c in self]
66+
if not coeffs:
67+
return "0"
68+
s = []
69+
coeffs = enumerate(coeffs)
70+
if not ascending:
71+
coeffs = reversed(list(coeffs))
72+
for i, c in coeffs:
73+
if c == "0":
74+
continue
75+
else:
76+
if c.startswith("-") or (" " in c):
77+
c = "(" + c + ")"
78+
if i == 0:
79+
s.append("%s" % c)
80+
elif i == 1:
81+
if c == "1":
82+
s.append("x")
83+
else:
84+
s.append("%s*x" % c)
85+
else:
86+
if c == "1":
87+
s.append("x^%s" % i)
88+
else:
89+
s.append("%s*x^%s" % (c, i))
90+
return " + ".join(s)
91+
92+
def roots(self, **kwargs):
93+
"""
94+
Isolates the complex roots of *self*. See :meth:`.acb_poly.roots`
95+
for details.
96+
"""
97+
return acb_poly(self).roots(**kwargs)
98+
3699
include "fmpz.pyx"
37100
include "fmpz_poly.pyx"
38101
include "fmpz_mpoly.pyx"

0 commit comments

Comments
 (0)