Skip to content

Allow passing any ArrayLike object instead of just numpy.ndarray.#450

Draft
psobot wants to merge 3 commits intomasterfrom
psobot/pytorch
Draft

Allow passing any ArrayLike object instead of just numpy.ndarray.#450
psobot wants to merge 3 commits intomasterfrom
psobot/pytorch

Conversation

@psobot
Copy link
Copy Markdown
Member

@psobot psobot commented Jan 14, 2026

Rather than just passing np.ndarray, we should support passing torch.Tensor, tf.Tensor, jax.Array, etc. We will always still return np.ndarray from APIs.

@psobot psobot changed the title Allow passing any ArrayLike object. Allow passing any ArrayLike object instead of just numpy.ndarray. Jan 14, 2026
gijzelaerr added a commit to gijzelaerr/pedalboard that referenced this pull request Mar 18, 2026
PR spotify#450 changed ExternalPlugin binding lambdas to accept py::object
instead of const py::array for the audio input parameter. This broke
pybind11's overload resolution for instrument plugins: since py::object
matches any Python type, calls with MIDI messages (e.g.
plugin(notes, 5.0, sr, reset=False)) would match the audio overload
before the MIDI overload, causing ensureArrayLike() to fail on
non-array-like MIDI message lists with:
  TypeError: Pedalboard only supports 32-bit and 64-bit floating point
  audio for processing.

The fix restores const py::array as the parameter type in the
ExternalPlugin binding lambdas (for AbstractExternalPlugin, VST3Plugin,
and AudioUnitPlugin) so pybind11 correctly rejects non-array inputs and
falls through to the MIDI overload. The base Plugin class and standalone
process() function retain py::object since they have no MIDI overloads.
pybind11 will still auto-convert array-like objects (torch tensors, etc.)
to py::array via the buffer protocol and __array__ interface.

Based on psobot's work in spotify#450.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant