Skip to content
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

Replace imports from sage.all #123

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3fee3f1
Replace imports from sage.all
mkoeppe Oct 29, 2024
0ced6af
python/snap/polished_reps.py: Use try..except for imports from Sage
mkoeppe Oct 31, 2024
e60fb8d
src/snappy/verify/upper_halfspace/finite_point.py: Use try..except fo…
mkoeppe Nov 1, 2024
029a047
python/snap/polished_reps.py: Move try..except for imports to sage_he…
mkoeppe Nov 1, 2024
77efeac
python/number.py: Go through .sage_helper instead of sage.all
mkoeppe Nov 1, 2024
72721d6
python/verify/upper_halfspace/finite_point.py: Go through sage_helper…
mkoeppe Nov 1, 2024
8f21e9f
python/sage_helper.py: Fix for is_RealIntervalFieldElement
mkoeppe Nov 1, 2024
30a2efa
python/verify/upper_halfspace/ideal_point.py: Go through sage_helper
mkoeppe Nov 1, 2024
0ddfa37
python/number.py: If SR cannot be imported, just do not register a co…
mkoeppe Nov 1, 2024
32555f9
python/verify/hyperbolicity.py: Go through sage_helper
mkoeppe Nov 1, 2024
58bd6e4
python/cusps/maximal_cusp_area_matrix.py: Go through sage_helper
mkoeppe Nov 1, 2024
5d234f3
python/hyperboloid/distances.py: Go through sage_helper
mkoeppe Nov 1, 2024
2e2e02b
python/tiling/tile.py: Go through sage_helper
mkoeppe Nov 1, 2024
3fea8b1
python/verify/complex_volume/adjust_torsion.py: Go through sage_helper
mkoeppe Nov 1, 2024
0d97472
python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py: Go thro…
mkoeppe Nov 1, 2024
95327e4
python/verify/upper_halfspace/finite_point.py: Go through sage_helper
mkoeppe Nov 1, 2024
7bd05d3
python/pari.py: Use try..except for import of PariError
mkoeppe Nov 1, 2024
b305331
python/number.py: If SR cannot be imported, just do not register a co…
mkoeppe Nov 1, 2024
bf1628f
python/verify/complex_volume/extended_bloch.py: Go through sage_helper
mkoeppe Nov 1, 2024
269d31a
python/verify/complex_volume/cusped.py: Go through sage_helper
mkoeppe Nov 1, 2024
9dcede5
python/upper_halfspace/__init__.py: Go through sage_helper for arccosh
mkoeppe Nov 1, 2024
f97e4b4
python/database.py: Go through sage_helper
mkoeppe Nov 1, 2024
76826d0
Use 'from sage.symbolic.constants import pi'
mkoeppe Nov 1, 2024
515730d
python/verify/complex_volume/closed.py: Go through sage_helper
mkoeppe Nov 1, 2024
6bf03b9
cython/core/fundamental_group.pyx: Use import
mkoeppe Nov 1, 2024
c14a53c
python/testing.py: Use import
mkoeppe Nov 1, 2024
cba8112
cython/core/abelian_group.pyx: Use import
mkoeppe Nov 1, 2024
92ab31b
cython/core/basic.pyx: Remove .all import
mkoeppe Nov 1, 2024
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
3 changes: 2 additions & 1 deletion cython/core/abelian_group.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ cdef class AbelianGroup():
'as a sequence.')
int_types = [int]
if _within_sage:
int_types += [sage.rings.integer.Integer]
from sage.rings.integer import Integer
int_types += [Integer]
for c in self.divisors:
assert type(c) in int_types and c >= 0,\
'Elementary divisors must be non-negative integers.\n'
Expand Down
1 change: 0 additions & 1 deletion cython/core/basic.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ python_major_version = sys.version_info.major
from .sage_helper import _within_sage, SageNotAvailable
from .pari import pari as pari
try:
import sage.all
import sage.structure.sage_object
from sage.groups.perm_gps.permgroup_element import is_PermutationGroupElement
from sage.groups.perm_gps.permgroup import PermutationGroup
Expand Down
6 changes: 4 additions & 2 deletions cython/core/fundamental_group.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ class FundamentalGroup(CFundamentalGroup):


if _within_sage:
FundamentalGroup.__bases__ += (sage.structure.sage_object.SageObject,)
from sage.structure.sage_object import SageObject
FundamentalGroup.__bases__ += (SageObject,)


# Holonomy Groups
Expand Down Expand Up @@ -594,4 +595,5 @@ class HolonomyGroup(CHolonomyGroup):


if _within_sage:
HolonomyGroup.__bases__ += (sage.structure.sage_object.SageObject,)
from sage.structure.sage_object import SageObject
HolonomyGroup.__bases__ += (SageObject,)
2 changes: 1 addition & 1 deletion dev/drilling/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from snappy.drilling import exceptions
from snappy.drilling import perturb

from sage.all import pi
from sage.symbolic.constants import pi

# perturb._tube_developing_radius = 1

Expand Down
2 changes: 1 addition & 1 deletion dev/drilling/smoke_test2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from snappy.drilling import exceptions
from snappy.drilling import perturb

from sage.all import pi
from sage.symbolic.constants import pi

# perturb._tube_developing_radius = 1

Expand Down
6 changes: 3 additions & 3 deletions python/cusps/maximal_cusp_area_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..hyperboloid.distances import distance_r13_horoballs

if _within_sage:
import sage.all
from ..sage_helper import Infinity

def maximal_cusp_area_matrix(manifold, bits_prec, verified):
"""
Expand Down Expand Up @@ -63,7 +63,7 @@ def _diagonal_scale(mcomplex, i):
return e ** 2

if mcomplex.verified:
d = mcomplex.RF(sage.all.Infinity)
d = mcomplex.RF(Infinity)
else:
d = mcomplex.RF(1e20)

Expand Down Expand Up @@ -93,7 +93,7 @@ def _non_diagonal_scale(mcomplex, i, j):
return e ** 2

if mcomplex.verified:
d = mcomplex.RF(sage.all.Infinity)
d = mcomplex.RF(Infinity)
else:
d = mcomplex.RF(1e20)

Expand Down
10 changes: 5 additions & 5 deletions python/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
import collections

if _within_sage:
import sage.all
from .sage_helper import Integer, RealDoubleElement, RealNumber

def is_int(slice):
return isinstance(slice, (sage.all.Integer, int))
return isinstance(slice, (Integer, int))

def is_int_or_none(slice):
return isinstance(slice, (sage.all.Integer, int, type(None)))
return isinstance(slice, (Integer, int, type(None)))

def is_float_or_none(slice):
return isinstance(slice, (float, sage.all.RealDoubleElement,
sage.rings.real_mpfr.RealNumber, type(None)))
return isinstance(slice, (float, RealDoubleElement,
RealNumber, type(None)))
else:
def is_int(slice):
return isinstance(slice, int)
Expand Down
6 changes: 5 additions & 1 deletion python/exterior_to_link/rational_linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
from .. import sage_helper

if sage_helper._within_sage and not use_pari_even_inside_sage:
from sage.all import QQ, RR, vector, matrix, VectorSpace
from sage.rings.rational_field import Q as QQ
from sage.rings.real_mpfr import RR
from sage.modules.free_module_element import free_module_element as vector
from sage.matrix.constructor import Matrix as matrix
from sage.modules.free_module import VectorSpace

def rational_sqrt(x):
"""
Expand Down
5 changes: 4 additions & 1 deletion python/exterior_to_link/rational_linear_algebra_wrapped.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
This file is not currently used by SnapPy, but is kept for possible
future reference.
"""
from sage.all import QQ, vector, matrix, VectorSpace
from sage.rings.rational_field import Q as QQ
from sage.modules.free_module_element import free_module_element as vector
from sage.matrix.constructor import Matrix as matrix
from sage.modules.free_module import VectorSpace


class Vector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ def _add_one_cusp_vertex_positions(self, cusp : t3m.Vertex):
visited.add((tet1.Index, vert1))

def _debug_show_horotriangles(self, cusp : int =0):
from sage.all import line, real, imag
from sage.plot.line import line
from sage.functions.other import real
from sage.functions.other import imag

self.add_vertex_positions_to_horotriangles()

Expand All @@ -398,7 +400,9 @@ def _debug_show_horotriangles(self, cusp : int =0):
if tet.Class[V].Index == cusp ])

def _debug_show_lifted_horotriangles(self, cusp : int =0):
from sage.all import line, real, imag
from sage.plot.line import line
from sage.functions.other import real
from sage.functions.other import imag

self.add_vertex_positions_to_horotriangles()

Expand Down
14 changes: 7 additions & 7 deletions python/hyperboloid/distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..sage_helper import _within_sage # type: ignore

if _within_sage:
import sage.all # type: ignore
from ..sage_helper import Infinity

__all__ = ['distance_r13_lines',
'lower_bound_distance_r13_line_triangle']
Expand Down Expand Up @@ -183,7 +183,7 @@ def _safe_sqrt(p):

if is_RealIntervalFieldElement(p):
RIF = p.parent()
p = p.intersection(RIF(0, sage.all.Infinity))
p = p.intersection(RIF(0, Infinity))
else:
if p < 0:
RF = p.parent()
Expand All @@ -193,7 +193,7 @@ def _safe_sqrt(p):
def _safe_log(p):
if is_RealIntervalFieldElement(p):
RIF = p.parent()
p = p.intersection(RIF(0, sage.all.Infinity))
p = p.intersection(RIF(0, Infinity))
else:
if p <= 0:
RF = p.parent()
Expand All @@ -207,7 +207,7 @@ def _safe_log_non_neg(p):
if p == 0:
if is_RealIntervalFieldElement(p):
RIF = p.parent()
return RIF(-sage.all.Infinity)
return RIF(-Infinity)
else:
RF = p.parent()
return RF(-1e20)
Expand All @@ -217,7 +217,7 @@ def _safe_log_non_neg(p):
def _safe_arccosh(p):
if is_RealIntervalFieldElement(p):
RIF = p.parent()
p = p.intersection(RIF(1, sage.all.Infinity))
p = p.intersection(RIF(1, Infinity))
else:
if p < 1:
RF = p.parent()
Expand All @@ -233,9 +233,9 @@ def _safe_div(a, b):
if is_RealIntervalFieldElement(b):
RIF = b.parent()
if b == 0:
return RIF(sage.all.Infinity)
return RIF(Infinity)
else:
return a / b.intersection(RIF(0, sage.all.Infinity))
return a / b.intersection(RIF(0, Infinity))
else:
if b <= 0:
RIF = b.parent()
Expand Down
3 changes: 2 additions & 1 deletion python/math_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def is_Interval(x):
return is_RealIntervalFieldElement(x) or is_ComplexIntervalFieldElement(x)

if _within_sage:
from sage.all import prod, xgcd
from sage.misc.misc_c import prod
from sage.arith.misc import XGCD as xgcd
from sage.rings.real_mpfi import is_RealIntervalFieldElement
from sage.rings.complex_interval import is_ComplexIntervalFieldElement

Expand Down
11 changes: 8 additions & 3 deletions python/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
precision_of_exact_GEN = pari(0).precision()

if _within_sage:
from sage.all import RealField, Integer, Rational, ZZ, QQ, RR, CC, SR
from .sage_helper import RealField, Integer, Rational, ZZ, QQ, RR, CC
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.categories.homset import Hom
Expand Down Expand Up @@ -66,8 +66,13 @@ def __init__(self, precision):
self._precision = precision
self.register_coercion(MorphismToSPN(ZZ, self, self._precision))
self.register_coercion(MorphismToSPN(QQ, self, self._precision))
to_SR = Hom(self, SR, Sets())(lambda x: SR(x.sage()))
SR.register_coercion(to_SR)
try:
from sage.symbolic.ring import SR
except ImportError:
pass
else:
to_SR = Hom(self, SR, Sets())(lambda x: SR(x.sage()))
SR.register_coercion(to_SR)

def _repr_(self):
return "SnapPy Numbers with %s bits precision" % self._precision
Expand Down
6 changes: 5 additions & 1 deletion python/pari.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
prec_words_to_bits,
prec_bits_to_dec,
prec_dec_to_bits)
from sage.all import PariError
try:
from sage.all import PariError
except ImportError:
from sage.libs.pari.all import PariError

shut_up = lambda: None
speak_up = lambda: None

Expand Down
34 changes: 33 additions & 1 deletion python/sage_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

try:
import sage.all
import sage.structure.sage_object
_within_sage = True
except ImportError:
_within_sage = False
Expand All @@ -30,6 +30,38 @@ def sage_method(function):
from sage.rings.complex_field import ComplexField, ComplexField_class
from sage.rings.complex_number import create_ComplexNumber

try:
# Monolithic Sage library
from sage.all import RealField, RealNumber, RealDoubleElement, ComplexField, gcd, prod, powerset
from sage.all import MatrixSpace, matrix, vector, ZZ
from sage.all import Integer, Rational, QQ, RR, CC
from sage.all import sqrt
from sage.all import I, Infinity
from sage.all import arccosh
except ImportError:
# Modularized Sage library
from sage.arith.misc import gcd
from sage.combinat.subset import powerset
from sage.functions.hyperbolic import arccosh
from sage.matrix.constructor import Matrix as matrix
from sage.matrix.matrix_space import MatrixSpace
from sage.misc.functional import sqrt
from sage.misc.misc_c import prod
from sage.modules.free_module_element import free_module_element as vector
from sage.rings.cc import CC
from sage.rings.complex_mpfr import ComplexField
from sage.rings.imaginary_unit import I
from sage.rings.infinity import Infinity
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.rings.rational import Rational
from sage.rings.rational_field import QQ
from sage.rings.real_double import RealDoubleElement
from sage.rings.real_mpfr import RealField, RealNumber, RR

from sage.rings.real_mpfi import is_RealIntervalFieldElement
from sage.structure.sage_object import SageObject

else:
import decorator

Expand Down
3 changes: 2 additions & 1 deletion python/snap/character_varieties.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ def character_variety_ideal(gens, rels=None):
2
"""
presentation = character_variety(gens, rels)
from sage.all import PolynomialRing, QQ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.rational_field import Q as QQ
R = PolynomialRing(QQ, [repr(v) for v in presentation.gens])
return R.ideal([R(p) for p in presentation.rels])

Expand Down
18 changes: 15 additions & 3 deletions python/snap/find_field.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from sage.all import (cached_method, real_part, imag_part, round, ceil, floor, log,
ZZ, QQ, CDF, ComplexField, NumberField, PolynomialRing,
matrix, identity_matrix)
from sage.misc.cachefunc import cached_method
from sage.functions.other import real as real_part
from sage.functions.other import imag as imag_part
from sage.misc.functional import round
from sage.functions.other import ceil
from sage.functions.other import floor
from sage.misc.functional import log
from sage.rings.integer_ring import Z as ZZ
from sage.rings.rational_field import Q as QQ
from sage.rings.complex_double import CDF
from sage.rings.complex_mpfr import ComplexField
from sage.rings.number_field.number_field import NumberField
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.matrix.constructor import Matrix as matrix
from sage.matrix.special import identity_matrix
import itertools


Expand Down
2 changes: 1 addition & 1 deletion python/snap/fundamental_polyhedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from ..sage_helper import _within_sage
if _within_sage:
from sage.all import matrix
from sage.matrix.constructor import Matrix as matrix
else:
from .utilities import Matrix2x2 as matrix

Expand Down
17 changes: 14 additions & 3 deletions python/snap/nsagetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@

if _within_sage:
import sage
from sage.all import (ZZ, vector, matrix, block_matrix, identity_matrix,
gcd, prod, det, MatrixSpace, AbelianGroup, GroupAlgebra,
SageObject, PolynomialRing, LaurentPolynomialRing)
from sage.rings.integer_ring import Z as ZZ
from sage.modules.free_module_element import free_module_element as vector
from sage.matrix.constructor import Matrix as matrix
from sage.matrix.special import block_matrix
from sage.matrix.special import identity_matrix
from sage.arith.misc import GCD as gcd
from sage.misc.misc_c import prod
from sage.misc.functional import det
from sage.matrix.matrix_space import MatrixSpace
from sage.groups.abelian_gps.abelian_group import AbelianGroup
from sage.algebras.group_algebra import GroupAlgebra
from sage.structure.sage_object import SageObject
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing

from .polished_reps import polished_holonomy, MatrixRepresentation
Id2 = MatrixSpace(ZZ, 2)(1)
Expand Down
6 changes: 5 additions & 1 deletion python/snap/peripheral/dual_cellulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from .. import t3mlite as t3m

if sage_helper._within_sage:
from sage.all import (ZZ, matrix, vector, ChainComplex, Graph)
from sage.rings.integer_ring import Z as ZZ
from sage.matrix.constructor import Matrix as matrix
from sage.modules.free_module_element import free_module_element as vector
from sage.homology.chain_complex import ChainComplex
from sage.graphs.graph import Graph


class DualCell():
Expand Down
4 changes: 3 additions & 1 deletion python/snap/peripheral/peripheral.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from . import link, dual_cellulation

if sage_helper._within_sage:
from sage.all import matrix, vector, ZZ
from sage.matrix.constructor import Matrix as matrix
from sage.modules.free_module_element import free_module_element as vector
from sage.rings.integer_ring import Z as ZZ


def peripheral_curve_from_snappy(dual_cell, snappy_data):
Expand Down
Loading
Loading