moble / quaternionic

Interpret numpy arrays as quaternionic arrays with numba acceleration
MIT License
84 stars 7 forks source link

Add static typing support for QArray #43

Closed tungalbert99 closed 10 months ago

tungalbert99 commented 11 months ago

I have some existing edits for how to support type checking with QArray which I think will be useful for developers. Small edits were also made to have the properties return floats

There might be some formatting fixes that I've triggered as a result of auto-formatting but willing to revert those if you find it not useful.

Example with a pyright checker showing no errors: image

moble commented 10 months ago

I appreciate the effort, but I think this can't work, because float isn't the only dtype that can be used here — which is the whole reason for this awkward factory function that contains QArray. That factory function can be called multiple times with different dtypes.

For example, I have found it very useful to be able to just use sympy variables as quaternion components, which allows me to expand and simplify expressions. This means I can be absolutely sure that the symbolic expressions I get really use all the same conventions and the exact same form as the numerical results I get.

Now, there are obviously lots of very low-level tricks going on in this package. But I really don't spend any time at all on typing, so I don't know if there other tricks that could be used to allow typing to work. I'm open to the possibilities, but this PR will have to be rethought.

tungalbert99 commented 10 months ago

This might require a larger re-design that separates the implementations or return types of different dtypes with subtype polymorphism. For example, if you use sympy variables as quaternion components, you should be expected to return a certain set of sympy types.

Because Python's limitations as a non-compiled language, static typing is unfortunately the only way to do typing and I personally find typing very useful to catch bugs before runtime :)