Skip to content

Add Split-Operator in Rust #686

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 2 commits into from
May 17, 2020

Conversation

fanninpm
Copy link
Contributor

@fanninpm fanninpm commented May 6, 2020

@Gathros and @strega-nil do you want to help make this code more rusty, especially with those very short for-loops. (I essentially translated the preexisting C++ implementation and kept fighting the borrow checker until it worked.)

@fanninpm fanninpm marked this pull request as ready for review May 6, 2020 03:08
@Gathros
Copy link
Contributor

Gathros commented May 6, 2020

I don't know rust enough to be able to review it, but I think @Liikt can help you.

Copy link

@Liikt Liikt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me. 👍

let mut density: Vec<f64>;

for i in 0..par.timesteps {
// this should use an iterator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how you turn this into an iterator as you need the index for accessing a different array than the one you are iterating over. Not saying it is impossible, just harder. I think this is perfectly fine. This also makes the code a bit clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized I could've used the enumerate() method, but (as you point out) that may come at the cost of clarity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't mind using that either. It just depends on what Rust users are used to reading.

@leios
Copy link
Member

leios commented May 6, 2020

Cool, I am happy to merge if @fanninpm is happy as well. Maybe remove the this should be an iterator comment?

Thanks for hopping in folks!

Also, no problem if you want to keep fiddling with it!

The small for-loops are fine as they are.
@fanninpm
Copy link
Contributor Author

fanninpm commented May 6, 2020

If you guys think this is fine as is, I'm happy to see it merged.

@leios
Copy link
Member

leios commented May 6, 2020

I'll do a final look-over later. Probably on stream.

@leios
Copy link
Member

leios commented May 6, 2020

I ran this locally and got the expected results, so it is good to merge as soon as you are happy with the code (just let me know if you want to use enumerate() or not).

As a question, I am not good with rust, how do you normally compile this type of stuff? Would it be worth adding a cargo.toml file or something?

@fanninpm
Copy link
Contributor Author

fanninpm commented May 6, 2020

If this were in a standalone project, I would be using a Cargo.toml file and running cargo build or cargo run in lieu of rustc, because it depends on crates not found in the standard library. (Specifically, I make use of the latest versions of num and rustfft as of 5 May 2020.)

Since I didn't want to disturb the existing directory structure, I developed this on repl.it. Per #691, if you want to add a Cargo.toml file, be my guest.

Anyway, I'm happy with the code as is. @Liikt would it hurt to remove the two instances of extern crate, as they're no longer required in Rust 2018? That would be my only other outstanding reservation I have with the code. (By the way, if you're interested in learning more about iterators vs. for loops in Rust, I'd recommend reading this section of the Rust Book.)

@leios
Copy link
Member

leios commented May 17, 2020

I am happy with this PR as is, great work! Thanks for the code!

@leios leios merged commit c3ac3be into algorithm-archivists:master May 17, 2020
@fanninpm fanninpm deleted the split_operator_in_rust branch May 18, 2020 00:21
@fanninpm fanninpm mentioned this pull request May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants