Skip to content

Commit

Permalink
Trac #24511: Move create_RealField to real_field.py
Browse files Browse the repository at this point in the history
This is part of #24457 but it already makes sense without that ticket to
have the factory function in a separate module.

URL: https://trac.sagemath.org/24511
Reported by: rws
Ticket author(s): Ralf Stephan
Reviewer(s): Vincent Delecroix
  • Loading branch information
Release Manager authored and vbraun committed May 30, 2018
2 parents 714b911 + c02bb43 commit 4c2e232
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 63 deletions.
4 changes: 2 additions & 2 deletions src/sage/rings/qqbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ def completion(self, p, prec, extras = {}):
NotImplementedError
"""
if p == infinity.Infinity:
from sage.rings.real_mpfr import create_RealField
from sage.rings.real_field import create_RealField
return create_RealField(prec, **extras)
else:
raise NotImplementedError
Expand Down Expand Up @@ -1243,7 +1243,7 @@ def completion(self, p, prec, extras = {}):
NotImplementedError
"""
if p == infinity.Infinity:
from sage.rings.real_mpfr import create_RealField
from sage.rings.real_field import create_RealField
return create_RealField(prec, **extras).complex_field()
else:
raise NotImplementedError
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/rational_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def completion(self, p, prec, extras = {}):
"""
from sage.rings.infinity import Infinity
if p == Infinity:
from sage.rings.real_mpfr import create_RealField
from sage.rings.real_field import create_RealField
return create_RealField(prec, **extras)
else:
from sage.rings.padics.factory import Qp
Expand Down
61 changes: 61 additions & 0 deletions src/sage/rings/real_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
def create_RealField(prec=53, type="MPFR", rnd="RNDN", sci_not=0):
"""
Create a real field with given precision, type, rounding mode and
scientific notation.
Some options are ignored for certain types (RDF for example).
INPUT:
- ``prec`` -- a positive integer
- ``type`` -- type of real field:
- ``'RDF'`` -- the Sage real field corresponding to native doubles
- ``'Interval'`` -- real fields implementing interval arithmetic
- ``'RLF'`` -- the real lazy field
- ``'MPFR'`` -- floating point real numbers implemented using the MPFR
library
- ``rnd`` -- rounding mode:
- ``'RNDN'`` -- round to nearest
- ``'RNDZ'`` -- round toward zero
- ``'RNDD'`` -- round down
- ``'RNDU'`` -- round up
- ``sci_not`` -- boolean, whether to use scientific notation for printing
OUTPUT:
the appropriate real field
EXAMPLES::
sage: from sage.rings.real_field import create_RealField
sage: create_RealField(30)
Real Field with 30 bits of precision
sage: create_RealField(20, 'RDF') # ignores precision
Real Double Field
sage: create_RealField(60, 'Interval')
Real Interval Field with 60 bits of precision
sage: create_RealField(40, 'RLF') # ignores precision
Real Lazy Field
"""
if type == "RDF":
from .real_double import RDF
return RDF
elif type == "Interval":
from .real_mpfi import RealIntervalField
return RealIntervalField(prec, sci_not)
elif type == "Ball":
from .real_arb import RealBallField
return RealBallField(prec)
elif type == "RLF":
from .real_lazy import RLF
return RLF
else:
from .real_mpfr import RealField
return RealField(prec, sci_not, rnd)


78 changes: 18 additions & 60 deletions src/sage/rings/real_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5710,66 +5710,6 @@ def create_RealNumber(s, int base=10, int pad=0, rnd="RNDN", int min_prec=53):
return RealLiteral(R, s, base)


# here because this imports the other real fields
def create_RealField(prec=53, type="MPFR", rnd="RNDN", sci_not=0):
"""
Create a real field with given precision, type, rounding mode and
scientific notation.
Some options are ignored for certain types (RDF for example).
INPUT:
- ``prec`` -- a positive integer
- ``type`` -- type of real field:
- ``'RDF'`` -- the Sage real field corresponding to native doubles
- ``'Interval'`` -- real fields implementing interval arithmetic
- ``'RLF'`` -- the real lazy field
- ``'MPFR'`` -- floating point real numbers implemented using the MPFR
library
- ``rnd`` -- rounding mode:
- ``'RNDN'`` -- round to nearest
- ``'RNDZ'`` -- round toward zero
- ``'RNDD'`` -- round down
- ``'RNDU'`` -- round up
- ``sci_not`` -- boolean, whether to use scientific notation for printing
OUTPUT:
the appropriate real field
EXAMPLES::
sage: from sage.rings.real_mpfr import create_RealField
sage: create_RealField(30)
Real Field with 30 bits of precision
sage: create_RealField(20, 'RDF') # ignores precision
Real Double Field
sage: create_RealField(60, 'Interval')
Real Interval Field with 60 bits of precision
sage: create_RealField(40, 'RLF') # ignores precision
Real Lazy Field
"""
if type == "RDF":
return RDF
elif type == "Interval":
from .real_mpfi import RealIntervalField
return RealIntervalField(prec, sci_not)
elif type == "Ball":
from .real_arb import RealBallField
return RealBallField(prec)
elif type == "RLF":
from .real_lazy import RLF
return RLF
else:
return RealField(prec, sci_not, rnd)


def is_RealField(x):
"""
Returns ``True`` if ``x`` is technically of a Python real field type.
Expand Down Expand Up @@ -5968,3 +5908,21 @@ cdef class int_toRR(Map):
raise TypeError("argument cannot be converted to a Python int/long")

return y


def create_RealField(*args, **kwds):
r"""
Deprecated function moved to :mod:`sage.rings.real_field`.
TESTS::
sage: from sage.rings.real_mpfr import create_RealField
sage: create_RealField()
doctest:...: DeprecationWarning: Please import create_RealField from sage.rings.real_field
See http://trac.sagemath.org/24511 for details.
Real Field with 53 bits of precision
"""
from sage.misc.superseded import deprecation
deprecation(24511, "Please import create_RealField from sage.rings.real_field")
from sage.rings.real_field import create_RealField as cr
return cr(*args, **kwds)

0 comments on commit 4c2e232

Please sign in to comment.