-
Notifications
You must be signed in to change notification settings - Fork 17
Python 3.14 refcount semantics and problems with resize #35
Description
I'm just flagging this for you so you're aware, though it's likely to be fixed upstream of you (ie in numpy) anyway.
I've been seeing test failures in librosa on 3.14 environments lately, and after discussing with numpy devs, traced it back to the following issue numpy/numpy#30991 wherein the resize operation causes problems with memory reference counting on python 3.14 (but not earlier).
Note: this is a rather sneaky bug, as it only pops up for me when bundling resample calls within a vectorization like np.apply_along_axis (as we do in librosa to handle multichannel).
Looking into the python-samplerate code, it appears that resize is generally used to make a truncated view of an over-allocated output array:
python-samplerate/src/samplerate.cpp
Lines 184 to 188 in 235d720
| // create a shorter view of the array | |
| if ((size_t)src_data.output_frames_gen < new_size) { | |
| out_shape[0] = src_data.output_frames_gen; | |
| output.resize(out_shape); | |
| } |
It's probably more hassle than it's worth to rewrite these bindings to avoid view resize. (Unless libsamplerate exposes a function to pre-compute output lengths?) It may also work (and is probably safe) to force refcheck=False into the resize calls, but that seems a little hacky IMO.