Skip to content

Conversation

JamesWrigley
Copy link

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

@gdalle
Copy link
Contributor

gdalle commented Apr 6, 2025

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

Copy link
Contributor

@gdalle gdalle left a 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)
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
F2 = copy(F)
F2 = copyto!(similar(F), F)

Copy link
Author

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.
@pkofod
Copy link
Member

pkofod commented Apr 7, 2025

Thanks. This PR needs a test for the correct behavior.

@devmotion
Copy link
Contributor

This workaround might not be necessary: JuliaDiff/ForwardDiff.jl#743

@pkofod
Copy link
Member

pkofod commented Apr 9, 2025

Would definitely be nice if we didn't have to rely on fixes here

@pkofod
Copy link
Member

pkofod commented Aug 24, 2025

If ForwardDiff doesn't merge the PR I think we need some kind of fix ourselves here

@devmotion
Copy link
Contributor

devmotion commented Aug 25, 2025

Kristoffer is fine with the ForwardDiff PR and I just increased the test coverage, so I'll merge and release once codecov confirms that all changes are covered.

@devmotion
Copy link
Contributor

devmotion commented Aug 25, 2025

The BigFloat fix is released in ForwardDiff 1.0.2: JuliaRegistries/General#137312

Edit: Since the Julia compat bound was updated to 1.10, it had to be released as version 1.1.0. The new release is now available in the registry (but may take a few minutes until it is available in all package servers).

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.

4 participants