-
-
Notifications
You must be signed in to change notification settings - Fork 359
Add FFT in Rust #688
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
Add FFT in Rust #688
Conversation
This code is incomplete right now. (It hasn't resolved all compiler warnings/errors, and I haven't put it through Clippy yet.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change all the &[Complex<f64>]
to Vec<Complex<f64>>
then you can drop the references and just move the value into the functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a big ask, but I think that, like at least the Julia and C implementations, this should compare to FFTW. It looks like the de facto crate is https://crates.io/crates/fftw.
let mut v = Complex::new(1.0_f64, 0.0_f64); | ||
for k in 0..((stride / 2) as usize) { | ||
let k_plus_j = new_x[k + j]; | ||
let k_plus_j_plus_half_stride = new_x[k + j + ((stride / 2) as usize)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this intermediate and k_plus_j_plus_half_stride_2
, since they're only used in one place each, don't buy you anything and make the code harder to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In getting rid of those three intermediates, I had to sacrifice the -=
operator. If I didn't do that, the compiler warns that I "cannot borrow new_x
as immutable because it is also borrowed as mutable".
}) | ||
.sum() | ||
}) | ||
.collect::<Vec<_>>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The turbofish isn't necessary here due to the return type in the function signature.
} | ||
let y = cooley_tukey(&x.clone()); | ||
let z = iterative_cooley_tukey(&x.clone()); | ||
let t = dft(&x.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed, these don't need to be cloned either.
I also think that you should leave the functions as not taking ownership.
We don't need to borrow a clone of an object if we only need to borrow the object.
@berquist I'll try to add references to fftw later. (Note that #686 actually uses a different crate that offers a pure Rust FFT implementation.) |
If you think using |
@berquist I have implemented |
I think this will be fine, but is there a better way for me to test this other than creating a temporary Cargo package and running it inside? |
I tested my last submission with just rustc. |
I'm getting
with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
Moving the arguments into the functions doesn't seem important, since you don't need to take ownership of the input, unless you can figure out how to do the operations in-place.
* Add rust builder and build script * Move file to be discovered by SCons, and update Cargo.toml to reflect this * Add rustc to SCons * Add Cargo.toml files for code requiring libraries * Add cargo building when Cargo.toml is present * Fix copying fail on linux due to directory name and file name collision * Add build artifacts to SCons clean command and .gitignore * Fix Not a directory issue due to getting parent directory of a file * Remove redefinition of languages dictionary * Add rustc and cargo install to docker * Update Cooley-Tukey to use correct version of crates * Update split-operator method to use correct library versions and apply fixes from #688
@Liikt (and maybe @strega-nil) I felt like I had to do something
dirtya little bit inelegant in order to make Clippy shut up. (You'll see what I mean.)