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

eval_equation and tests #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

eval_equation and tests #74

wants to merge 1 commit into from

Conversation

Nic2020
Copy link
Member

@Nic2020 Nic2020 commented Oct 4, 2024

We add a function to evaluate the residuals of an equation: eval_equation().

@Nic2020 Nic2020 requested a review from bbejanov October 4, 2024 20:07
@codecov-commenter
Copy link

codecov-commenter commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.64%. Comparing base (b82db5b) to head (db3a1a5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #74      +/-   ##
==========================================
+ Coverage   95.56%   95.64%   +0.07%     
==========================================
  Files          14       14              
  Lines        2189     2203      +14     
==========================================
+ Hits         2092     2107      +15     
+ Misses         97       96       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +515 to +518
function eval_equation(model::AbstractModel, eqn::AbstractEquation, sim_data::AbstractMatrix{Float64}, rng::UnitRange{Int64} = 1:size(sim_data,1))
# Check bounds
@assert rng[begin] >= 1 && rng[end] <= size(sim_data, 1) "Error: The range specified is out of bounds. Ensure that the range starts from 1 or higher and ends within the size of the data."

Copy link
Member

Choose a reason for hiding this comment

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

Two comments about @assert

  • As a general rule I wouldn't use an assertion to check validity of input arguments. I use assertions to confirm that something I assume is actually true. I think throwing an ArgumentError is more appropriate when input arguments are not valid. A BoundsError would be okay here too, since this is a bounds check.
  • On the other hand, in this function we return NaN at indexes of res which depend on rows of sim_data that are out of bounds. So this function doesn't actually fail if rng is "not valid", it just fills those locations with NaNs. So why bother with a bounds check at all.

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.

3 participants