Skip to content

Drop Pair interface #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ source = ["fftw-sys/source"]
intel-mkl = ["fftw-sys/intel-mkl"]

[dependencies]
num-traits = "0.1.37"
num-complex = "0.1.37"
lazy_static = "0.2.2"
derive-new = "0.4"
ndarray = "0.10"
ndarray-linalg = "0.7"
num-traits = "0.1"
num-complex = "0.1"
lazy_static = "0.2"
derive-new = "0.5"
ndarray = "0.11"
procedurals = "0.2"

[dependencies.fftw-sys]
Expand Down
18 changes: 0 additions & 18 deletions examples/r2r.rs

This file was deleted.

10 changes: 3 additions & 7 deletions src/array.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{c32, c64, FFTW_MUTEX};
use error::*;
use ffi;
use types::*;

use ndarray::*;
use num_traits::Zero;
Expand Down Expand Up @@ -147,9 +147,7 @@ impl<T> DerefMut for AlignedVec<T> {

impl<T> Drop for AlignedVec<T> {
fn drop(&mut self) {
let lock = FFTW_MUTEX.lock().expect("Cannot get lock");
unsafe { ffi::fftw_free(self.data as *mut c_void) };
drop(lock);
excall! { ffi::fftw_free(self.data as *mut c_void) };
}
}

Expand All @@ -159,9 +157,7 @@ where
{
/// Create array with `fftw_malloc` (`fftw_free` is automatically called when the arrya is `Drop`-ed)
pub fn new(n: usize) -> Self {
let lock = FFTW_MUTEX.lock().expect("Cannot get lock");
let ptr = unsafe { T::alloc(n) };
drop(lock);
let ptr = excall! { T::alloc(n) };
let mut vec = AlignedVec { n: n, data: ptr };
for v in vec.iter_mut() {
*v = T::zero();
Expand Down
42 changes: 0 additions & 42 deletions src/c2c.rs

This file was deleted.

7 changes: 2 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use ndarray::ShapeError;
pub use ndarray_linalg::error::{MemoryContError, StrideError};

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

use super::nae::NAEInputMismatchError;
use super::plan::InputMismatchError;

#[derive(Debug, IntoEnum)]
pub enum Error {
InvalidPlanError(InvalidPlanError),
ShapeError(ShapeError),
StrideError(StrideError),
MemoryContError(MemoryContError),
NAEInputMismatchError(NAEInputMismatchError),
InputMismatchError(InputMismatchError),
}

#[derive(Debug, new)]
Expand Down
94 changes: 14 additions & 80 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,28 @@ extern crate lazy_static;
#[macro_use]
extern crate procedurals;

extern crate fftw_sys as ffi;

extern crate ndarray;
extern crate num_complex;
extern crate num_traits;
// XXX For ndarray_linalg::Scalar
// Will be removed if the following PR to num-complex is merged
// https://github.com/rust-num/num/pull/338
extern crate ndarray_linalg;

extern crate fftw_sys as ffi;

pub mod pair;
pub mod r2r;
pub mod r2c;
pub mod c2c;
pub mod array;
pub mod error;
pub mod plan;
pub mod nae;
pub mod traits;

pub use ffi::fftw_complex as c64;
pub use ffi::fftwf_complex as c32;

pub use c2c::*;
pub use pair::*;
pub use r2c::*;
pub use r2r::*;
pub use traits::*;

use std::sync::Mutex;

lazy_static! {
pub static ref FFTW_MUTEX: Mutex<()> = Mutex::new(());
}

#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Sign {
Forward = -1,
Backward = 1,
}

impl ::std::ops::Neg for Sign {
type Output = Sign;
fn neg(self) -> Self::Output {
match self {
Sign::Forward => Sign::Backward,
Sign::Backward => Sign::Forward,
}
}
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Flag {
Measure,
DestroyInput,
Unaligned,
ConserveMemory,
Exhausive,
PreserveInput,
Patient,
Estimate,
WisdowmOnly,
Mixed(u32),
}

impl Into<u32> for Flag {
fn into(self) -> u32 {
use Flag::*;
match self {
Measure => 0,
DestroyInput => 1 << 0,
Unaligned => 1 << 1,
ConserveMemory => 1 << 2,
Exhausive => 1 << 3,
PreserveInput => 1 << 4,
Patient => 1 << 5,
Estimate => 1 << 6,
WisdowmOnly => 1 << 21,
Mixed(u) => u,
}
/// Exclusive call of FFTW interface.
macro_rules! excall {
($call:expr) => {
{
let _lock = $crate::FFTW_MUTEX.lock().expect("Cannot get lock");
unsafe { $call }
}
}
}} // excall!

impl ::std::ops::BitOr for Flag {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
let lhs: u32 = self.into();
let rhs: u32 = rhs.into();
Flag::Mixed(lhs | rhs)
}
}
pub mod array;
pub mod error;
pub mod types;
pub mod plan;
Loading