Skip to content

Commit 713b3a6

Browse files
committed
Update pre-commit hook to run clippy everywhere
1 parent e94f2fc commit 713b3a6

File tree

6 files changed

+86
-70
lines changed

6 files changed

+86
-70
lines changed

benches/README.md

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,26 @@
44

55
### Setup Environment
66

7-
1. Install [FFTW3](http://www.fftw.org/download.html)[^1]
7+
1. Clone the `PhastFT` git repository [^2].
88

9-
It may be possible to install `fftw3` using a package manager.
10-
11-
##### debian
12-
```bash
13-
sudo apt install libfftw3-dev
14-
```
15-
16-
2. Clone the `PhastFT` git repository [^2].
17-
18-
3. Create virtual env
9+
2. Create virtual env
1910

2011
```bash
2112
cd ~/PhastFT/benches && python3 -m venv .env && source .env/bin/activate
2213
```
2314

24-
4. Install python dependencies[^1]
15+
3. Install python dependencies[^1]
2516

2617
```bash
2718
pip install -r requirements.txt
2819
cd ~/PhastFT/pyphastft
2920
pip install .
3021
```
3122

32-
5. Run the `FFTW3` vs. `RustFFT` vs. `PhastFT` benchmark for all inputs of size `2^n`, where `n \in [4, 30].`
23+
5. Run the `FFTW3-RB` vs. `RustFFT` vs. `PhastFT` benchmarks`
3324

3425
```bash
35-
./benchmark.sh 4 29
26+
python run_benches.py
3627
```
3728

3829
6. Plot the results
@@ -101,13 +92,6 @@ On linux, open access to performance monitoring, and observability operations fo
10192
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
10293
```
10394

104-
Add debug to `Cargo.toml` under `profile.release`:
105-
106-
```bash
107-
[profile.release]
108-
debug = true
109-
```
110-
11195
Finally, run:
11296

11397
```bash

benches/bench.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn benchmark_forward_f32(c: &mut Criterion) {
6969
let planner = Planner32::new(len, Direction::Forward);
7070
let (mut reals, mut imags) = generate_numbers(len);
7171

72-
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &len| {
72+
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &_len| {
7373
b.iter(|| {
7474
fft_32_with_opts_and_plan(
7575
black_box(&mut reals),
@@ -85,7 +85,7 @@ fn benchmark_forward_f32(c: &mut Criterion) {
8585
let fft = planner.plan_fft_forward(len);
8686
let mut signal = generate_complex_numbers(len);
8787

88-
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &len| {
88+
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &_len| {
8989
b.iter(|| fft.process(black_box(&mut signal)));
9090
});
9191
}
@@ -103,9 +103,12 @@ fn benchmark_inverse_f32(c: &mut Criterion) {
103103
c.bench_function(&id, |b| {
104104
let (mut reals, mut imags) = generate_numbers(len);
105105
b.iter(|| {
106-
black_box(fft_32_with_opts_and_plan(
107-
&mut reals, &mut imags, &options, &planner,
108-
));
106+
fft_32_with_opts_and_plan(
107+
black_box(&mut reals),
108+
black_box(&mut imags),
109+
black_box(&options),
110+
black_box(&planner),
111+
);
109112
});
110113
});
111114
}
@@ -122,7 +125,7 @@ fn benchmark_forward_f64(c: &mut Criterion) {
122125
let (mut reals, mut imags) = generate_numbers(len);
123126
group.throughput(Throughput::Elements(len as u64));
124127

125-
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &len| {
128+
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &_len| {
126129
b.iter(|| {
127130
fft_64_with_opts_and_plan(
128131
black_box(&mut reals),
@@ -138,7 +141,7 @@ fn benchmark_forward_f64(c: &mut Criterion) {
138141
let fft = planner.plan_fft_forward(len);
139142
let mut signal = generate_complex_numbers(len);
140143

141-
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &len| {
144+
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &_len| {
142145
b.iter(|| fft.process(black_box(&mut signal)));
143146
});
144147
}
@@ -156,19 +159,22 @@ fn benchmark_inverse_f64(c: &mut Criterion) {
156159
c.bench_function(&id, |b| {
157160
let (mut reals, mut imags) = generate_numbers(len);
158161
b.iter(|| {
159-
black_box(fft_64_with_opts_and_plan(
160-
&mut reals, &mut imags, &options, &planner,
161-
));
162+
fft_64_with_opts_and_plan(
163+
black_box(&mut reals),
164+
black_box(&mut imags),
165+
black_box(&options),
166+
black_box(&planner),
167+
);
162168
});
163169
});
164170
}
165171
}
166172

167173
criterion_group!(
168174
benches,
169-
// benchmark_forward_f32,
170-
// benchmark_inverse_f32,
175+
benchmark_forward_f32,
176+
benchmark_inverse_f32,
171177
benchmark_forward_f64,
172-
// benchmark_inverse_f64
178+
benchmark_inverse_f64
173179
);
174180
criterion_main!(benches);

hooks/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ then
99
exit 1
1010
fi
1111

12-
if ! cargo clippy -- -D warnings
12+
if ! cargo clippy --all-targets --all-features --tests -- -D warnings
1313
then
1414
echo "There are some clippy issues."
1515
exit 1
1616
fi
1717

18-
if ! cargo test
18+
if ! cargo test --all-features
1919
then
2020
echo "There are some test issues."
2121
exit 1

src/lib.rs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@
1111
#![feature(portable_simd, avx512_target_feature)]
1212

1313
#[cfg(feature = "complex-nums")]
14-
use std::simd::{f32x16, f64x8};
15-
16-
#[cfg(feature = "complex-nums")]
17-
use bytemuck::cast_slice;
14+
use crate::utils::{combine_re_im, deinterleave_complex32, deinterleave_complex64};
1815
#[cfg(feature = "complex-nums")]
1916
use num_complex::Complex;
20-
#[cfg(feature = "complex-nums")]
21-
use num_traits::Float;
2217

2318
use crate::cobra::cobra_apply;
2419
use crate::kernels::{
@@ -96,9 +91,9 @@ macro_rules! impl_fft_interleaved_for {
9691
}
9792

9893
#[cfg(feature = "complex-nums")]
99-
impl_fft_interleaved_for!(fft_32_interleaved, f32, fft_32, separate_re_im_f32);
94+
impl_fft_interleaved_for!(fft_32_interleaved, f32, fft_32, deinterleave_complex32);
10095
#[cfg(feature = "complex-nums")]
101-
impl_fft_interleaved_for!(fft_64_interleaved, f64, fft_64, separate_re_im_f64);
96+
impl_fft_interleaved_for!(fft_64_interleaved, f64, fft_64, deinterleave_complex64);
10297

10398
macro_rules! impl_fft_with_opts_and_plan_for {
10499
($func_name:ident, $precision:ty, $planner:ty, $simd_butterfly_kernel:ident, $lanes:literal) => {
@@ -240,25 +235,6 @@ mod tests {
240235

241236
use super::*;
242237

243-
#[cfg(feature = "complex-nums")]
244-
#[test]
245-
fn test_separate_and_combine_re_im() {
246-
use utils::deinterleave;
247-
248-
let complex_vec: Vec<_> = vec![
249-
Complex::new(1.0, 2.0),
250-
Complex::new(3.0, 4.0),
251-
Complex::new(5.0, 6.0),
252-
Complex::new(7.0, 8.0),
253-
];
254-
255-
let (reals, imags) = deinterleave(&complex_vec);
256-
257-
let recombined_vec = combine_re_im(&reals, &imags);
258-
259-
assert_eq!(complex_vec, recombined_vec);
260-
}
261-
262238
macro_rules! non_power_of_2_planner {
263239
($test_name:ident, $planner:ty) => {
264240
#[should_panic]
@@ -436,9 +412,9 @@ mod tests {
436412
let mut re = reals.clone();
437413
let mut im = imags.clone();
438414

439-
let mut planner = Planner64::new(num_points, Direction::Forward);
415+
let planner = Planner64::new(num_points, Direction::Forward);
440416
let opts = Options::guess_options(reals.len());
441-
fft_64_with_opts_and_plan(&mut reals, &mut imags, &opts, &mut planner);
417+
fft_64_with_opts_and_plan(&mut reals, &mut imags, &opts, &planner);
442418

443419
fft_64(&mut re, &mut im, Direction::Forward);
444420

@@ -467,9 +443,9 @@ mod tests {
467443
let mut re = reals.clone();
468444
let mut im = imags.clone();
469445

470-
let mut planner = Planner32::new(num_points, direction);
446+
let planner = Planner32::new(num_points, direction);
471447
let opts = Options::guess_options(reals.len());
472-
fft_32_with_opts_and_plan(&mut reals, &mut imags, &opts, &mut planner);
448+
fft_32_with_opts_and_plan(&mut reals, &mut imags, &opts, &planner);
473449

474450
fft_32(&mut re, &mut im, direction);
475451

src/twiddles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ mod tests {
239239

240240
let actual_w_im = -fwd_twiddles_re[(i + dist / 2) % dist];
241241
//assert_float_closeness(actual_w_im, expected_w_im, 1e-6);
242-
print!("actual: {actual_w_im} expected: {expected_w_im}\n");
242+
println!("actual: {actual_w_im} expected: {expected_w_im}");
243243
}
244244
println!("{:?}", fwd_twiddles_re);
245245
println!("{:?}", fwd_twiddles_im);

src/utils.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
//! Utility functions such as interleave/deinterleave
22
3+
#[cfg(feature = "complex-nums")]
4+
use num_complex::Complex;
5+
6+
#[cfg(feature = "complex-nums")]
7+
use num_traits::Float;
8+
9+
#[cfg(feature = "complex-nums")]
10+
use bytemuck::cast_slice;
11+
312
use std::simd::{prelude::Simd, simd_swizzle, SimdElement};
413

514
// We don't multiversion for AVX-512 here and keep the chunk size below AVX-512
@@ -59,6 +68,30 @@ pub(crate) fn deinterleave<T: Copy + Default + SimdElement>(input: &[T]) -> (Vec
5968
(out_odd, out_even)
6069
}
6170

71+
/// Utility function to separate a slice of [`Complex64``]
72+
/// into a single vector of Complex Number Structs.
73+
///
74+
/// # Panics
75+
///
76+
/// Panics if `reals.len() != imags.len()`.
77+
#[cfg(feature = "complex-nums")]
78+
pub(crate) fn deinterleave_complex64(signal: &[Complex<f64>]) -> (Vec<f64>, Vec<f64>) {
79+
let complex_t: &[f64] = cast_slice(signal);
80+
deinterleave(complex_t)
81+
}
82+
83+
/// Utility function to separate a slice of [`Complex32``]
84+
/// into a single vector of Complex Number Structs.
85+
///
86+
/// # Panics
87+
///
88+
/// Panics if `reals.len() != imags.len()`.
89+
#[cfg(feature = "complex-nums")]
90+
pub(crate) fn deinterleave_complex32(signal: &[Complex<f32>]) -> (Vec<f32>, Vec<f32>) {
91+
let complex_t: &[f32] = cast_slice(signal);
92+
deinterleave(complex_t)
93+
}
94+
6295
/// Utility function to combine separate vectors of real and imaginary components
6396
/// into a single vector of Complex Number Structs.
6497
///
@@ -78,10 +111,10 @@ pub(crate) fn combine_re_im<T: Float>(reals: &[T], imags: &[T]) -> Vec<Complex<T
78111

79112
#[cfg(test)]
80113
mod tests {
81-
use super::deinterleave;
114+
use super::*;
82115

83116
fn gen_test_vec(len: usize) -> Vec<usize> {
84-
(0..len).into_iter().collect()
117+
(0..len).collect()
85118
}
86119

87120
/// Slow but obviously correct implementation of deinterleaving,
@@ -100,4 +133,21 @@ mod tests {
100133
assert_eq!(naive_b, opt_b);
101134
}
102135
}
136+
137+
#[cfg(feature = "complex-nums")]
138+
#[test]
139+
fn test_separate_and_combine_re_im() {
140+
let complex_vec: Vec<_> = vec![
141+
Complex::new(1.0, 2.0),
142+
Complex::new(3.0, 4.0),
143+
Complex::new(5.0, 6.0),
144+
Complex::new(7.0, 8.0),
145+
];
146+
147+
let (reals, imags) = deinterleave_complex64(&complex_vec);
148+
149+
let recombined_vec = combine_re_im(&reals, &imags);
150+
151+
assert_eq!(complex_vec, recombined_vec);
152+
}
103153
}

0 commit comments

Comments
 (0)