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

Add typing to tangent vectors #35189

Merged
merged 3 commits into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 19 additions & 5 deletions src/sage/manifolds/differentiable/diff_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@
# the License, or (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations

from typing import TYPE_CHECKING

from sage.manifolds.continuous_map import ContinuousMap
from sage.parallel.decorate import parallel
from sage.parallel.parallelism import Parallelism

if TYPE_CHECKING:
from sage.manifolds.point import ManifoldPoint
from sage.tensor.modules.free_module_morphism import FiniteRankFreeModuleMorphism

class DiffMap(ContinuousMap):
r"""
Expand Down Expand Up @@ -515,7 +521,7 @@ def _del_derived(self):
# class
self._diff.clear()

def differential(self, point):
def differential(self, point: ManifoldPoint) -> FiniteRankFreeModuleMorphism:
r"""
Return the differential of ``self`` at a given point.

Expand Down Expand Up @@ -949,8 +955,12 @@ def pullback(self, tensor_or_codomain_subset, name=None, latex_name=None):
tensor = tensor_or_codomain_subset

from sage.manifolds.differentiable.tensorfield_paral import TensorFieldParal
from sage.tensor.modules.comp import (Components, CompWithSym,
CompFullySym, CompFullyAntiSym)
from sage.tensor.modules.comp import (
CompFullyAntiSym,
CompFullySym,
Components,
CompWithSym,
)

def _pullback_chart(diff_map, tensor, chart1, chart2):
r"""
Expand Down Expand Up @@ -1195,9 +1205,13 @@ def pushforward(self, tensor):
Psi_*(u) = -sin(t) βˆ‚/βˆ‚x + cos(t) βˆ‚/βˆ‚y + βˆ‚/βˆ‚z

"""
from sage.tensor.modules.comp import (Components, CompWithSym,
CompFullySym, CompFullyAntiSym)
from sage.manifolds.differentiable.tensorfield_paral import TensorFieldParal
from sage.tensor.modules.comp import (
CompFullyAntiSym,
CompFullySym,
Components,
CompWithSym,
)
vmodule = tensor.base_module()
dest_map = vmodule.destination_map()
dom1 = tensor.domain()
Expand Down
8 changes: 5 additions & 3 deletions src/sage/manifolds/differentiable/scalarfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
#******************************************************************************

from __future__ import annotations
from typing import Union, TYPE_CHECKING

from typing import TYPE_CHECKING, Union

from sage.manifolds.scalarfield import ScalarField

if TYPE_CHECKING:
from sage.manifolds.differentiable.diff_form import DiffForm
from sage.manifolds.differentiable.symplectic_form import SymplecticForm
from sage.manifolds.differentiable.metric import PseudoRiemannianMetric
from sage.manifolds.differentiable.symplectic_form import SymplecticForm


class DiffScalarField(ScalarField):
Expand Down Expand Up @@ -713,7 +715,7 @@ def tensor_type(self):
"""
return self._tensor_type

def differential(self):
def differential(self) -> DiffForm:
r"""
Return the differential of ``self``.

Expand Down
10 changes: 8 additions & 2 deletions src/sage/manifolds/differentiable/tangent_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#******************************************************************************
from __future__ import annotations

from typing import TYPE_CHECKING

from sage.manifolds.differentiable.tangent_vector import TangentVector
from sage.symbolic.ring import SR
from sage.tensor.modules.finite_rank_free_module import FiniteRankFreeModule
from sage.manifolds.differentiable.tangent_vector import TangentVector

if TYPE_CHECKING:
from sage.manifolds.point import ManifoldPoint

class TangentSpace(FiniteRankFreeModule):
r"""
Expand Down Expand Up @@ -222,7 +228,7 @@ class TangentSpace(FiniteRankFreeModule):
"""
Element = TangentVector

def __init__(self, point, base_ring=None):
def __init__(self, point: ManifoldPoint, base_ring=None):
r"""
Construct the tangent space at a given point.

Expand Down
3 changes: 2 additions & 1 deletion src/sage/manifolds/differentiable/tensorfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from sage.manifolds.differentiable.poisson_tensor import PoissonTensorField
from sage.manifolds.differentiable.symplectic_form import SymplecticForm
from sage.manifolds.differentiable.vectorfield_module import VectorFieldModule
from sage.manifolds.point import ManifoldPoint
from sage.tensor.modules.comp import Components


Expand Down Expand Up @@ -3634,7 +3635,7 @@ def lie_derivative(self, vector):

lie_der = lie_derivative

def at(self, point):
def at(self, point: ManifoldPoint) -> FreeModuleTensor:
r"""
Value of ``self`` at a point of its domain.

Expand Down
21 changes: 18 additions & 3 deletions src/sage/tensor/modules/free_module_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@
# http://www.gnu.org/licenses/
#******************************************************************************

from __future__ import annotations

from typing import TYPE_CHECKING, Optional

from sage.tensor.modules.alternating_contr_tensor import AlternatingContrTensor
from sage.tensor.modules.comp import Components

if TYPE_CHECKING:
from sage.tensor.modules.finite_rank_free_module import FiniteRankFreeModule
from sage.tensor.modules.free_module_basis import FreeModuleBasis


class FiniteRankFreeModuleElement(AlternatingContrTensor):
r"""
Element of a free module of finite rank over a commutative ring.
Expand Down Expand Up @@ -185,7 +194,13 @@ class FiniteRankFreeModuleElement(AlternatingContrTensor):
a∧b = -2 e_0∧e_1 - 6 e_0∧e_2 + 7 e_1∧e_2

"""
def __init__(self, fmodule, name=None, latex_name=None):

def __init__(
self,
fmodule: FiniteRankFreeModule,
name: Optional[str] = None,
latex_name: Optional[str] = None,
):
r"""
TESTS::

Expand All @@ -209,7 +224,7 @@ def __init__(self, fmodule, name=None, latex_name=None):
AlternatingContrTensor.__init__(self, fmodule, 1, name=name,
latex_name=latex_name)

def _repr_(self):
def _repr_(self) -> str:
r"""
Return a string representation of ``self``.

Expand All @@ -227,7 +242,7 @@ def _repr_(self):
description += "of the {}".format(self._fmodule)
return description

def _new_comp(self, basis):
def _new_comp(self, basis: FreeModuleBasis) -> Components:
r"""
Create some (uninitialized) components of ``self`` in a given basis.

Expand Down
13 changes: 11 additions & 2 deletions src/sage/tensor/modules/free_module_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
# the License, or (at your option) any later version.
# https://www.gnu.org/licenses/
# *****************************************************************************
from sage.rings.integer import Integer
from __future__ import annotations

from typing import TYPE_CHECKING

from sage.categories.morphism import Morphism
from sage.rings.integer import Integer

if TYPE_CHECKING:
from sage.tensor.modules.free_module_element import FiniteRankFreeModuleElement


class FiniteRankFreeModuleMorphism(Morphism):
Expand Down Expand Up @@ -764,7 +771,9 @@ def __neg__(self):
# Map methods
#

def _call_(self, element):
def _call_(
self, element: FiniteRankFreeModuleElement
) -> FiniteRankFreeModuleElement:
r"""
Action of the homomorphism ``self`` on some free module element

Expand Down
23 changes: 14 additions & 9 deletions src/sage/tensor/modules/free_module_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,22 @@ class being:
# *****************************************************************************
from __future__ import annotations

from typing import TYPE_CHECKING, Dict
from typing import TYPE_CHECKING, Dict, Optional

from sage.parallel.decorate import parallel
from sage.parallel.parallelism import Parallelism
from sage.rings.integer import Integer
from sage.structure.element import ModuleElementWithMutability
from sage.tensor.modules.comp import (Components, CompWithSym, CompFullySym,
CompFullyAntiSym)
from sage.tensor.modules.comp import (
CompFullyAntiSym,
CompFullySym,
Components,
CompWithSym,
)
from sage.tensor.modules.tensor_with_indices import TensorWithIndices
from sage.parallel.decorate import parallel
from sage.parallel.parallelism import Parallelism

if TYPE_CHECKING:
from sage.symbolic.expression import Expression
from sage.tensor.modules.finite_rank_free_module import FiniteRankFreeModule
from sage.tensor.modules.free_module_basis import FreeModuleBasis

Expand Down Expand Up @@ -264,8 +269,8 @@ def __init__(
self,
fmodule: FiniteRankFreeModule,
tensor_type,
name=None,
latex_name=None,
name: Optional[str] = None,
latex_name: Optional[str] = None,
sym=None,
antisym=None,
parent=None,
Expand Down Expand Up @@ -891,7 +896,7 @@ def display_comp(self, basis=None, format_spec=None, symbol=None,
only_nonzero=only_nonzero,
only_nonredundant=only_nonredundant)

def set_name(self, name=None, latex_name=None):
def set_name(self, name: Optional[str] = None, latex_name: Optional[str] = None):
r"""
Set (or change) the text name and LaTeX name of ``self``.

Expand Down Expand Up @@ -2262,7 +2267,7 @@ def __truediv__(self, other):
result._components[basis] = self._components[basis] / other
return result

def __call__(self, *args):
def __call__(self, *args) -> Expression:
r"""
The tensor acting on linear forms and module elements as a multilinear
map.
Expand Down