ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
576 stars 29 forks source link

Algebraically linking `Shape` attributes #119

Open LMWafer opened 3 months ago

LMWafer commented 3 months ago

I have a function which takes as input a sequence of 3-vectors with N elements. My input hint is

from nptyping import NDArray, Shape, Float

def foo(input_seq: NDArray[Shape["3, N"], Float]):
    pass

The function returns another sequence of 3-vectors, BUT this time with N+1 elements. Hence, I would like the output hint to re-employ the N variable. I'm thinking of something like

def foo(input_seq: NDArray[Shape["3, N"], Float]) -> NDArray[Shape["3, N+1"], Float]:
    pass

When I execute the above syntax I get the following error : nptyping.error.InvalidShapeError: "3, N+1" is not a valid shape expression.

In general, how can I specify that one Shape object is related to another Shape by an algebraic expression (using *, +, -, /, **, ...) ? I'm sorry if there is already a related issue/a feature that I did not notice.

I encounter this situation anytime I deal with temporal sequences (kinematic simulation, logs extraction, state estimation etc.) : the sequence is N+1 elements-long while the sequence of deltas is N elements-long.