Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRulesCore"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "0.9.31"
version = "0.9.32"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
6 changes: 6 additions & 0 deletions src/differentials/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ canonicalize(comp::Composite{<:Tuple, <:Tuple}) = comp
# Dict composite are always in their canonical form.
canonicalize(comp::Composite{<:Any, <:AbstractDict}) = comp

# Composites of unspecified primal types (indicated by specifying exactly `Any`)
# all combinations of type-params are specified here to avoid ambiguities
canonicalize(comp::Composite{Any, <:NamedTuple{L}}) where {L} = comp
canonicalize(comp::Composite{Any, <:Tuple}) where {L} = comp
canonicalize(comp::Composite{Any, <:AbstractDict}) where {L} = comp

"""
_zeroed_backing(P)

Expand Down
10 changes: 10 additions & 0 deletions test/differentials/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ end
@test canonicalize(CFoo(y=10)) == CFoo(x=Zero(), y=10)

@test_throws ArgumentError canonicalize(CFoo(q=99.0, x=2.5))

@testset "unspecified primal type" begin
c1 = Composite{Any}(;a=1, b=2)
c2 = Composite{Any}(1, 2)
c3 = Composite{Any}(Dict(4 => 3))

@test c1 == canonicalize(c1)
@test c2 == canonicalize(c2)
@test c3 == canonicalize(c3)
end
end

@testset "+ with other composites" begin
Expand Down