-
Notifications
You must be signed in to change notification settings - Fork 62
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
unthunk getindex
and iterate
on Composite
objects
#237
base: main
Are you sure you want to change the base?
Changes from all commits
a90cfdd
ed24d97
c10fc3a
a7caf9d
9f0a2dc
fb86f1a
c3ac790
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,8 @@ end | |
@test getproperty(Composite{Tuple{Float64,}}(2.0), 1) == 2.0 | ||
@test getproperty(Composite{Tuple{Float64,}}(@thunk 2.0^2), 1) == 4.0 | ||
@test getproperty(Composite{Tuple{Float64,}}(a=(@thunk 2.0^2),), :a) == 4.0 | ||
@test getindex(Composite{Tuple{Float64,}}(@thunk 2.0^2), 1) == 4.0 | ||
@test getindex(Composite{Tuple{Float64,}}(a=(@thunk 2.0^2),), 1) == 4.0 | ||
|
||
@test length(Composite{Foo}(x=2.5)) == 1 | ||
@test length(Composite{Tuple{Float64,}}(2.0)) == 1 | ||
|
@@ -65,6 +67,9 @@ end | |
# Testing iterate via collect | ||
@test collect(Composite{Foo}(x=2.5)) == [2.5] | ||
@test collect(Composite{Tuple{Float64,}}(2.0)) == [2.0] | ||
@test collect(Float64, Composite{Tuple{Float64,}}(@thunk 2.0^2)) == [4.0] | ||
@test collect(Float64, Composite{Tuple{Float64,}}(a=(@thunk 2.0^2),)) == [4.0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have tests for dictionary backed composites. THough I suspect iterating them will be weird, since they will iterate pairs and only the value, not the whole pair will need to be unthunked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agreed.
I rather think that having the implementation of WDYT, shall I try that in this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually get |
||
@test collect(Pair{String, Float64}, Composite{Dict}(Dict([("a", @thunk 2.0^2)]))) == [Pair("a", 4.0)] | ||
end | ||
|
||
@testset "unset properties" begin | ||
|
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.
Or I can replace the entire code block with:
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.
If I look at the benchmarks, the current code in the pull request gives me:
while the suggested code gives me:
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.
my instinct is the suggested code is better. I will take a look into why it is slower
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.
Poking at this, it looks like something funky is happening where it is deciding not to constant fold the state in the iterate.
I get on julia-master no allocations and instant on both.
but when timing:
[x for x in $r]
the getindex code has 1 allocation and the iterate backing code has 2 allocations.Weird.
But i guess this is fine
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.
Ok, I've used the
iterate
approach then.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.
I mean the getindex appraoch is fine