fftw/lib.rs
1//! Rust binding of [FFTW]
2//!
3//! [FFTW]: http://www.fftw.org/
4//!
5//! Examples
6//! ---------
7//!
8//! Complex-to-Complex
9//!
10//! ```
11//! use fftw::array::AlignedVec;
12//! use fftw::plan::*;
13//! use fftw::types::*;
14//! use std::f64::consts::PI;
15//!
16//! let n = 128;
17//! let mut plan: C2CPlan64 = C2CPlan::aligned(&[n], Sign::Forward, Flag::MEASURE).unwrap();
18//! let mut a = AlignedVec::new(n);
19//! let mut b = AlignedVec::new(n);
20//! let k0 = 2.0 * PI / n as f64;
21//! for i in 0..n {
22//! a[i] = c64::new((k0 * i as f64).cos(), 0.0);
23//! }
24//! plan.c2c(&mut a, &mut b).unwrap();
25//! ```
26//!
27//! Complex-to-Real
28//!
29//! ```
30//! use fftw::array::AlignedVec;
31//! use fftw::plan::*;
32//! use fftw::types::*;
33//! use std::f64::consts::PI;
34//!
35//! let n = 128;
36//! let mut c2r: C2RPlan64 = C2RPlan::aligned(&[n], Flag::MEASURE).unwrap();
37//! let mut a = AlignedVec::new(n / 2 + 1);
38//! let mut b = AlignedVec::new(n);
39//! for i in 0..(n / 2 + 1) {
40//! a[i] = c64::new(1.0, 0.0);
41//! }
42//! c2r.c2r(&mut a, &mut b).unwrap();
43//! ```
44
45extern crate fftw_sys as ffi;
46
47use lazy_static::lazy_static;
48use std::sync::Mutex;
49
50lazy_static! {
51 /// Mutex for FFTW call.
52 ///
53 /// This mutex is necessary because most of calls in FFTW are not thread-safe.
54 /// See the [original document](http://www.fftw.org/fftw3_doc/Thread-safety.html) for detail
55 pub static ref FFTW_MUTEX: Mutex<()> = Mutex::new(());
56}
57
58/// Exclusive call of FFTW interface.
59macro_rules! excall {
60 ($call:expr) => {{
61 let _lock = $crate::FFTW_MUTEX.lock().expect("Cannot get lock");
62 unsafe { $call }
63 }};
64} // excall!
65
66pub mod array;
67pub mod error;
68pub mod plan;
69pub mod types;