Skip to content

Commit

Permalink
added comment to explain reason for covariant type
Browse files Browse the repository at this point in the history
  • Loading branch information
mcocdawc committed Dec 4, 2024
1 parent 91a8a97 commit dab199c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/quemb/shared/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@

import numpy as np

T_co = TypeVar("T_co", bound=np.generic, covariant=True)
# We want the dtype to behave covariant, i.e. if a
# Vector[float] is allowed, then the more specific
# Vector[float64] should also be allowed.
#
# Also see here:
# https://stackoverflow.com/questions/61568462/what-does-typevara-b-covariant-true-mean
T_dtype_co = TypeVar("T_dtype_co", bound=np.generic, covariant=True)

Vector = np.ndarray[Tuple[int], np.dtype[T_co]]
Matrix = np.ndarray[Tuple[int, int], np.dtype[T_co]]
Tensor3D = np.ndarray[Tuple[int, int, int], np.dtype[T_co]]
Tensor4D = np.ndarray[Tuple[int, int, int, int], np.dtype[T_co]]
Tensor5D = np.ndarray[Tuple[int, int, int, int, int], np.dtype[T_co]]
Tensor6D = np.ndarray[Tuple[int, int, int, int, int, int], np.dtype[T_co]]
Tensor = np.ndarray[Tuple[int, ...], np.dtype[T_co]]
Vector = np.ndarray[Tuple[int], np.dtype[T_dtype_co]]
Matrix = np.ndarray[Tuple[int, int], np.dtype[T_dtype_co]]
Tensor3D = np.ndarray[Tuple[int, int, int], np.dtype[T_dtype_co]]
Tensor4D = np.ndarray[Tuple[int, int, int, int], np.dtype[T_dtype_co]]
Tensor5D = np.ndarray[Tuple[int, int, int, int, int], np.dtype[T_dtype_co]]
Tensor6D = np.ndarray[Tuple[int, int, int, int, int, int], np.dtype[T_dtype_co]]
Tensor = np.ndarray[Tuple[int, ...], np.dtype[T_dtype_co]]

0 comments on commit dab199c

Please sign in to comment.