Skip to content
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

chore(docs): enhance the example in the README #34

Merged
merged 1 commit into from
Jul 18, 2024
Merged
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
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,33 @@ Additionally, an optional 128-bit negacyclic FFT module is provided.

```rust
use concrete_fft::c64;
use concrete_fft::ordered::{Plan, Method};
use dyn_stack::{PodStack, GlobalPodBuffer, ReborrowMut};
use concrete_fft::ordered::{Method, Plan};
use dyn_stack::{GlobalPodBuffer, PodStack, ReborrowMut};
use num_complex::ComplexFloat;
use std::time::Duration;

const N: usize = 4;
let plan = Plan::new(4, Method::Measure(Duration::from_millis(10)));
let mut scratch_memory = GlobalPodBuffer::new(plan.fft_scratch().unwrap());
let mut stack = PodStack::new(&mut scratch_memory);
fn main() {
const N: usize = 4;
let plan = Plan::new(4, Method::Measure(Duration::from_millis(10)));
let mut scratch_memory = GlobalPodBuffer::new(plan.fft_scratch().unwrap());
let mut stack = PodStack::new(&mut scratch_memory);

let data = [
c64::new(1.0, 0.0),
c64::new(2.0, 0.0),
c64::new(3.0, 0.0),
c64::new(4.0, 0.0),
];
let data = [
c64::new(1.0, 0.0),
c64::new(2.0, 0.0),
c64::new(3.0, 0.0),
c64::new(4.0, 0.0),
];

let mut transformed_fwd = data;
plan.fwd(&mut transformed_fwd, stack.rb_mut());
let mut transformed_fwd = data;
plan.fwd(&mut transformed_fwd, stack.rb_mut());

let mut transformed_inv = transformed_fwd;
plan.inv(&mut transformed_inv, stack.rb_mut());
let mut transformed_inv = transformed_fwd;
plan.inv(&mut transformed_inv, stack.rb_mut());

for (actual, expected) in transformed_inv.iter().map(|z| z / N as f64).zip(data) {
assert!((expected - actual).abs() < 1e-9);
for (actual, expected) in transformed_inv.iter().map(|z| z / N as f64).zip(data) {
assert!((expected - actual).abs() < 1e-9);
}
}
```

Expand Down
Loading