Skip to content

Forward mode gradient doesn't support tuples with varying element types #1994

@mhauru

Description

@mhauru

MWE:

julia> f(t) = t[1]*t[2]
f (generic function with 1 method)

julia> Enzyme.gradient(Enzyme.Forward, f, (1.0, Float32(2.0)))
ERROR: MethodError: no method matching onehot(::Tuple{Float64, Float32})

Closest candidates are:
  onehot(::Type{Tuple{Vararg{T, N}}}) where {T, N}
   @ Enzyme ~/projects/Enzyme.jl/src/Enzyme.jl:1557
  onehot(::Array)
   @ Enzyme ~/projects/Enzyme.jl/src/Enzyme.jl:1527
  onehot(::Array, ::Int64, ::Int64)
   @ Enzyme ~/projects/Enzyme.jl/src/Enzyme.jl:1531
  ...

Stacktrace:
 [1] macro expansion
   @ ~/projects/Enzyme.jl/src/Enzyme.jl:1833 [inlined]
 [2] create_shadows
   @ ~/projects/Enzyme.jl/src/Enzyme.jl:1811 [inlined]
 [3] gradient(::EnzymeCore.ForwardMode{false, EnzymeCore.FFIABI, false, false}, ::typeof(f), ::Tuple{Float64, Float32})
   @ Enzyme ~/projects/Enzyme.jl/src/Enzyme.jl:1970
 [4] top-level scope
   @ REPL[97]:1

Looking at the definition of onehot(::Type{NTuple{N,T}}), it doesn't seem to use the parameter T anywhere. Could it just be dropped?

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