Skip to content

Commit

Permalink
Replacing np by npt in python function annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
ordinary-slim committed Aug 14, 2024
1 parent 42c7efd commit 5d075a4
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
11 changes: 6 additions & 5 deletions python/dolfinx/fem/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import typing

import numpy as np
import numpy.typing as npt

import dolfinx
from dolfinx import cpp as _cpp
Expand Down Expand Up @@ -183,7 +184,7 @@ def _assemble_vector_form(L: Form, constants=None, coeffs=None) -> la.Vector:


@assemble_vector.register(np.ndarray)
def _assemble_vector_array(b: np.ndarray, L: Form, constants=None, coeffs=None):
def _assemble_vector_array(b: npt.NDArray, L: Form, constants=None, coeffs=None):
"""Assemble linear form into an existing array.
Args:
Expand Down Expand Up @@ -297,10 +298,10 @@ def _assemble_matrix_csr(


def apply_lifting(
b: np.ndarray,
b: npt.NDArray,
a: list[Form],
bcs: list[list[DirichletBC]],
x0: typing.Optional[list[np.ndarray]] = None,
x0: typing.Optional[list[npt.NDArray]] = None,
scale: float = 1.0,
constants=None,
coeffs=None,
Expand Down Expand Up @@ -344,9 +345,9 @@ def apply_lifting(


def set_bc(
b: np.ndarray,
b: npt.NDArray,
bcs: list[DirichletBC],
x0: typing.Optional[np.ndarray] = None,
x0: typing.Optional[npt.NDArray] = None,
scale: float = 1.0,
) -> None:
"""Insert boundary condition values into vector.
Expand Down
7 changes: 4 additions & 3 deletions python/dolfinx/fem/bcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from dolfinx.fem.function import Constant, Function

import numpy as np
import numpy.typing as npt

import dolfinx
from dolfinx import cpp as _cpp
Expand Down Expand Up @@ -57,7 +58,7 @@ def locate_dofs_geometrical(
def locate_dofs_topological(
V: typing.Union[dolfinx.fem.FunctionSpace, typing.Iterable[dolfinx.fem.FunctionSpace]],
entity_dim: int,
entities: numpy.typing.NDArray[np.int32],
entities: npt.NDArray[np.int32],
remote: bool = True,
) -> np.ndarray:
"""Locate degrees-of-freedom belonging to mesh entities topologically.
Expand Down Expand Up @@ -134,8 +135,8 @@ def function_space(self) -> dolfinx.fem.FunctionSpace:


def dirichletbc(
value: typing.Union[Function, Constant, np.ndarray],
dofs: numpy.typing.NDArray[np.int32],
value: typing.Union[Function, Constant, npt.NDArray],
dofs: npt.NDArray[np.int32],
V: typing.Optional[dolfinx.fem.FunctionSpace] = None,
) -> DirichletBC:
"""Create a representation of Dirichlet boundary condition which
Expand Down
4 changes: 2 additions & 2 deletions python/dolfinx/fem/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def integral_types(self):

def get_integration_domains(
integral_type: IntegralType,
subdomain: typing.Optional[typing.Union[MeshTags, list[tuple[int, np.ndarray]]]],
subdomain: typing.Optional[typing.Union[MeshTags, list[tuple[int, npt.NDArray]]]],
subdomain_ids: list[int],
) -> list[tuple[int, np.ndarray]]:
"""Get integration domains from subdomain data.
Expand Down Expand Up @@ -190,7 +190,7 @@ def form(
dtype: npt.DTypeLike = default_scalar_type,
form_compiler_options: typing.Optional[dict] = None,
jit_options: typing.Optional[dict] = None,
entity_maps: dict[Mesh, np.typing.NDArray[np.int32]] = {},
entity_maps: dict[Mesh, npt.NDArray[np.int32]] = {},
):
"""Create a Form or an array of Forms.
Expand Down
12 changes: 6 additions & 6 deletions python/dolfinx/fem/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Constant(ufl.Constant):
]

def __init__(
self, domain, c: typing.Union[np.ndarray, typing.Sequence, np.floating, np.complexfloating]
self, domain, c: typing.Union[npt.NDArray, typing.Sequence, np.floating, np.complexfloating]
):
"""A constant with respect to a domain.
Expand Down Expand Up @@ -90,7 +90,7 @@ class Expression:
def __init__(
self,
e: ufl.core.expr.Expr,
X: np.ndarray,
X: npt.NDArray,
comm: typing.Optional[_MPI.Comm] = None,
form_compiler_options: typing.Optional[dict] = None,
jit_options: typing.Optional[dict] = None,
Expand Down Expand Up @@ -196,7 +196,7 @@ def _create_expression(dtype):
def eval(
self,
mesh: Mesh,
entities: np.ndarray,
entities: npt.NDArray,
values: typing.Optional[np.ndarray] = None,
) -> np.ndarray:
"""Evaluate Expression on entities.
Expand Down Expand Up @@ -412,8 +412,8 @@ def interpolate_nonmatching(
def interpolate(
self,
u0: typing.Union[typing.Callable, Expression, Function],
cells0: typing.Optional[np.ndarray] = None,
cells1: typing.Optional[np.ndarray] = None,
cells0: typing.Optional[npt.NDArray] = None,
cells1: typing.Optional[npt.NDArray] = None,
) -> None:
"""Interpolate an expression.
Expand Down Expand Up @@ -582,7 +582,7 @@ def _create_dolfinx_element(
comm: _MPI.Intracomm,
cell_type: _cpp.mesh.CellType,
ufl_e: ufl.FiniteElementBase,
dtype: np.dtype,
dtype: npt.DTypeLike,
) -> typing.Union[_cpp.fem.FiniteElement_float32, _cpp.fem.FiniteElement_float64]:
"""Create a DOLFINx element from a basix.ufl element."""
if np.issubdtype(dtype, np.float32):
Expand Down
4 changes: 2 additions & 2 deletions python/dolfinx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from __future__ import annotations

import numpy as np
import numpy.typing as npt

from dolfinx import cpp as _cpp
from dolfinx.cpp.graph import partitioner
Expand All @@ -31,7 +31,7 @@
__all__ = ["adjacencylist", "partitioner"]


def adjacencylist(data: np.ndarray, offsets=None):
def adjacencylist(data: npt.NDArray, offsets=None):
"""Create an AdjacencyList for int32 or int64 datasets.
Args:
Expand Down
2 changes: 1 addition & 1 deletion python/dolfinx/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def read_meshtags(self, mesh, name, xpath="/Xdmf/Domain"):


def distribute_entity_data(
mesh: Mesh, entity_dim: int, entities: npt.NDArray[np.int64], values: np.ndarray
mesh: Mesh, entity_dim: int, entities: npt.NDArray[np.int64], values: npt.NDArray
) -> tuple[npt.NDArray[np.int64], np.ndarray]:
"""Given a set of mesh entities and values, distribute them to the process that owns the entity.
Expand Down
12 changes: 6 additions & 6 deletions python/dolfinx/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def compute_midpoints(mesh: Mesh, dim: int, entities: npt.NDArray[np.int32]):
return _cpp.mesh.compute_midpoints(mesh._cpp_object, dim, entities)


def locate_entities(mesh: Mesh, dim: int, marker: typing.Callable) -> np.ndarray:
def locate_entities(mesh: Mesh, dim: int, marker: typing.Callable) -> npt.NDArray:
"""Compute mesh entities satisfying a geometric marking function.
Args:
Expand All @@ -239,7 +239,7 @@ def locate_entities(mesh: Mesh, dim: int, marker: typing.Callable) -> np.ndarray
return _cpp.mesh.locate_entities(mesh._cpp_object, dim, marker)


def locate_entities_boundary(mesh: Mesh, dim: int, marker: typing.Callable) -> np.ndarray:
def locate_entities_boundary(mesh: Mesh, dim: int, marker: typing.Callable) -> npt.NDArray:
"""Compute mesh entities that are connected to an owned boundary
facet and satisfy a geometric marking function.
Expand Down Expand Up @@ -313,7 +313,7 @@ def transfer_meshtag(


def refine(
mesh: Mesh, edges: typing.Optional[np.ndarray] = None, redistribute: bool = True
mesh: Mesh, edges: typing.Optional[npt.NDArray] = None, redistribute: bool = True
) -> Mesh:
"""Refine a mesh.
Expand All @@ -336,7 +336,7 @@ def refine(

def refine_interval(
mesh: Mesh,
cells: typing.Optional[np.ndarray] = None,
cells: typing.Optional[npt.NDArray] = None,
redistribute: bool = True,
ghost_mode: GhostMode = GhostMode.shared_facet,
) -> tuple[Mesh, npt.NDArray[np.int32]]:
Expand Down Expand Up @@ -367,7 +367,7 @@ def refine_interval(

def refine_plaza(
mesh: Mesh,
edges: typing.Optional[np.ndarray] = None,
edges: typing.Optional[npt.NDArray] = None,
redistribute: bool = True,
option: RefinementOption = RefinementOption.none,
) -> tuple[Mesh, npt.NDArray[np.int32], npt.NDArray[np.int32]]:
Expand Down Expand Up @@ -506,7 +506,7 @@ def meshtags(
mesh: Mesh,
dim: int,
entities: npt.NDArray[np.int32],
values: typing.Union[np.ndarray, int, float],
values: typing.Union[npt.NDArray, int, float],
) -> MeshTags:
"""Create a MeshTags object that associates data with a subset of mesh entities.
Expand Down

0 comments on commit 5d075a4

Please sign in to comment.