EPFL-Center-for-Imaging / splinebox

A python package for fitting splines.
BSD 3-Clause "New" or "Revised" License
14 stars 0 forks source link

Question: Vectorized implementation of spline sampling #25

Open jjerphan opened 1 month ago

jjerphan commented 1 month ago

Dear developers of splinebox,

Thank you for open-sourcing and maintaining this library!

Would you be interested in considering a vectorized implementation of 2D and 3D spline sampling with potentially near-optimal arithmetic intensity, such as this proposal which I hope is sufficiently clear, or would it be too much of a maintenance cost for you?

faymanns commented 1 month ago

Hi @jjerphan,

Thank you for your interest in splinebox.

The sampling is implemented via matrices as you describe it in your post.

For the equidistant sampling in terms of arc length, we do use binary search and numerical integration. However, I am not super happy with the performance of the arc_length_to_parameter method. Perhaps, there are some tricks that we are missing. If I understand your post correctly, you suggest using matrix based sampling of the first derivative followed by numerical integration via e.g. the trapezoidal rule. We currently use scipy.integarte.quad, which is slower than the trapezoidal rule but plays nicely with nan values at positions where the derivative is not defined.

Regarding 2D and 3D multivariate splines, we currently don't plan to implement those. Colleagues of us are developing the SplineOps package, which implements at least 2D (not sure about 3D).

Hope that answers your question.

jjerphan commented 1 month ago

Thank you for your reply.

I might open a pull request to make this scheme explicit. IIRC, it sped up the sampling by 4 orders of magnitude.

faymanns commented 1 month ago

That would be great if we could speed it up! Let me know if you have any questions or need help with the pull request.

jjerphan commented 1 month ago

I just need some time to find, copy and paste the diff.