Skip to main content

convolve_impl

Function convolve_impl 

Source
pub fn convolve_impl<R, C>(
    client: &C,
    a: &Tensor<R>,
    b: &Tensor<R>,
    dtype_support: DTypeSupport,
) -> Result<Tensor<R>>
where R: Runtime<DType = DType>, C: RuntimeClient<R> + BinaryOps<R> + IndexingOps<R> + ShapeOps<R> + UtilityOps<R> + ReduceOps<R> + FftAlgorithms<R> + ComplexOps<R>,
Expand description

Convolve two 1D tensors (polynomial multiplication).

Auto-selects direct vs FFT based on input sizes:

  • Direct for nm < 64 (O(nm) complexity)
  • FFT for n*m >= 64 (O(n log n) complexity)

§Arguments

  • client - The runtime client
  • a - First polynomial coefficients [a₀, a₁, …, aₙ₋₁]
  • b - Second polynomial coefficients [b₀, b₁, …, bₘ₋₁]
  • dtype_support - Backend dtype support flags

§Returns

Convolution result with length n+m-1, where: c[k] = Σᵢ a[i] * b[k-i] for valid i

§Example

// (1 + 2x) * (3 + 4x) = 3 + 10x + 8x²
let a = Tensor::from_slice(&[1.0f32, 2.0], &[2], &device);
let b = Tensor::from_slice(&[3.0f32, 4.0], &[2], &device);
let c = convolve_impl(&client, &a, &b, DTypeSupport::FULL)?;
// c = [3.0, 10.0, 8.0]