from typing_extensions import Annotated
from pydantic import FiniteFloat, BaseModel
from numpydantic import Shape, NDArray
class T(BaseModel):
t: NDArray[Shape['2, 2'], FiniteFloat]
We should refactor the dtype check out into a separate class with classmethods to be able to expand dtype checks for the future, the current method is likely to end up with an enormous brittle if/else chain otherwise.
Some of these checks will have a faster vectorized method, like eg. Positive* shouldn't need to iterate over every value but just use np.all(array > 0). For any that don't have specific vectorized operations, we should just map that check across values of the array.
In pydantic implementation, these are all annotated types (eg. Annotated[int, Le(0)]), so that's what we should target for support.
From: https://github.com/LiberTEM/LiberTEM-schema/pull/7
The example given was:
We should refactor the dtype check out into a separate class with classmethods to be able to expand dtype checks for the future, the current method is likely to end up with an enormous brittle if/else chain otherwise.
We could allow generic support for all pydantic types here: https://docs.pydantic.dev/latest/api/types/
Some of these checks will have a faster vectorized method, like eg.
Positive*
shouldn't need to iterate over every value but just usenp.all(array > 0)
. For any that don't have specific vectorized operations, we should just map that check across values of the array.In pydantic implementation, these are all annotated types (eg.
Annotated[int, Le(0)]
), so that's what we should target for support.