Skip to content

canonicalize Composite{Any} #321

@mzgubic

Description

@mzgubic

What do we think about the following:

julia> c = Composite{Any}(;a=1, b=2);

julia> canonicalize(c)
ERROR: ArgumentError: type does not have a definite number of fields
Stacktrace:
 [1] fieldcount(::Any) at ./reflection.jl:725
 [2] #s15#27 at /Users/mzgubic/JuliaEnvs/test/alex/dev/ChainRulesCore/src/differentials/composite.jl:189 [inlined]
 [3] #s15#27(::Any, ::Any, ::Any) at ./none:0
 [4] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:543
 [5] canonicalize(::Composite{Any,NamedTuple{(:a, :b),Tuple{Int64,Int64}}}) at /Users/mzgubic/JuliaEnvs/test/alex/dev/ChainRulesCore/src/differentials/composite.jl:166
 [6] top-level scope at REPL[5]:1

I suppose this should never really happen (but it does in higher order AD in Zygote).

Would it make sense to define something like

canonicalize(c::Composite{Any}) = c

since in that case we don't know what the fields are, or do we prefer the error to be thrown?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Structural TangentRelated to the `Tangent` type for structured (composite) values

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions