Skip to content

Commit

Permalink
Replace imports from sage.all
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Oct 29, 2024
1 parent bb3f498 commit 2462dfb
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 45 deletions.
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
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
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
10 changes: 8 additions & 2 deletions python/snap/peripheral/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
from ... import sage_helper

if sage_helper._within_sage:
from sage.all import (ZZ, matrix, vector, ChainComplex,
cached_method, line, arrow, text)
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.misc.cachefunc import cached_method
from sage.plot.line import line
from sage.plot.arrow import arrow
from sage.plot.text import text
else:
def cached_method(func):
return func
Expand Down
11 changes: 9 additions & 2 deletions python/snap/polished_reps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@

if _within_sage:
import sage
from sage.all import RealField, ComplexField, gcd, prod, powerset
from sage.all import MatrixSpace, matrix, vector, ZZ
from sage.rings.real_mpfr import RealField
from sage.rings.complex_mpfr import ComplexField
from sage.arith.misc import GCD as gcd
from sage.misc.misc_c import prod
from sage.combinat.subset import powerset
from sage.matrix.matrix_space import MatrixSpace
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
Object = sage.structure.sage_object.SageObject
identity = lambda A: MatrixSpace(A.base_ring(), A.nrows())(1)
abelian_group_elt = lambda v: vector(ZZ, v)
Expand Down
16 changes: 12 additions & 4 deletions python/snap/slice_obs_HKL.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@

from ..sage_helper import _within_sage, sage_method
if _within_sage:
from sage.all import (ZZ, PolynomialRing, LaurentPolynomialRing,
GF, CyclotomicField, vector, matrix,
identity_matrix, block_matrix,
MatrixSpace, ChainComplex, prime_range)
from sage.rings.integer_ring import Z as ZZ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
from sage.rings.number_field.number_field import CyclotomicField
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 identity_matrix
from sage.matrix.special import block_matrix
from sage.matrix.matrix_space import MatrixSpace
from sage.homology.chain_complex import ChainComplex
from sage.rings.fast_arith import prime_range

from .nsagetools import (MapToFreeAbelianization, compute_torsion,
fox_derivative_with_involution,
Expand Down
6 changes: 3 additions & 3 deletions python/snap/t3mlite/spun.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

from ...sage_helper import _within_sage
if _within_sage:
from sage.all import gcd
from sage.all import vector as Vector
from sage.all import matrix as Matrix
from sage.arith.misc import GCD as gcd
from sage.modules.free_module_element import free_module_element as Vector
from sage.matrix.constructor import Matrix as Matrix
else:
from snappy.snap.t3mlite.linalg import Vector, Matrix, gcd

Expand Down
3 changes: 2 additions & 1 deletion python/snap/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from ..pari import pari, PariError
from .fundamental_polyhedron import Infinity
if _within_sage:
from sage.all import matrix as sage_matrix, vector as sage_vector
from sage.matrix.constructor import Matrix as sage_matrix
from sage.modules.free_module_element import free_module_element as sage_vector
from sage.rings.real_mpfr import RealField_class
from ..sage_helper import ComplexField_class

Expand Down
2 changes: 1 addition & 1 deletion python/verify/complex_volume/adjust_torsion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ...sage_helper import _within_sage, sage_method
if _within_sage:
from sage.all import pi
from sage.symbolic.constants import pi
import sage.all

from .extended_bloch import *
Expand Down
3 changes: 2 additions & 1 deletion python/verify/complex_volume/closed.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from ...snap.t3mlite import simplex

if _within_sage:
from sage.all import pi, xgcd
from sage.symbolic.constants import pi
from sage.arith.misc import XGCD as xgcd
import sage.all

from .. import hyperbolicity
Expand Down
8 changes: 5 additions & 3 deletions python/verify/complex_volume/extended_bloch.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from ...sage_helper import _within_sage, sage_method

if _within_sage:
from sage.all import (ComplexBallField,
RealField,
Integer, exp, pi)
from sage.rings.complex_arb import ComplexBallField
from sage.rings.real_mpfr import RealField
from sage.rings.integer import Integer
from sage.functions.log import exp
from sage.symbolic.constants import pi

import sage.all

Expand Down
2 changes: 1 addition & 1 deletion python/verify/hyperbolicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'verify_hyperbolicity' ]

if _within_sage:
from sage.all import pi
from sage.symbolic.constants import pi
import sage.all


Expand Down
8 changes: 5 additions & 3 deletions python/verify/interval_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ def check_find_result(self, interval):
self.brute_force_find(interval)))

def check_consistency(self):
from sage.all import Infinity
from sage.rings.infinity import Infinity
if self._root.isRed:
raise Exception("Red root")
_IntervalTreeTester._recursively_check_consistency(
self._root, -Infinity, +Infinity)

@staticmethod
def _recursively_check_consistency(node, l, r):
from sage.all import Infinity
from sage.rings.infinity import Infinity

if not node:
return -Infinity, 0
Expand Down Expand Up @@ -370,7 +370,9 @@ def print_tree_recursively(node, depth):

@staticmethod
def run_test():
from sage.all import RIF, sin, Infinity
from sage.rings.real_mpfi import RIF
from sage.functions.trig import sin
from sage.rings.infinity import Infinity

intervals = [
RIF(sin(1.2 * i), sin(1.2 * i) + sin(1.43 * i) ** 2)
Expand Down
2 changes: 1 addition & 1 deletion python/verify/krawczyk_shapes_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if _within_sage:
from sage.rings.complex_interval_field import ComplexIntervalField
from sage.rings.real_mpfi import RealIntervalField
from sage.all import ComplexDoubleField
from sage.rings.complex_double import ComplexDoubleField
from snappy.pari import prec_dec_to_bits

__all__ = ['KrawczykShapesEngine']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .cusp_translate_engine import *

if _within_sage:
from sage.all import matrix
from sage.matrix.constructor import Matrix as matrix
import sage.all

import heapq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from ..upper_halfspace.finite_point import *

if _within_sage:
from sage.all import vector, matrix
from sage.modules.free_module_element import free_module_element as vector
from sage.matrix.constructor import Matrix as matrix

__all__ = ['CuspTranslateEngine']

Expand Down
2 changes: 1 addition & 1 deletion python/verify/short_slopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import math

if _within_sage:
from sage.all import gcd
from sage.arith.misc import GCD as gcd
else:
# Python 3 has gcd in math
from math import gcd
Expand Down
2 changes: 1 addition & 1 deletion python/verify/upper_halfspace/extended_matrix.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ...sage_helper import _within_sage

if _within_sage:
from sage.all import sqrt
from sage.misc.functional import sqrt

__all__ = ['ExtendedMatrix']

Expand Down
3 changes: 2 additions & 1 deletion python/verify/upper_halfspace/finite_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

if _within_sage:
import sage.all
from sage.all import matrix, sqrt
from sage.matrix.constructor import Matrix as matrix
from sage.misc.functional import sqrt
from sage.rings.real_mpfi import is_RealIntervalFieldElement

from .extended_matrix import ExtendedMatrix
Expand Down
9 changes: 6 additions & 3 deletions python/verify/upper_halfspace/ideal_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

if _within_sage:
import sage.all
from sage.all import matrix
from sage.matrix.constructor import Matrix as matrix

from .finite_point import *
from .extended_matrix import *
Expand Down Expand Up @@ -398,7 +398,9 @@ class _IdealPointTester():
"""

def matrices(self):
from sage.all import RIF, CIF, matrix
from sage.rings.real_mpfi import RIF
from sage.rings.cif import CIF
from sage.matrix.constructor import Matrix as matrix

return [
matrix.identity(CIF, 2),
Expand All @@ -410,7 +412,8 @@ def matrices(self):
[CIF(RIF(-0.3), RIF(1.1)), CIF(1)]]) ]

def run_tests(self):
from sage.all import RIF, CIF
from sage.rings.real_mpfi import RIF
from sage.rings.cif import CIF

bias = RIF(1.5)

Expand Down

0 comments on commit 2462dfb

Please sign in to comment.