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

(feat) improve rss_errors() using a functional programming approach #177

Merged
merged 3 commits into from
Jun 10, 2023
Merged

(feat) improve rss_errors() using a functional programming approach #177

merged 3 commits into from
Jun 10, 2023

Conversation

ThibFrgsGmz
Copy link
Contributor

  • Improve docstrings on rss_* utility functions from utils.rs
  • Make rss_errors kind of more idiomatic using a functional programming way

I tried to put some UT but I did not well understood how to do them.

For example, we could have:

    #[test]
    fn test_rss_errors() {
        let prop_err = OVector::from_vec(vec![1.0, 2.0, 3.0]);
        let cur_state = OVector::from_vec(vec![1.0, 2.0, 3.0]);
        assert_eq!(rss_errors(&prop_err, &cur_state), 0.0);

        let prop_err = OVector::from_vec(vec![1.0, 2.0, 3.0]);
        let cur_state = OVector::from_vec(vec![4.0, 5.0, 6.0]);
        assert_eq!(rss_errors(&prop_err, &cur_state), 5.196152422706632);
    }

But I currently have some compiler complains about from_vec, so I gave up and trust the CI.

I hope to get feedback from you on this subject!

@codecov
Copy link

codecov bot commented Jun 9, 2023

Codecov Report

Patch coverage: 70.83% and project coverage change: +0.15 🎉

Comparison is base (2ee5225) 66.33% compared to head (e107020) 66.49%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #177      +/-   ##
==========================================
+ Coverage   66.33%   66.49%   +0.15%     
==========================================
  Files         127      127              
  Lines       32445    32455      +10     
==========================================
+ Hits        21524    21580      +56     
+ Misses      10921    10875      -46     
Impacted Files Coverage Δ
src/utils.rs 58.95% <70.83%> (+7.55%) ⬆️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@ChristopherRabotin ChristopherRabotin left a comment

Choose a reason for hiding this comment

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

We can add some unit tests for sure. At the moment, these two functions are used in the propagator when we're using an adaptive time step, so they're frequently hit. The results of the propagators exactly match GMAT, so I'm pretty confident that they're correct and that any new bug in those functions would be caught immediately.

If you want to add units tests, I wrote a quick example of different common ways to initialize a vector using nalgebra: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=00f15985f45e6c43e3ab1469bd310cb3 .

v += (prop_err[i] - cur_state[i]).powi(2);
}
v.sqrt()
prop_err
Copy link
Member

Choose a reason for hiding this comment

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

Good idea! I initially seem to have written this in April 2018 (the 2021 commit is got a change in nalgebra), and that was before I used any FP in Rust.

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 added the UT based on the way you created OVector in the code snippet you shared.

src/utils.rs Outdated
///
/// # Returns
///
/// * A f64 value representing the RSS state error.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// * A f64 value representing the RSS state error.
/// A f64 value representing the RSS state error.

(minor) I don't think we need this to be a bullet point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/utils.rs Outdated
///
/// # Returns
///
/// * A tuple of f64 values representing the RSS orbit errors in radius and velocity.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// * A tuple of f64 values representing the RSS orbit errors in radius and velocity.
/// A tuple of f64 values representing the RSS orbit errors in radius and velocity.

(minor) idem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/utils.rs Outdated
///
/// # Returns
///
/// * A tuple of f64 values representing the RSS orbit vector errors in radius and velocity.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// * A tuple of f64 values representing the RSS orbit vector errors in radius and velocity.
/// A tuple of f64 values representing the RSS orbit vector errors in radius and velocity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@ChristopherRabotin ChristopherRabotin merged commit 338ad97 into nyx-space:master Jun 10, 2023
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.

2 participants