Skip to content
Open
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
13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ bench = false
test = true

[dependencies]
num-traits = ">=0.0.0"
num-complex = ">=0.0.0"
num-traits = { version = "0.2.9", default-features = false }
num-complex = { version = "0.2.3", default-features = false }

[dev-dependencies]
rand = ">=0.7.0"
rand_xorshift = ">=0.2.0"
rand = "0.7.2"
rand_xorshift = "0.2.0"

[dev-dependencies.appro-eq]
version=">=0.0.0"
version= "0.3.0"
features=["complex"]

[features]
default = ["std"]
docs = []
std = ["num-traits/std", "num-complex/std"]
libm = ["num-traits/libm"]
3 changes: 3 additions & 0 deletions src/cfft1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ use num_traits::float::{Float, FloatConst};
use num_traits::identities::{one, zero};
use num_traits::{cast, NumAssign};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[derive(Debug)]
enum WorkData<T> {
MixedRadix(mixed_radix::MixedRadixData<T>),
Expand Down
3 changes: 3 additions & 0 deletions src/cfft2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use num_traits::float::{Float, FloatConst};
use num_traits::identities::{one, zero};
use num_traits::{cast, NumAssign};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

/// Perform a complex-to-complex two-dimensional Fourier transform
///
/// <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>
Expand Down
3 changes: 3 additions & 0 deletions src/chirpz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use num_traits::float::Float;
use num_traits::identities::{one, zero};
use num_traits::NumAssign;

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[derive(Debug)]
pub(crate) struct ChirpzData<T> {
pub(crate) level: usize,
Expand Down
3 changes: 3 additions & 0 deletions src/dct1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use num_traits::float::{Float, FloatConst};
use num_traits::identities::{one, zero};
use num_traits::{cast, NumAssign};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

/// Perform a discrete cosine transform
///
/// # Example
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![crate_type = "lib"]
#![cfg_attr(not(feature = "std"), no_std)]

//! Chalharu's Fastest Fourier Transform.
//!
Expand All @@ -7,6 +8,13 @@
//! version 2.0 (the "License"). You can obtain a copy of the License at
//! http://mozilla.org/MPL/2.0/ .

#[cfg(not(any(feature = "std", feature = "libm")))]
compile_error!("Either feature 'std' or feature 'libm' must be enabled for 'chfft' to work");

#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;

mod chirpz;
mod mixed_radix;
mod precompute_utils;
Expand Down
3 changes: 3 additions & 0 deletions src/mdct1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use num_traits::float::{Float, FloatConst};
use num_traits::identities::zero;
use num_traits::{cast, one, NumAssign};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

/// Perform a Modified discrete cosine transform
///
/// <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>
Expand Down
3 changes: 3 additions & 0 deletions src/mixed_radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use num_traits::float::{Float, FloatConst};
use num_traits::identities::one;
use num_traits::{cast, NumAssign};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[derive(Debug)]
pub(crate) struct MixedRadixData<T> {
pub(crate) ids: Vec<usize>,
Expand Down
15 changes: 11 additions & 4 deletions src/precompute_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ use num_complex::Complex;
use num_traits::cast;
use num_traits::float::{Float, FloatConst};
use num_traits::identities::one;

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use core::cmp;
#[cfg(feature = "std")]
use std::cmp;

#[inline]
pub(crate) fn calc_omega_item<T: Float + FloatConst>(len: usize, position: usize) -> Complex<T> {
Complex::from_polar(
&one(),
&(cast::<_, T>(-2.0).unwrap() * T::PI() / cast(len).unwrap() * cast(position).unwrap()),
)
let r: T = one();
let theta: T =
cast::<_, T>(-2.0).unwrap() * T::PI() / cast(len).unwrap() * cast(position).unwrap();
// We can't use Complex::from_polar because it is at the time of writing not no_std compatible
Complex::new(r * theta.cos(), r * theta.sin())
}

// ωの事前計算
Expand Down
3 changes: 3 additions & 0 deletions src/prime_factorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
//! version 2.0 (the "License"). You can obtain a copy of the License at
//! http://mozilla.org/MPL/2.0/ .

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[derive(Debug)]
pub(crate) struct Factor {
pub(crate) value: usize,
Expand Down
3 changes: 3 additions & 0 deletions src/rfft1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use num_traits::float::{Float, FloatConst};
use num_traits::identities::{one, zero};
use num_traits::{cast, NumAssign};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

/// Perform a real-to-complex one-dimensional Fourier transform
///
/// <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>
Expand Down