-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom type alias for floats or arrays of floats
Closes #10
- Loading branch information
Showing
4 changed files
with
25 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Some type aliases, mostly for hinting about arrays of | ||
numbers. `numpy.typing.ArrayLike` covers anything that can be | ||
converted to an array of any type, and we mostly want to restrict to | ||
arrays of floats. | ||
""" | ||
|
||
from typing import Union, Any, List | ||
import numpy as np | ||
|
||
try: | ||
from numpy.typing import NDArray | ||
|
||
float_ = np.floating[Any] | ||
FloatArray = NDArray[np.floating[Any]] | ||
except ImportError: | ||
float_ = float # type: ignore | ||
FloatArray = np.ndarray # type: ignore | ||
|
||
ArrayLike = Union[int, float, float_, FloatArray, List[float_]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters