icecube / photospline

https://docs.icecube.aq/photospline/v2.0.7/
BSD 2-Clause "Simplified" License
5 stars 12 forks source link

Restore scalar pysplinetable_searchcenters #40

Closed jvansanten closed 11 months ago

jvansanten commented 11 months ago

The vectorized implementation introduced in #35 assumed that inputs were ndarrays with at least 1 dimension. Python scalars happily convert to 0-d ndarrays, but for these PyArray_DIMS returns nullptr, leading to a segfault. NpyIter_MultiNew also does not support iteration over 0-d arrays.

Paper over this by falling back to the scalar case if all elements in the sequence can be converted to floats. This has the added benefit of actually checking whether elements are floats, rather than replacing incompatible elements with -1.

Also add a test that exercises the updated function, and update type annotations to reflect the different return types in the array and scalar case.

Fixes #39.