-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
I don't quite understand what's going on here so it's a bit hard to title it. I found it in a test regression in OrdinaryDiffEq.jl SciML/OrdinaryDiffEq.jl#2093 which started giving the wrong error. Seems innocuous, but digging in made it weirder. The MWE I cam up with is:
# Setup
using FunctionWrappers, ForwardDiff, OrdinaryDiffEq
const a = Float64[1.0]
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
a[1] = t
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
u = [1.0; 0.0; 0.0]
du = copy(u)
t = 0.0
dualgen(::Type{T}) where {T} = ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, T}, T, 1}
T = Float64
T1 = Float64
dualT = dualgen(T)
# Version 1
R = Nothing
A = Tuple{Vector{dualgen(T)}, Vector{dualgen(T)}, SciMLBase.NullParameters, Float64}
ff = FunctionWrappers.FunctionWrapper{R, A}(SciMLBase.Void(lorenz!))
ff(du,u,SciMLBase.NullParameters(),t)Which gives:
julia> ff(du,u,SciMLBase.NullParameters(),t)
ERROR: TypeError: in cfunction, expected Union{}, got a value of type Nothing
Stacktrace:
[1] macro expansion
@ FunctionWrappers C:\Users\accou\.julia\packages\FunctionWrappers\Q5cBx\src\FunctionWrappers.jl:137 [inlined]
[2] do_ccall(f::FunctionWrappers.FunctionWrapper{…}, args::Tuple{…})
@ FunctionWrappers C:\Users\accou\.julia\packages\FunctionWrappers\Q5cBx\src\FunctionWrappers.jl:125
[3] (::FunctionWrappers.FunctionWrapper{Nothing, Tuple{…}})(::Vector{Float64}, ::Vararg{Any})
@ FunctionWrappers C:\Users\accou\.julia\packages\FunctionWrappers\Q5cBx\src\FunctionWrappers.jl:144
[4] top-level scope
@ REPL[27]:1
Some type information was truncated. Use `show(err)` to see complete types.
And you might go, that's not an MWE! Delete stuff. Well... deleting stuff and replacing it with the same thing... is fine. Here's the definition of Void: https://github.com/SciML/SciMLBase.jl/blob/v2.11.7/src/utils.jl#L477-L483 . Let's just remove a bit of package code by copy pasting that into the MWE:
struct Void{F}
f::F
end
function (f::Void)(args...)
f.f(args...)
nothing
end
ff = FunctionWrappers.FunctionWrapper{R, A}(Void(lorenz!))
ff(du,u,SciMLBase.NullParameters(),t)Tada! That works fine. What about getting rid of SciMLBase.NullParameters, that's just a singleton so what about nothing:
R = Nothing
A = Tuple{Vector{dualgen(T)}, Vector{dualgen(T)}, Nothing, Float64}
ff = FunctionWrappers.FunctionWrapper{R, A}(SciMLBase.Void(lorenz!))
ff(du,u,nothing,t)That works fine too!
So it seems this exact combination of arguments, and only using the version of things in the precompiled (?) package, causes the error. And I don't know what this error really is. It's a v1.10 only issue, so I'm posting here though it's also maybe FunctionWrappers.jl related?