Skip to content

Update signal::convolve to use ndarrays over vec#76

Draft
SpookyYomo wants to merge 4 commits intoqsib-cbie:mainfrom
SpookyYomo:sci-convolve
Draft

Update signal::convolve to use ndarrays over vec#76
SpookyYomo wants to merge 4 commits intoqsib-cbie:mainfrom
SpookyYomo:sci-convolve

Conversation

@SpookyYomo
Copy link
Copy Markdown
Contributor

Overarching theme:
This PR is part of a larger effort to ensure ability to accept N-dimensional arrays over rust vecs.

PR details:
We defer to the communities efforts in NDArray FFT convolution instead of reinventing the wheel. There also exists other crates such as fftconvolve, but due to licensing, we go with ndarray-conv.

We try our best to make it convenient for users, so we use impl Into<ArrayView<_, _>> or impl Into<ArrayBase<_, _>>, so that rust vectors and slices besides ArrayBase can also be accepted by the function.

References:
ConvFFTExt differences from Scipy.
Trait bounds in thin wrapping. Special thanks to ndarray-conv creator for the help so far.

Todos before merging this PR:

  • Convolve::Full and Convolve::Valid. See above reference.
  • Unit tests with higher dimensional arrays.
  • Docstring examples showing different valid inputs, possibly with need for typehinting for compiler.

Other details:
For unspecified dimensions, array[:, -1] as in python cannot satisfy NDArray trait bounds by doing array.slice(s![..;-1]).

Scipy's documentation specifies that convolve (by FFT) accepts
N-dimensional numpy arrays, and not just 1D. This commit provides some
progress towards the interface standardisation.

Due to trait bounds, either both arguments have to be by reference, or
by value. To make things easier for end users, we let the functions be
by reference, so that rust vectors in-place of ndarray::Array1 is also
accepted by our functions.
@SpookyYomo SpookyYomo mentioned this pull request Jun 29, 2025
1 task
Symmetric kernel meant that it was possible that it was not properly
checked.
While this rejects taking in of Vec, it simplifies the function
signature a lot, and allows for clearer expression by end user if to pass
ndarrays by value or reference.
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