nipy / nibabel

Python package to access a cacophony of neuro-imaging file formats
http://nipy.org/nibabel/
Other
649 stars 258 forks source link

[Question] Native code in NiBabel #1238

Closed nx10 closed 6 months ago

nx10 commented 1 year ago

Does NiBabel accept contributions in native / C/C++ code or is the 'vision' of the project to provide a pure python implementation?

Background: I have been experimenting with implementing nifti/freesurfer/... loading with the Numpy C API for additional performance gains and was wondering if it would be worth it to carve out a PR to NiBabel or if you would be reluctant because of the increase in maintenance complexity.

matthew-brett commented 1 year ago

It's not my call - but it were - I wouldn't be entirely opposed to compiled code as long as a) it was very well maintained and easy to read and b) it provided a substantial speed up, I suppose in the region of 2 x speedup or more for typical use-cases and and c) it wasn't fairly easily refactored into an external and optional library, which, if available could speed up the Nibabel loading.

effigies commented 1 year ago

I'm curious what you're trying to speed up. Do you have profiling demonstrating a problem, and benchmarks showing relevant speedups?

Like Matthew, I think my position can be stated as "not entirely opposed". I strongly value the readability of Python, and improvements in speed or memory usage need to be commensurate with the added complexity. There also need to be use cases where nibabel's Python-only codebase is a demonstrable bottleneck; a 10x speedup is a big win on 50% of runtime, but not much on 1% of runtime.

One situation where we've incorporated C code quite well is indexed-gzip, which provides extremely efficient seeking within compressed files. We are able to opportunistically use the library when it's present, without making it a hard dependency or taking on a maintenance burden.

All that said, I'm happy to have a look, just please don't spend a ton of time pushing forward on this without feedback.

effigies commented 6 months ago

Question has been answered. Specific issues can be opened.