-
Notifications
You must be signed in to change notification settings - Fork 64
Handle Base.tail
& friends
#567
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
Changes from all commits
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 |
---|---|---|
|
@@ -72,12 +72,22 @@ end | |
end | ||
@test Tangent{Foo}(; x=2.5).x == 2.5 | ||
|
||
@test keys(Tangent{Tuple{Float64}}(2.0)) == Base.OneTo(1) | ||
tang1 = Tangent{Tuple{Float64}}(2.0) | ||
@test keys(tang1) == Base.OneTo(1) | ||
@test propertynames(Tangent{Tuple{Float64}}(2.0)) == (1,) | ||
@test getindex(Tangent{Tuple{Float64}}(2.0), 1) == 2.0 | ||
@test getindex(Tangent{Tuple{Float64}}(@thunk 2.0^2), 1) == 4.0 | ||
@test getproperty(Tangent{Tuple{Float64}}(2.0), 1) == 2.0 | ||
@test getproperty(Tangent{Tuple{Float64}}(@thunk 2.0^2), 1) == 4.0 | ||
@test NoTangent() === @inferred Base.tail(tang1) | ||
@test NoTangent() === @inferred Base.tail(Tangent{Tuple{}}()) | ||
|
||
tang3 = Tangent{Tuple{Float64, String, Vector{Float64}}}(1.0, NoTangent(), @thunk [3.0] .+ 4) | ||
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. Should we test this behaviour explicitly? julia> tang1 = Tangent{Tuple{Float64}}(1.0)
Tangent{Tuple{Float64}}(1.0,)
julia> Base.tail(tang1)
Tangent{Tuple{}}() 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. Maybe this should just return NoTangent()? 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. Maybe, would be consistent with julia> rand_tangent(())
NoTangent() |
||
@test @inferred(first(tang3)) === tang3[1] === 1.0 | ||
@test @inferred(last(tang3)) isa Thunk | ||
@test unthunk(last(tang3)) == [7.0] | ||
@test Tuple(@inferred Base.tail(tang3))[1] === NoTangent() | ||
@test Tuple(Base.tail(tang3))[end] isa Thunk | ||
|
||
NT = NamedTuple{(:a, :b),Tuple{Float64,Float64}} | ||
@test getindex(Tangent{NT}(; a=(@thunk 2.0^2)), :a) == 4.0 | ||
|
@@ -89,6 +99,14 @@ end | |
@test getproperty(Tangent{NT}(; a=(@thunk 2.0^2)), :b) == ZeroTangent() | ||
@test getproperty(Tangent{NT}(; b=(@thunk 2.0^2)), 1) == ZeroTangent() | ||
@test getproperty(Tangent{NT}(; b=(@thunk 2.0^2)), 2) == 4.0 | ||
|
||
@test first(Tangent{NT}(; a=(@thunk 2.0^2))) isa Thunk | ||
@test unthunk(first(Tangent{NT}(; a=(@thunk 2.0^2)))) == 4.0 | ||
@test last(Tangent{NT}(; a=(@thunk 2.0^2))) isa ZeroTangent | ||
|
||
ntang1 = @inferred Base.tail(Tangent{NT}(; b=(@thunk 2.0^2))) | ||
@test ntang1 isa Tangent{<:NamedTuple{(:b,)}} | ||
@test NoTangent() === @inferred Base.tail(ntang1) | ||
|
||
# TODO: uncomment this once https://github.com/JuliaLang/julia/issues/35516 | ||
if VERSION >= v"1.8-" | ||
|
Uh oh!
There was an error while loading. Please reload this page.