Skip to content

Conversation

@devmotion
Copy link
Member

Fixes #436. Fixes #740.

@gdalle
Copy link
Member

gdalle commented Apr 7, 2025

I didn't know about isassigned, this seems appropriate. Could this cause a slowdown in the vast majority of cases where similar actually assigns stuff?

@devmotion
Copy link
Member Author

Could this cause a slowdown in the vast majority of cases where similar actually assigns stuff?

I put it behind an isbitstype check, so it should never be hit for bit types (such as Float64, Float32, Duals of Float64, Complex of FloatXY, etc.)

end
end

@testset "BigFloat" begin
Copy link
Member

Choose a reason for hiding this comment

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

Does this test cover all the new branches? It seems CodeCov is sleeping at the wheel.
I think we may also want to add cases where only some of the values are uninitialized?

Copy link
Member Author

@devmotion devmotion Aug 25, 2025

Choose a reason for hiding this comment

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

Codecov results are available on the codecov webpage: https://app.codecov.io/github/JuliaDiff/ForwardDiff.jl/commit/6f8f6a977d4d69fda7c492f6e0a47cb8a6853045 (I assume the codecov app is not installed in the repo and hence there's no nice summary in the PR - AFAICT I don't have sufficient permissions to install it)

Indeed, you were right, the tests did not cover all new branches. I extended the tests, and locally it seems that they cover all branches as commenting out any of the branches leads to test failures.

Copy link
Member Author

Choose a reason for hiding this comment

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

if isassigned(x, idx)
duals[idx] = Dual{T,V,N}(x[idx], seed)
else
Base._unsetindex!(duals, idx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

:/, this is quite unfortunate, is this really the only way to fix this?

Copy link
Member

Choose a reason for hiding this comment

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

I think the idea is that if x[idx] is #undef, we want duals[idx] to be the same

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wasn't 100% percent happy but it was the best I could think of and what apparently is used in base. IMO we really want to ensure here that we get the same behaviour as copyto! on the primal part, to avoid that yduals contains any surprising values, possibly from previous chunks or differentations.

Copy link
Member Author

Choose a reason for hiding this comment

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

julia> x = BigFloat[1, 2];

julia> y = similar(x); y[2] = 1;

julia> x
2-element Vector{BigFloat}:
 1.0
 2.0

julia> y
2-element Vector{BigFloat}:
 #undef
   1.0

julia> copyto!(x, y);

julia> x
2-element Vector{BigFloat}:
 #undef
   1.0

@gdalle
Copy link
Member

gdalle commented May 3, 2025

What's the word on this one? Do we want it?

@pkofod
Copy link

pkofod commented Jun 8, 2025

gentle bump from me as well

@pkofod
Copy link

pkofod commented Aug 24, 2025

Bump again

@devmotion devmotion requested a review from KristofferC August 25, 2025 08:06
@KristofferC
Copy link
Collaborator

I guess let's go with _unsetindex! for now then. 👍

@KristofferC
Copy link
Collaborator

I opened JuliaLang/julia#59394 regarding unsetindex!.

@devmotion devmotion merged commit e670596 into master Aug 25, 2025
10 of 11 checks passed
@devmotion devmotion deleted the dw/seed_non_bitstypes branch September 12, 2025 14:26
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.

Why is seeding ydual necessary? Jacobian of in-place functions in presence of undefined references

5 participants