sci-gaussfilt-rs

Crates.iosci-gaussfilt-rs
lib.rssci-gaussfilt-rs
version0.1.0
created_at2025-12-05 15:28:49.064399+00
updated_at2025-12-05 15:28:49.064399+00
descriptionA Rust implementation of the 1D Gaussian filter matching SciPy's behavior.
homepage
repositoryhttps://github.com/Beneficial01/sci-gaussfilt-rs
max_upload_size
id1968428
size72,376
Mahmoud (Beneficial01)

documentation

README

sci-gaussfilt-rs

A Rust implementation of the 1D Gaussian filter that exactly matches the behavior of scipy.ndimage.gaussian_filter1d.

This crate provides a high-performance, pure Rust implementation of the Gaussian filter for 1D arrays, supporting various boundary conditions and floating-point types (f32, f64). It is designed to be a drop-in replacement for SciPy's implementation in Rust applications.

Features

  • SciPy Parity: Matches scipy.ndimage.gaussian_filter1d output within floating-point tolerance (1e-6 or better).
  • Boundary Modes: Supports Reflect, Nearest, and Constant padding modes.
  • Generic: Works with f32 and f64 data types.
  • Performance: Optimized convolution with pre-calculated kernels and padding.

Installation

Add this to your Cargo.toml:

[dependencies]
sci-gaussfilt-rs = "0.1.0"

Usage

use sci_gaussfilt_rs::{gaussian_filter1d, types::BoundaryMode};

fn main() {
    let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
    let sigma = 1.0;
    let truncate = 4.0;
    
    // Apply Gaussian filter with Reflect boundary mode
    let result = gaussian_filter1d(&data, sigma, truncate, BoundaryMode::Reflect).unwrap();
    
    println!("Filtered data: {:?}", result);
}

Supported Boundary Modes

  • BoundaryMode::Reflect: (Default in SciPy) d c b a | a b c d | d c b a
  • BoundaryMode::Nearest: a a a a | a b c d | d d d d
  • BoundaryMode::Constant(value): v v v v | a b c d | v v v v

License

MIT

Commit count: 0

cargo fmt