-
Notifications
You must be signed in to change notification settings - Fork 32
Safely initialize the inplace Jacobian cache #160
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
base: master
Are you sure you want to change the base?
Conversation
Do you have an MWE with the error you are encountering? I have a strong feeling that the bug is located downstream, because using similar here is not incorrect |
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.
Okay, on second thought this looks like a correct patch, maybe we should add a test that used to fail? Or at least a comment pointing to the rationale?
@@ -78,7 +78,7 @@ function OnceDifferentiable(f, x_seed::AbstractArray, F::AbstractArray, DF::Abst | |||
fdfF = make_fdf(f, x_seed, F) | |||
return OnceDifferentiable(fF, dfF, fdfF, x_seed, F, DF) | |||
else | |||
F2 = similar(F) | |||
F2 = copy(F) |
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.
Is F2
mutated in the jacobian!
call below? Would it still work if F2
can't be mutated anymore? similar
is guaranteed to create a mutable array whereas copy
may return a static array.
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.
F2 = copy(F) | |
F2 = copyto!(similar(F), F) |
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.
Fixed in facf227. I attempted to add a test but couldn't figure out how to make it fail outside of LsqFit so I added a comment instead.
This fixes support for BigFloat in LsqFit.jl, ForwardDiff.jl requires that the array is initialized.
Thanks. This PR needs a test for the correct behavior. |
This workaround might not be necessary: JuliaDiff/ForwardDiff.jl#743 |
Would definitely be nice if we didn't have to rely on fixes here |
This fixes support for BigFloat in LsqFit.jl. Making a copy instead of similar ensures that the elements aren't
undef
, which is what previous versions did.CC @gdalle