-
-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution interpolation does not infer type #2610
Comments
That's not intentional. |
With using Cthulhu
@descend sol(ts) I have digged down to this as a possible source (screenshot for colors), where it doesn't seem infer the vector element type? This also looks suspiciously similar to #1270. |
Yeah isolate that do function: why is the element type not inferable there? It seems like it should be fine... |
Separated the |
Alright... I'll leave that to @oscardssmith to figure out then 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 |
Did you try the |
What do you mean? |
I can at least confirm the ...
vals = [dofunc(tvals[1], ts, tdir, timeseries, cache, idxs, deriv, ks, id, p, differential_vars, i₋₊ref, f)]
for t in tvals[2:end]
push!(vals, dofunc(t, ts, tdir, timeseries, cache, idxs, deriv, ks, id, p, differential_vars, i₋₊ref, f))
end
vals = vals[idx]
... But I don't think this is an optimal solution. |
That it does not infer anymore in the |
Hmm ok, thanks. That's a rabbit hole I didn't know about 😅 I'm not sure I got it right, but I tried this ugly thing, which does not help: function ode_interpolation(tvals, id::I, idxs, deriv::D, p,
continuity::Symbol = :left) where {I, D}
@unpack ts, timeseries, ks, f, cache, differential_vars = id
@inbounds tdir = sign(ts[end] - ts[1])
idx = sortperm(tvals, rev = tdir < 0)
# start the search thinking it's ts[1]-ts[2]
i₋₊ref = Ref((1, 2))
vals = map(idx) do j
let j=j, tvals=tvals, tdir=tdir, i₋₊ref=i₋₊ref, ts=ts, timeseries=timeseries, ks=ks, f=f, cache=cache, differential_vars=differential_vars, continuity=continuity, id=id, idxs=idxs, deriv=deriv, p=p
dofunc(j, tvals, tdir, i₋₊ref, ts, timeseries, ks, f, cache, differential_vars, continuity, id, idxs, deriv, p) # moved everything in the "do" into this function
end
end
invpermute!(vals, idx)
DiffEqArray(vals, tvals)
end
|
You'd have to swap the |
Oh, of course, now I get it: function ode_interpolation(tvals, id::I, idxs, deriv::D, p,
continuity::Symbol = :left) where {I, D}
@unpack ts, timeseries, ks, f, cache, differential_vars = id
@inbounds tdir = sign(ts[end] - ts[1])
idx = sortperm(tvals, rev = tdir < 0)
# start the search thinking it's ts[1]-ts[2]
i₋₊ref = Ref((1, 2))
vals = nothing # must be declared outside "let"; should at least make types infer to Union{Nothing, ...}?
let tvals=tvals, tdir=tdir, i₋₊ref=i₋₊ref, ts=ts, timeseries=timeseries, ks=ks, f=f, cache=cache, differential_vars=differential_vars, continuity=continuity, id=id, idxs=idxs, deriv=deriv, p=p
vals = map(idx) do j
dofunc(j, tvals, tdir, i₋₊ref, ts, timeseries, ks, f, cache, differential_vars, continuity, id, idxs, deriv, p) # moved everything in the "do" into this function
end
end
invpermute!(vals, idx)
DiffEqArray(vals, tvals)
end Still doesn't help, unfortunately :( But thank you for the suggestion! |
One additional comment: You don't need the vals = let ...
map(..) do ..
...
end
end Another comment: In my experience, tuples sometimes lead to better type inference in broadcasting etc than |
Thanks, appreciate the tips. It also runs, but doesn't help the issue. |
The simple example
infers the output only as
Any
:This is what a flamegraph looks like:
Is this to be expected?
The text was updated successfully, but these errors were encountered: