Skip to content

AD error due to interaction of missing gradient of besselk and struct with vector #1204

@st--

Description

@st--

Minimal reproducible example - note that Foo errors, whereas Bar works.

using Zygote
using SpecialFunctions: besselk
using Test

struct Foo{Tv<:Real}
    v::Vector{Tv}

    function Foo(v::Real)
        return new{typeof(v)}([v])
    end
end

struct Bar{Tv<:Real}
    v::Tv
end

function check_ad(k)
    return only(Zygote.gradient(x -> besselk(only(k.v), x), 2.1))
end

@test_throws MethodError check_ad(Foo(1.5))
@test check_ad(Bar(1.5)) isa Real

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions