Source code for pyxu.info.ptype
1import collections.abc as cabc
2import numbers as nb
3import pathlib as plib
4import typing as typ
5
6import numpy.typing as npt
7
8import pyxu.info.deps as pxd
9
10if typ.TYPE_CHECKING:
11 import pyxu.abc.operator as pxo
12 import pyxu.abc.solver as pxs
13
14#: Supported dense array types.
15NDArray = typ.TypeVar("NDArray", *pxd.supported_array_types())
16
17#: Supported dense array modules.
18ArrayModule = typ.TypeVar(
19 "ArrayModule",
20 *[typ.Literal[_] for _ in pxd.supported_array_modules()],
21)
22
23#: Supported sparse array types.
24if len(sst := pxd.supported_sparse_types()) == 1:
25 SparseArray = typ.TypeVar("SparseArray", bound=tuple(sst)[0])
26else:
27 SparseArray = typ.TypeVar("SparseArray", *sst)
28
29#: Supported sparse array modules.
30if len(ssm := pxd.supported_sparse_modules()) == 1:
31 SparseModule = typ.TypeVar("SparseModule", bound=tuple(ssm)[0])
32else:
33 SparseModule = typ.TypeVar("SparseModule", *[typ.Literal[_] for _ in ssm])
34
35#: Top-level abstract :py:class:`~pyxu.abc.Operator` interface exposed to users.
36OpT = typ.TypeVar(
37 # This list should be kept in sync with all user-facing operators in `pxo`.
38 "OpT",
39 "pxo.Operator",
40 "pxo.DiffFunc",
41 "pxo.ProxDiffFunc",
42 "pxo.NormalOp",
43 "pxo.ProxFunc",
44 "pxo.SquareOp",
45 "pxo.QuadraticFunc",
46 "pxo.ProjOp",
47 "pxo.LinFunc",
48 "pxo.PosDefOp",
49 "pxo.Map",
50 "pxo.Func",
51 "pxo.OrthProjOp",
52 "pxo.DiffMap",
53 "pxo.UnitOp",
54 "pxo.SelfAdjointOp",
55 "pxo.LinOp",
56)
57
58#: :py:class:`~pyxu.abc.Operator` hierarchy class type.
59OpC = typ.Type[OpT] # Operator classes
60
61#: Mathematical properties attached to :py:class:`~pyxu.abc.Operator` objects.
62Property = "pxo.Property"
63
64#: Top-level abstract :py:class:`~pyxu.abc.Solver` interface exposed to users.
65SolverT = typ.TypeVar("SolverT", bound="pxs.Solver")
66
67#: :py:class:`~pyxu.abc.Solver` hierarchy class type.
68SolverC = typ.Type[SolverT]
69
70#: Solver run-modes.
71SolverM = typ.TypeVar("SolverM", bound="pxs.SolverMode")
72
73Integer = nb.Integral
74Real = nb.Real #: Alias of :py:class:`numbers.Real`.
75DType = npt.DTypeLike #: :py:attr:`~pyxu.info.ptype.NDArray` dtype specifier.
76NDArrayAxis = typ.Union[Integer, tuple[Integer, ...]] #: Axis/Axes specifier.
77NDArrayShape = typ.Union[Integer, tuple[Integer, ...]] #: :py:attr:`~pyxu.info.ptype.NDArray` shape specifier.
78Path = typ.Union[str, plib.Path] #: Path-like object.
79VarName = typ.Union[str, cabc.Collection[str]] #: Variable name(s).