From cbbef94efbbe8feedcc2d07da5fd6caf5a01b74e Mon Sep 17 00:00:00 2001 From: Nathan Dunfield Date: Sun, 19 Jan 2025 18:42:07 -0600 Subject: [PATCH] Get rid of more SageMath DeprecationWarnings --- python/exterior_to_link/barycentric_geometry.py | 4 ++-- python/exterior_to_link/rational_linear_algebra.py | 7 +++++++ python/sage_helper.py | 2 +- python/verify/upper_halfspace/finite_point.py | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/python/exterior_to_link/barycentric_geometry.py b/python/exterior_to_link/barycentric_geometry.py index bd7381c2..e1708947 100644 --- a/python/exterior_to_link/barycentric_geometry.py +++ b/python/exterior_to_link/barycentric_geometry.py @@ -5,7 +5,7 @@ """ from ..snap.t3mlite.simplex import * -from .rational_linear_algebra import Matrix, Vector3, Vector4 +from .rational_linear_algebra import Matrix, Vector3, Vector4, rational_round from . import pl_utils @@ -185,7 +185,7 @@ def round(self, max_denom=2**32, force=False): v = [] for y in max_denom * self.vector: if y != 0: - y = max(y.round(), 1) + y = max(rational_round(y), 1) v.append(y) # Should be just Vector4(v)/sum(v) diff --git a/python/exterior_to_link/rational_linear_algebra.py b/python/exterior_to_link/rational_linear_algebra.py index c63825f2..8a3d1ab8 100644 --- a/python/exterior_to_link/rational_linear_algebra.py +++ b/python/exterior_to_link/rational_linear_algebra.py @@ -19,6 +19,10 @@ if sage_helper._within_sage and not use_pari_even_inside_sage: from ..sage_helper import QQ, RR, vector, matrix, VectorSpace + def rational_round(x): + # This is just to suppress a deprecation warning. + return x.round(mode='even') + def rational_sqrt(x): """ Given a nonnegative rational x, return a rational r which is close to @@ -58,6 +62,9 @@ def Matrix(entries): from ..snap.t3mlite import linalg QQ = linalg.pari + def rational_round(x): + return x.round() + def rational_sqrt(x): """ Given a nonnegative rational x, return a rational r which is close to diff --git a/python/sage_helper.py b/python/sage_helper.py index 95aa7854..bcf51abb 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -81,7 +81,7 @@ def sage_method(function): from sage.rings.real_mpfr import RealField, RealNumber, RR from sage.rings.complex_interval_field import ComplexIntervalField - from sage.rings.real_mpfi import is_RealIntervalFieldElement, RealIntervalField + from sage.rings.real_mpfi import RealIntervalFieldElement, RealIntervalField from sage.rings.real_mpfr import RealNumber, RealField_class from sage.structure.sage_object import SageObject diff --git a/python/verify/upper_halfspace/finite_point.py b/python/verify/upper_halfspace/finite_point.py index 0920b4c5..0afdc13b 100644 --- a/python/verify/upper_halfspace/finite_point.py +++ b/python/verify/upper_halfspace/finite_point.py @@ -2,7 +2,7 @@ if _within_sage: import sage - from ...sage_helper import matrix, sqrt, is_RealIntervalFieldElement, Infinity + from ...sage_helper import matrix, sqrt, RealIntervalFieldElement, Infinity from .extended_matrix import ExtendedMatrix @@ -167,7 +167,7 @@ def cosh_dist(self, other): # RIF = r.parent() if _within_sage: - if is_RealIntervalFieldElement(r): + if isinstance(r, RealIntervalFieldElement): return r.intersection(RIF(1, Infinity)) if r < 1.0: return RIF(1.0)