A Rust library crate providing an [FFT] API for arrays and slices. This crate wraps the [rustfft] and [realfft] crates that does the heavy lifting behind the scenes.
const-realfft
feature requires the nightly
compiler because it depends on
the [genericconstexprs] featureThe nightly
dependent features are commented out.
```rust
// NOTE: Only required for real arrays
// #![allow(incompletefeatures)]
// #![feature(genericconst_exprs)]
// use easyfft::constsize::realfft::*; use easyfft::constsize::; use easyfft::dyn_size::realfft::; use easyfft::dyn_size::; use easyfft::;
fn main() { // Complex arrays let complexarray = [Complex::new(1.0, 0.0); 100]; let complexarraydft = complexarray.fft(); let complexarraydftidft = complexarraydft.ifft();
// Real to complex arrays
let real_array = [1.0; 100];
let _real_array_dft = real_array.fft();
// // Real arrays
// let real_array = [1.0; 100];
// let real_array_dft = real_array.real_fft();
// let _real_array_dft_idft = real_array_dft.real_ifft();
// Complex slices
let complex_slice: &[_] = &[Complex::new(1.0, 0.0); 100];
let complex_slice_dft = complex_slice.fft();
let _complex_slice_dft_idft = complex_slice_dft.ifft();
// Real to complex slices
let real_slice: &[_] = &[1.0; 100];
let _real_slice_dft = real_slice.fft();
// Real slices
let real_slice: &[_] = &[1.0; 100];
let real_slice_dft = real_slice.real_fft();
let _real_slice_dft_idft = real_slice_dft.real_ifft();
// In-place mutation on complex -> complex transforms
let mut complex_slice = [Complex::new(1.0, 0.0); 100];
complex_slice.fft_mut();
complex_slice.ifft_mut();
let mut complex_array = [Complex::new(1.0, 0.0); 100];
complex_array.fft_mut();
complex_array.ifft_mut();
} ```
There could be other bugs in this crate or it's dependencies that may cause a panic, but in theory all the runtime panics have been moved to compile time errors.
panic. This is because the rust language does not have the ability to encode
properties of the length of slices in the type system. This might become
possible in the future if the rust team manages to extend const generics to
fully fledged [dependent types]. For now, we're limited to using arrays where
we can ensure these properties. You can opt into these panic-able operations
via the fallible
feature flag. This brings slices up to feature parity with
arrays, but you opt out of the "won't panicâ„¢" guarantee of this crate. I do
recommend you take a step back and consider if you REALLY need to work with
slices instead of arrays. Many applications can get away with knowing the size
of their signal at compile time.