Skip to content

Commit 56ba10d

Browse files
committed
TYP: improve type annotations of arrays to also express constraints on shapes
1 parent 37a2e0a commit 56ba10d

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

src/rlic/_core.pyi

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,65 @@
1+
from typing import TypeVar
2+
13
from numpy import dtype, ndarray
24
from numpy import float32 as f32
35
from numpy import float64 as f64
46

57
from rlic._boundaries import BoundaryStr
68
from rlic._typing import Pair, UVMode
79

10+
I = TypeVar("I", bound=int)
11+
J = TypeVar("J", bound=int)
12+
F = TypeVar("F", f32, f64)
13+
14+
IJArray = ndarray[tuple[I, J], dtype[F]]
15+
816
def convolve_f32(
9-
texture: ndarray[tuple[int, int], dtype[f32]],
17+
texture: IJArray[I, J, f32],
1018
uv: tuple[
11-
ndarray[tuple[int, int], dtype[f32]],
12-
ndarray[tuple[int, int], dtype[f32]],
19+
IJArray[I, J, f32],
20+
IJArray[I, J, f32],
1321
UVMode,
1422
],
1523
kernel: ndarray[tuple[int], dtype[f32]],
1624
boundaries: Pair[Pair[BoundaryStr]],
1725
iterations: int = 1,
18-
) -> ndarray[tuple[int, int], dtype[f32]]: ...
26+
) -> IJArray[I, J, f32]: ...
1927
def convolve_f64(
20-
texture: ndarray[tuple[int, int], dtype[f64]],
28+
texture: IJArray[I, J, f64],
2129
uv: tuple[
22-
ndarray[tuple[int, int], dtype[f64]],
23-
ndarray[tuple[int, int], dtype[f64]],
30+
IJArray[I, J, f64],
31+
IJArray[I, J, f64],
2432
UVMode,
2533
],
2634
kernel: ndarray[tuple[int], dtype[f64]],
2735
boundaries: Pair[Pair[BoundaryStr]],
2836
iterations: int = 1,
29-
) -> ndarray[tuple[int, int], dtype[f64]]: ...
37+
) -> IJArray[I, J, f64]: ...
3038
def equalize_histogram_f32(
31-
image: ndarray[tuple[int, int], dtype[f32]],
39+
image: IJArray[I, J, f32],
3240
nbins: int,
33-
) -> ndarray[tuple[int, int], dtype[f32]]: ...
41+
) -> IJArray[I, J, f32]: ...
3442
def equalize_histogram_f64(
35-
image: ndarray[tuple[int, int], dtype[f64]],
43+
image: IJArray[I, J, f64],
3644
nbins: int,
37-
) -> ndarray[tuple[int, int], dtype[f64]]: ...
45+
) -> IJArray[I, J, f64]: ...
3846
def equalize_histogram_sliding_tile_f32(
39-
image: ndarray[tuple[int, int], dtype[f32]],
47+
image: IJArray[I, J, f32],
4048
nbins: int,
4149
tile_shape: Pair[int],
42-
) -> ndarray[tuple[int, int], dtype[f32]]: ...
50+
) -> IJArray[I, J, f32]: ...
4351
def equalize_histogram_sliding_tile_f64(
44-
image: ndarray[tuple[int, int], dtype[f64]],
52+
image: IJArray[I, J, f64],
4553
nbins: int,
4654
tile_shape: Pair[int],
47-
) -> ndarray[tuple[int, int], dtype[f64]]: ...
55+
) -> IJArray[I, J, f64]: ...
4856
def equalize_histogram_tile_interpolation_f32(
49-
image: ndarray[tuple[int, int], dtype[f32]],
57+
image: IJArray[I, J, f32],
5058
nbins: int,
5159
tile_shape: Pair[int],
52-
) -> ndarray[tuple[int, int], dtype[f32]]: ...
60+
) -> IJArray[I, J, f32]: ...
5361
def equalize_histogram_tile_interpolation_f64(
54-
image: ndarray[tuple[int, int], dtype[f64]],
62+
image: IJArray[I, J, f64],
5563
nbins: int,
5664
tile_shape: Pair[int],
57-
) -> ndarray[tuple[int, int], dtype[f64]]: ...
65+
) -> IJArray[I, J, f64]: ...

0 commit comments

Comments
 (0)