-
Notifications
You must be signed in to change notification settings - Fork 35
Finish the flint_base submodule, depreciate old roots and factor out more utils
#63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
87082ee
e2904c6
b0a5722
ddf8365
4d8e3ad
4d46c69
f43b291
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| from warnings import warn | ||
|
|
||
| from flint.flint_base.flint_context cimport thectx | ||
|
|
||
| cdef class flint_elem: | ||
|
|
@@ -10,78 +12,78 @@ cdef class flint_elem: | |
| def __str__(self): | ||
| return self.str() | ||
|
|
||
|
|
||
| cdef class flint_scalar(flint_elem): | ||
| pass | ||
|
|
||
| # TODO: | ||
| # We cannot include this class until we can import | ||
| # acb_poly, so for now we leave this class as a global | ||
| # inside pyflint.pyx | ||
| # | ||
| # cdef class flint_poly(flint_elem): | ||
| # """ | ||
| # Base class for polynomials. | ||
| # """ | ||
|
|
||
| # def __iter__(self): | ||
| # cdef long i, n | ||
| # n = self.length() | ||
| # for i in range(n): | ||
| # yield self[i] | ||
|
|
||
| # def coeffs(self): | ||
| # return list(self) | ||
|
|
||
| # def str(self, bint ascending=False): | ||
| # """ | ||
| # Convert to a human-readable string (generic implementation for | ||
| # all polynomial types). | ||
|
|
||
| # If *ascending* is *True*, the monomials are output from low degree to | ||
| # high, otherwise from high to low. | ||
| # """ | ||
| # coeffs = [str(c) for c in self] | ||
| # if not coeffs: | ||
| # return "0" | ||
| # s = [] | ||
| # coeffs = enumerate(coeffs) | ||
| # if not ascending: | ||
| # coeffs = reversed(list(coeffs)) | ||
| # for i, c in coeffs: | ||
| # if c == "0": | ||
| # continue | ||
| # else: | ||
| # if c.startswith("-") or (" " in c): | ||
| # c = "(" + c + ")" | ||
| # if i == 0: | ||
| # s.append("%s" % c) | ||
| # elif i == 1: | ||
| # if c == "1": | ||
| # s.append("x") | ||
| # else: | ||
| # s.append("%s*x" % c) | ||
| # else: | ||
| # if c == "1": | ||
| # s.append("x^%s" % i) | ||
| # else: | ||
| # s.append("%s*x^%s" % (c, i)) | ||
| # return " + ".join(s) | ||
|
|
||
| # def roots(self, **kwargs): | ||
| # """ | ||
| # Isolates the complex roots of *self*. See :meth:`.acb_poly.roots` | ||
| # for details. | ||
| # """ | ||
| # # TODO: | ||
| # # To avoid circular imports, we import within the method | ||
| # from XXX.XXX.acb_poly import acb_poly | ||
| # return acb_poly(self).roots(**kwargs) | ||
|
|
||
|
|
||
| cdef class flint_poly(flint_elem): | ||
| """ | ||
| Base class for polynomials. | ||
| """ | ||
|
|
||
| def __iter__(self): | ||
| cdef long i, n | ||
| n = self.length() | ||
| for i in range(n): | ||
| yield self[i] | ||
|
|
||
| def coeffs(self): | ||
| return list(self) | ||
|
|
||
| def str(self, bint ascending=False): | ||
| """ | ||
| Convert to a human-readable string (generic implementation for | ||
| all polynomial types). | ||
|
|
||
| If *ascending* is *True*, the monomials are output from low degree to | ||
| high, otherwise from high to low. | ||
| """ | ||
| coeffs = [str(c) for c in self] | ||
| if not coeffs: | ||
| return "0" | ||
| s = [] | ||
| coeffs = enumerate(coeffs) | ||
| if not ascending: | ||
| coeffs = reversed(list(coeffs)) | ||
| for i, c in coeffs: | ||
| if c == "0": | ||
| continue | ||
| else: | ||
| if c.startswith("-") or (" " in c): | ||
| c = "(" + c + ")" | ||
| if i == 0: | ||
| s.append("%s" % c) | ||
| elif i == 1: | ||
| if c == "1": | ||
| s.append("x") | ||
| else: | ||
| s.append("%s*x" % c) | ||
| else: | ||
| if c == "1": | ||
| s.append("x^%s" % i) | ||
| else: | ||
| s.append("%s*x^%s" % (c, i)) | ||
| return " + ".join(s) | ||
|
|
||
| def roots(self): | ||
| """ | ||
| Depreciated function. | ||
|
|
||
| To recover roots of a polynomial, first convert to acb: | ||
|
|
||
| acb_poly(input_poly).roots() | ||
| """ | ||
| warn('This method is deprecated. Please instead use acb_poly(input_poly).roots()', DeprecationWarning) | ||
|
|
||
|
|
||
|
Comment on lines
+76
to
+77
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warnings are useful only if we want to preserve existing behaviour while giving out the warning. This does not return the roots that would have previously been returned so existing behaviour is not preserved. I think it is better just to raise an error here rather than give out a warning and implicity return None.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also if giving an error (or not preserving existing behaviour) then it does not really make sense to refer to this as "deprecated": rather it is "unsupported" or "disallowed" or something like that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree, I'll swap this for raise NotImplementedError('This method has been deprecated. Please instead use acb_poly(input_poly).roots()')Example: Jack: python-flint % python3
Python 3.11.4 (main, Jul 25 2023, 17:07:07) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from flint import *
>>> acb_poly([1,2,3]).roots()
[[-0.333333333 +/- 7.53e-10] + [-0.471404521 +/- 7.03e-10]j, [-0.333333333 +/- 7.53e-10] + [0.471404521 +/- 7.03e-10]j]
>>> nmod_poly([1,2,3], 10).roots()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "src/flint/flint_base/flint_base.pyx", line 75, in flint.flint_base.flint_base.flint_poly.roots
raise NotImplementedError('This method has been deprecated. Please instead use acb_poly(input_poly).roots()')
NotImplementedError: This method has been deprecated. Please instead use acb_poly(input_poly).roots()
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also we should add a CHANGELOG section at the bottom of the README with something like:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the simplest thing to do is simply say it's not supported and point to the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| cdef class flint_mpoly(flint_elem): | ||
| """ | ||
| Base class for multivariate polynomials. | ||
| """ | ||
|
|
||
|
|
||
| cdef class flint_series(flint_elem): | ||
| """ | ||
| Base class for power series. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from flint._flint cimport PyTypeObject, PyObject_TypeCheck | ||
|
|
||
| cdef inline bint typecheck(object ob, object tp): | ||
| return PyObject_TypeCheck(ob, <PyTypeObject*>tp) |
Uh oh!
There was an error while loading. Please reload this page.