sagemath/sage

sage.arith: Use sage.rings.abc and move some module-level imports into methods

Closed this issue · 9 comments

(cherry-picked from #32432)

Depends on #32566

CC: @tscrim

Component: refactoring

Author: Matthias Koeppe

Branch/Commit: 5e5843a

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/32600

Changed dependencies from #32566: to #32566

New commits:

cee081asage.rings.real_mpfr.RealField_class: Inherit through a new class sage.rings.abc.RealField
99f4f10sage.rings.real_double.RealDoubleField_class: Inherit through a new class sage.rings.abc.RealDoubleField
29871d0ComplexField_class, ComplexDoubleField: Inherit through new classes sage.rings.abc.*
e1bb944src/sage/rings/polynomial/polynomial_element.pyx: Replace use of is_RealField by isinstance(sage.rings.abc.RealField) etc.
6e2c3c4src/sage/rings/abc.pyx: Add class docstrings
2bd66e4Merge #32566
4e2f0absrc/sage/arith/misc.py: move pari/flint imports into methods
5145d43src/sage/arith/misc.py: Use sage.rings.abc instead of importing element classes RealNumber, ComplexNumber
5e5843asage.arith.misc: Fixup

Commit: 5e5843a

Author: Matthias Koeppe

comment:5

While it's not an issue here since it is not the main part of the algorithm, changes like this do incur a slight performance penalty:

-    if isinstance(z, (RealNumber, ComplexNumber)):
+    if isinstance(z.parent(), (RealField, ComplexField)):

This is just for future reference.

Reviewer: Travis Scrimshaw

comment:6

Thanks! I agree with your analysis.