Method dispatch on function types with constructor

I am using Zygote to autodiff some code and Zygote needs me to define an adjoint for some constructor. Following the docs, I went on to define an rrule with ChainRules but now I am stuck because it does not work. The problem is that rrule dispatches on function types like this

function rrule(::typeof(sin), x)
    # ...
end

The following does not work though

struct A
    a
end

function rrule(::typeof(A), a)
    # ...
end

because typeof(A) == DataType and not typeof(A) as it is for functions. Is there some syntax that lets me express to Julia that I am talking about the constructor/function A and not the struct A?

I think you’re looking for Type{A}, a type whose only instance is A (Types · The Julia Language).

3 Likes

That works, thanks a lot!