Skip to content

Commit bf77ea8

Browse files
committed
Drop NAE name space
1 parent 68c8661 commit bf77ea8

File tree

5 files changed

+76
-75
lines changed

5 files changed

+76
-75
lines changed

src/array.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{FFTW_MUTEX, c32, c64};
1+
use types::*;
22
use error::*;
33
use ffi;
44

@@ -147,9 +147,7 @@ impl<T> DerefMut for AlignedVec<T> {
147147

148148
impl<T> Drop for AlignedVec<T> {
149149
fn drop(&mut self) {
150-
let lock = FFTW_MUTEX.lock().expect("Cannot get lock");
151-
unsafe { ffi::fftw_free(self.data as *mut c_void) };
152-
drop(lock);
150+
excall! { ffi::fftw_free(self.data as *mut c_void) };
153151
}
154152
}
155153

@@ -159,9 +157,7 @@ where
159157
{
160158
/// Create array with `fftw_malloc` (`fftw_free` is automatically called when the arrya is `Drop`-ed)
161159
pub fn new(n: usize) -> Self {
162-
let lock = FFTW_MUTEX.lock().expect("Cannot get lock");
163-
let ptr = unsafe { T::alloc(n) };
164-
drop(lock);
160+
let ptr = excall! { T::alloc(n) };
165161
let mut vec = AlignedVec { n: n, data: ptr };
166162
for v in vec.iter_mut() {
167163
*v = T::zero();

src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use ndarray::ShapeError;
22

33
pub type Result<T> = ::std::result::Result<T, Error>;
44

5-
use super::nae::NAEInputMismatchError;
5+
use super::plan::NAEInputMismatchError;
66

77
#[derive(Debug, IntoEnum)]
88
pub enum Error {

src/lib.rs

+6-64
Original file line numberDiff line numberDiff line change
@@ -18,72 +18,14 @@ lazy_static! {
1818

1919
macro_rules! excall {
2020
($call:expr) => {
21-
let _lock = FFTW_MUTEX.lock().expect("Cannot get lock");
22-
unsafe { $call }
21+
{
22+
let _lock = $crate::FFTW_MUTEX.lock().expect("Cannot get lock");
23+
unsafe { $call }
24+
}
2325
}
2426
}
2527

2628
pub mod array;
2729
pub mod error;
28-
pub mod nae;
29-
30-
pub use ffi::fftw_complex as c64;
31-
pub use ffi::fftwf_complex as c32;
32-
33-
#[repr(i32)]
34-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
35-
pub enum Sign {
36-
Forward = -1,
37-
Backward = 1,
38-
}
39-
40-
impl ::std::ops::Neg for Sign {
41-
type Output = Sign;
42-
fn neg(self) -> Self::Output {
43-
match self {
44-
Sign::Forward => Sign::Backward,
45-
Sign::Backward => Sign::Forward,
46-
}
47-
}
48-
}
49-
50-
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
51-
pub enum Flag {
52-
Measure,
53-
DestroyInput,
54-
Unaligned,
55-
ConserveMemory,
56-
Exhausive,
57-
PreserveInput,
58-
Patient,
59-
Estimate,
60-
WisdowmOnly,
61-
Mixed(u32),
62-
}
63-
64-
impl Into<u32> for Flag {
65-
fn into(self) -> u32 {
66-
use Flag::*;
67-
match self {
68-
Measure => 0,
69-
DestroyInput => 1 << 0,
70-
Unaligned => 1 << 1,
71-
ConserveMemory => 1 << 2,
72-
Exhausive => 1 << 3,
73-
PreserveInput => 1 << 4,
74-
Patient => 1 << 5,
75-
Estimate => 1 << 6,
76-
WisdowmOnly => 1 << 21,
77-
Mixed(u) => u,
78-
}
79-
}
80-
}
81-
82-
impl ::std::ops::BitOr for Flag {
83-
type Output = Self;
84-
fn bitor(self, rhs: Self) -> Self {
85-
let lhs: u32 = self.into();
86-
let rhs: u32 = rhs.into();
87-
Flag::Mixed(lhs | rhs)
88-
}
89-
}
30+
pub mod plan;
31+
pub mod types;

src/nae.rs renamed to src/plan.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::*;
1+
use types::*;
22
use error::*;
33
use ffi::*;
44

@@ -104,8 +104,6 @@ where
104104
}
105105
}
106106

107-
pub type R2RKind = ffi::fftw_r2r_kind;
108-
109107
#[derive(Debug)]
110108
pub struct R2RPlan<R: FFTW> {
111109
plan: R::Plan,

src/types.rs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
use ffi;
3+
4+
pub use ffi::fftw_complex as c64;
5+
pub use ffi::fftwf_complex as c32;
6+
7+
pub type R2RKind = ffi::fftw_r2r_kind;
8+
9+
#[repr(i32)]
10+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
11+
pub enum Sign {
12+
Forward = -1,
13+
Backward = 1,
14+
}
15+
16+
impl ::std::ops::Neg for Sign {
17+
type Output = Sign;
18+
fn neg(self) -> Self::Output {
19+
match self {
20+
Sign::Forward => Sign::Backward,
21+
Sign::Backward => Sign::Forward,
22+
}
23+
}
24+
}
25+
26+
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
27+
pub enum Flag {
28+
Measure,
29+
DestroyInput,
30+
Unaligned,
31+
ConserveMemory,
32+
Exhausive,
33+
PreserveInput,
34+
Patient,
35+
Estimate,
36+
WisdowmOnly,
37+
Mixed(u32),
38+
}
39+
40+
impl Into<u32> for Flag {
41+
fn into(self) -> u32 {
42+
use self::Flag::*;
43+
match self {
44+
Measure => 0,
45+
DestroyInput => 1 << 0,
46+
Unaligned => 1 << 1,
47+
ConserveMemory => 1 << 2,
48+
Exhausive => 1 << 3,
49+
PreserveInput => 1 << 4,
50+
Patient => 1 << 5,
51+
Estimate => 1 << 6,
52+
WisdowmOnly => 1 << 21,
53+
Mixed(u) => u,
54+
}
55+
}
56+
}
57+
58+
impl ::std::ops::BitOr for Flag {
59+
type Output = Self;
60+
fn bitor(self, rhs: Self) -> Self {
61+
let lhs: u32 = self.into();
62+
let rhs: u32 = rhs.into();
63+
Flag::Mixed(lhs | rhs)
64+
}
65+
}

0 commit comments

Comments
 (0)