SciML / DiffEqBase.jl

The lightweight Base library for shared types and functionality for defining differential equation and scientific machine learning (SciML) problems
Other
302 stars 106 forks source link

ReverseDiff Extension makes vector parameter into a scalar #1013

Closed avik-pal closed 4 months ago

avik-pal commented 4 months ago

If I provide a parameter p = [4.0], I would expect it to stay as a Vector. Currently it gets converted into a TrackedReal.

julia> reduce(vcat, ReverseDiff.track([4.0]))
TrackedReal<Cz3>(4.0, 0.0, 5TV, 1, 3KQ)

Maybe we should add a special case for length(p) == 1 and not do reduce(vcat, p)

ChrisRackauckas commented 4 months ago
julia> using ReverseDiff

julia> typeof(reduce(vcat, ReverseDiff.track([4.0])))
ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}}}

julia> typeof(reduce(vcat, ReverseDiff.track([4.0,4.0])))
ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}}

I'd surface that as a bug in ReverseDiff.

avik-pal commented 4 months ago
julia> reduce(vcat, [4.0])
4.0

That holds even for regular arrays