Skip to content

Commit

Permalink
Trac #32708: sage.tensor.modules: remove dependency on sage.manifolds
Browse files Browse the repository at this point in the history
In view of Sage modularization, this ticket removes the only import from
`sage.manifolds` in the module `sage.tensor.modules`.
This was an import of `Chart` in `FreeModuleTensor._preparse_display`.
This is avoided by reimplementing `_preparse_display` in
`TensorFieldParal`.

URL: https://trac.sagemath.org/32708
Reported by: egourgoulhon
Ticket author(s): Eric Gourgoulhon
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Oct 23, 2021
2 parents a8e7da2 + 1635bd3 commit 11684c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
32 changes: 32 additions & 0 deletions src/sage/manifolds/differentiable/tensorfield_paral.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
# *****************************************************************************

from sage.tensor.modules.free_module_tensor import FreeModuleTensor
from sage.manifolds.chart import Chart
from sage.manifolds.differentiable.tensorfield import TensorField
from sage.parallel.decorate import parallel
from sage.parallel.parallelism import Parallelism
Expand Down Expand Up @@ -727,6 +728,37 @@ def _del_derived(self, del_restrictions=True):
if del_restrictions:
self._del_restrictions()

def _preparse_display(self, basis=None, format_spec=None):
r"""
Helper function, to be used by FreeModuleTensor.display.
TESTS::
sage: M = Manifold(2, 'M')
sage: X.<x,y> = M.chart()
sage: t = M.tensor_field(1, 1)
sage: t._preparse_display()
(Coordinate frame (M, (∂/∂x,∂/∂y)), None)
sage: t._preparse_display(X.frame())
(Coordinate frame (M, (∂/∂x,∂/∂y)), None)
sage: t._preparse_display(X.frame(), X)
(Coordinate frame (M, (∂/∂x,∂/∂y)), Chart (M, (x, y)))
sage: t._preparse_display(X) # passing a chart instead of a frame
(Coordinate frame (M, (∂/∂x,∂/∂y)), Chart (M, (x, y)))
"""
if basis is None:
basis = self._fmodule._def_basis
elif isinstance(basis, Chart):
# a coordinate chart has been passed instead of a vector frame;
# the frame is then assumed to be the coordinate frame
# associated to the chart:
if format_spec is None:
format_spec = basis
basis = basis.frame()
return (basis, format_spec)


def _set_comp_unsafe(self, basis=None):
r"""
Return the components of the tensor field in a given vector frame
Expand Down
11 changes: 0 additions & 11 deletions src/sage/tensor/modules/free_module_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ class being:
from sage.tensor.modules.tensor_with_indices import TensorWithIndices
from sage.parallel.decorate import parallel
from sage.parallel.parallelism import Parallelism
from sage.manifolds.chart import Chart

# TODO: remove the import of Chart after _preparse_display has been redefined
# in tensor fields

class FreeModuleTensor(ModuleElementWithMutability):
r"""
Expand Down Expand Up @@ -583,13 +579,6 @@ def _preparse_display(self, basis=None, format_spec=None):
"""
if basis is None:
basis = self._fmodule._def_basis
elif isinstance(basis, Chart):
# a coordinate chart has been passed instead of a basis;
# the basis is then assumed to be the coordinate frame
# associated to the chart:
if format_spec is None:
format_spec = basis
basis = basis.frame()
return (basis, format_spec)

def display(self, basis=None, format_spec=None):
Expand Down

0 comments on commit 11684c2

Please sign in to comment.