Skip to content

Fix seeding with undefined elements #743

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.)

@@ -279,4 +279,18 @@ end
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?

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

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.

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