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

debug: revert allocation-free linearize! to avoid NonLinModel type-instability #160

Merged
merged 1 commit into from
Feb 16, 2025

Conversation

franckgaga
Copy link
Member

This reverts commit 25865ea. (so linearize! is no longer allocation-free)

MOTIVE

The intricate solution with a struct and 5 separate closures creates a weird type-instability on NonLinModel when its f and h functions are not in the global scope. I'm not sure I fully understand why.

In the end I prefer some small but deterministic allocations in ForwardDiff.jacobian! than a type-instability. I also benchmarked the two implementations, and the small allocations are way more performant than the type-instable version.

This reverts commit 25865ea.
(so `linearize!` is no longer allocation-free)

*MOTIVE*

The intricate solution with a `struct` and 5 separate closures creates a weird type-instability on `NonLinModel` when its `f` and `h` functions are not in the global scope. I'm not sure I fully understand why.

In the end I prefer some small but deterministic allocations in `ForwardDiff.jacobian!` than a type-instability. I also benchmarked the two implementations, and the small allocations are way more performant than the type-instable version.
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 72.72727% with 6 lines in your changes missing coverage. Please review.

Project coverage is 98.57%. Comparing base (0ca6f85) to head (b022769).

Files with missing lines Patch % Lines
src/sim_model.jl 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #160      +/-   ##
==========================================
- Coverage   98.89%   98.57%   -0.33%     
==========================================
  Files          24       24              
  Lines        3802     3787      -15     
==========================================
- Hits         3760     3733      -27     
- Misses         42       54      +12     

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

@franckgaga franckgaga merged commit 2b1abf0 into main Feb 16, 2025
4 checks passed
@franckgaga franckgaga deleted the type_stability_nonlinmodel branch February 16, 2025 00:56
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