|
| 1 | +{{ objname | escape | underline}} |
| 2 | + |
| 3 | +.. currentmodule:: {{ module }} |
| 4 | + |
| 5 | +.. py:data:: {{ objname }} |
| 6 | +
|
| 7 | + {% if objname == "SURFACE_EMG__TENSOR" %} |
| 8 | + **Alias of:** ``Annotated[npt.NDArray[np.floating], Is[lambda x: x.ndim == 5]]`` |
| 9 | + {% elif objname == "INPUT_CURRENT__MATRIX" %} |
| 10 | + **Alias of:** ``Annotated[npt.NDArray[np.floating], Is[lambda x: x.ndim == 2]]`` |
| 11 | + {% elif objname == "SPIKE_TRAIN__MATRIX" %} |
| 12 | + **Alias of:** ``Annotated[npt.NDArray[np.bool_], Is[lambda x: x.ndim == 3]]`` |
| 13 | + {% elif objname == "MUAP_SHAPE__TENSOR" %} |
| 14 | + **Alias of:** ``Annotated[npt.NDArray[np.floating], Is[lambda x: x.ndim == 5]]`` |
| 15 | + {% else %} |
| 16 | + **Alias of:** *(see source code)* |
| 17 | + {% endif %} |
| 18 | + |
| 19 | + .. rubric:: Type Definition |
| 20 | + |
| 21 | + This type alias is defined using beartype validators:: |
| 22 | + |
| 23 | + from typing import Annotated |
| 24 | + import numpy.typing as npt |
| 25 | + from beartype.vale import Is |
| 26 | + |
| 27 | + {{ objname }} = Annotated[ |
| 28 | + npt.NDArray[np.floating], # or np.bool_ for boolean arrays |
| 29 | + Is[lambda x: x.ndim == N], # where N is the required dimensions |
| 30 | + ] |
| 31 | + |
| 32 | + .. rubric:: Runtime Type Checking |
| 33 | + |
| 34 | + Use with beartype for automatic validation:: |
| 35 | + |
| 36 | + from {{ module }} import {{ objname }} |
| 37 | + from beartype import beartype |
| 38 | + |
| 39 | + @beartype |
| 40 | + def process_{{ objname.lower().split('_')[0] }}_data(data: {{ objname }}) -> {{ objname }}: |
| 41 | + """Process data with automatic shape validation.""" |
| 42 | + # beartype automatically validates array dimensions |
| 43 | + return data |
| 44 | + |
| 45 | + .. tip:: |
| 46 | + 🐻 **Beartype Integration**: This type uses `beartype <https://github.com/beartype/beartype>`_ validators to ensure arrays have the correct number of dimensions at runtime. |
| 47 | + |
| 48 | + .. note:: |
| 49 | + 📐 **Array Validation**: The `Is[lambda x: x.ndim == N]` validator automatically checks that your NumPy arrays have the expected shape for MyoGen operations. |
0 commit comments