Skip to main content

convolve_reference

Function convolve_reference 

Source
pub fn convolve_reference(signal: &[f32], kernel: &[f32]) -> Vec<f32>
Expand description

Pure-Rust reference linear convolution (direct O(N·M) algorithm).

Computes output[i] = Σ_k signal[i−k] · kernel[k] for a finite-support linear (non-circular) convolution.

Output length is signal.len() + kernel.len() - 1 when both are non-empty, and zero when either is empty.

This function exists as a ground-truth reference for tests; it is not optimised and should not be used on large inputs.

§Examples

use oxigdal_gpu::convolution_fft::convolve_reference;

// Polynomial multiplication: (1+x) * (1+x) = 1 + 2x + x²
let result = convolve_reference(&[1.0, 1.0], &[1.0, 1.0]);
assert!((result[0] - 1.0).abs() < 1e-6);
assert!((result[1] - 2.0).abs() < 1e-6);
assert!((result[2] - 1.0).abs() < 1e-6);