Skip to content

Fix basic math calls when TMB defined#946

Merged
kellijohnson-NOAA merged 1 commit into
mainfrom
dev-fix-exp-TMBad
Aug 13, 2025
Merged

Fix basic math calls when TMB defined#946
kellijohnson-NOAA merged 1 commit into
mainfrom
dev-fix-exp-TMBad

Conversation

@Andrea-Havron-NOAA

@Andrea-Havron-NOAA Andrea-Havron-NOAA commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator

What is the feature?

  • With the change to TMBad, models are sometimes crashing when calling exp() and other basic math functions. This has to do with how exp() was referenceing the global namespace. This worked when CppAD was defined because CppAD has an exp() and other basic math functions in the global namespace while TMBad does not. This PR fixes the issue by involking an Argument-Dependent Lookup instead of relying on the global namespace.

How have you implemented the solution?

  • removed using ::exp; and replaced with using std::exp;
  • removed extra function defining std::double type

This solution now initially looks for the type in std. If it is not found, it will search in other libraries for specialized versions of the function with the specific type defined.

Does the PR impact any other area of the project, maybe another repo?

  • no

@github-actions

Copy link
Copy Markdown
Contributor

Instructions for code reviewer

Hello reviewer, thanks for taking the time to review this PR!

  • Please use this checklist during your review, checking off items that you have verified are complete, but feel free to skip over items that are not relevant!
  • See the GitHub documentation for how to comment on a PR to indicate where you have questions or changes are needed before approving the PR.
  • Please use conventions in the guidelines for conventional commit messages for both commit messages and comments.
  • PR reviews are a great way to learn so feel free to share your tips and tricks. However, when suggesting changes to the PR that are optional please include nit: (for nitpicking) as the comment type. For example, nit: I prefer using a data.frame() instead of a matrix because ...
  • Engage with the developer when they respond to comments and check off additional boxes as they become complete so the PR can be merged in when all the tasks are fulfilled. Make it clear when the PR is approved by selecting the approved status, and potentially by commenting on the PR with something like This PR is now ready to be merged, no additional changes are needed.

Checklist

  • The PR is requested to be merged into the appropriate branch (typically dev).
  • The code is well-designed.
  • The functionality is good for the users of the code.
  • Code coverage remains high, indicating the new code is tested.
  • The code is commented and the comments are clear, useful, and mostly explain why instead of what.
  • Code is appropriately documented (doxygen and roxygen).

@codecov

codecov Bot commented Jul 31, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.18%. Comparing base (f5f9fa4) to head (ea27ecb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #946      +/-   ##
==========================================
- Coverage   80.26%   75.18%   -5.09%     
==========================================
  Files          51       82      +31     
  Lines        1941     8414    +6473     
  Branches      461      461              
==========================================
+ Hits         1558     6326    +4768     
- Misses        262     1981    +1719     
+ Partials      121      107      -14     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Andrea-Havron-NOAA

Copy link
Copy Markdown
Collaborator Author

How I tracked this down: I ran into an R session crash when trying to run tests in the surplus production branch. I used gdb backtrace to isolate the line of code in fims_math that was throwing the error. I then used a Gemini query to come up with the solution that was implemented.

@kellijohnson-NOAA

Copy link
Copy Markdown
Contributor

Thanks @Andrea-Havron-NOAA for finding this and explaining your path for working on it. I am thinking though that this should go to main rather than dev if the model is crashing. @msupernaw what do you think about the changes, are they sustainable for other engines besides TMB?

@kellijohnson-NOAA

Copy link
Copy Markdown
Contributor

@msupernaw when you are back from 🏖️ can you please review this PR so we can get it out has a hot fix? Thank you.

@kellijohnson-NOAA kellijohnson-NOAA changed the base branch from dev to main August 6, 2025 19:09
@kellijohnson-NOAA kellijohnson-NOAA changed the base branch from main to dev August 6, 2025 19:10
@kellijohnson-NOAA kellijohnson-NOAA changed the base branch from dev to main August 6, 2025 19:16
@kellijohnson-NOAA

Copy link
Copy Markdown
Contributor

@Andrea-Havron-NOAA I force pushed because I reset the base branch to main and cherry-picked your commit.

@kellijohnson-NOAA kellijohnson-NOAA merged commit bb9558f into main Aug 13, 2025
16 checks passed
@kellijohnson-NOAA kellijohnson-NOAA deleted the dev-fix-exp-TMBad branch August 13, 2025 18:08
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