-
Notifications
You must be signed in to change notification settings - Fork 12
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
209 pyo3 simdrivelabel #25
Conversation
@@ -49,45 +51,26 @@ lazy_static! { | |||
self.mc_peak_eff() | |||
} | |||
|
|||
// TODO: refactor this to have a non-py and `_py` version |
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.
@Romia87 , I made some edits to your changes and the code is correct now. I had actually left that TODO
note for myself months (maybe even years ???) ago and forgotten about it so it's good you got this to happen!
.iter() | ||
.map(|e: &f64| -> f64 { e * (new_peak / mc_max_full_eff) }) | ||
.collect(); | ||
#[setter("mc_peak_eff")] |
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.
#[setter("mc_peak_eff")]
makes it so that can run veh.mc_peak_eff = 0.44
in Python. set_mc_peak_eff_py
then calls set_mc_peak_eff
, the pure Rust version.
@@ -37,6 +37,8 @@ lazy_static! { | |||
#[add_pyo3_api( |
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.
@Romia87 , any arguments (e.g. function definitions) that get provided to add_pyo3_api
do not get compiled unless the fastsim-py
crate is being compiled because of this feature. As such, we want the pure rust versions of functions to live elsewhere. I'll drop a note on that next.
@@ -578,6 +562,32 @@ impl RustVehicle { | |||
arrmax(&self.fc_eff_array) | |||
} | |||
|
|||
pub fn set_mc_peak_eff(&mut self, new_peak: f64) { |
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.
@Romia87 , this where the pure rust functions live, and in this location, they get compiled every time no matter what features are enabled or disabled.
We created the add_pyo3_api
attribute-style procedural macro because it allows us to automate a lot of the pyo3
features for exposing struct fields to python. It also allow use to pass the pymethods block as an argument so that all the pymethods
definitions can live in a single impl
block, which is a requirement of pyo3. It took months and lots of tedious troubleshooting to get this worked out.
…pyo3-simdrivelabel
…pyo3-simdrivelabel
@@ -704,7 +709,7 @@ pub fn get_label_fe_phev( | |||
}; | |||
} | |||
|
|||
Ok(phev_calcs) | |||
return Ok(phev_calcs); |
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 idiomatic way to return in rust is Ok(phev_calcs)
so please change return Ok(phev_calcs);
back to Ok(phev_calcs)
since it will otherwise give warnings whenever we run cargo clippy
.
@Romia87, this pymethods attribute and this pymethods attribute are redundant, unnecessary, and not allowed because that's taken care of in the add_pyo3_api procedural macro. Also, none of these setters and getters, thees getters and setters, or these getters and setters are necessary because inside of Rust, the fields of PHEVCycleCalc are all let mut phev_cycle_calc = PHEVCycleCalc::default();
phev_cycle_calc.cd_fs_gal = 2.2;
println!("{}", phev_cycle_calc.cd_fs_gal); without needing getters and setters. Additionally, the |
No description provided.