Skip to content

Commit

Permalink
Merge pull request #2963 from AayushSabharwal/as/varmap-promote
Browse files Browse the repository at this point in the history
fix: promote buffer in `_varmap_to_vars`
  • Loading branch information
ChrisRackauckas authored Aug 13, 2024
2 parents ca85342 + 43e072f commit 6cc9816
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,19 @@ function _varmap_to_vars(varmap::Dict, varlist; defaults = Dict(), check = false
defaults = canonicalize_varmap(defaults; toterm)
varmap = merge(defaults, varmap)
values = Dict()

T = Union{}
for var in varlist
var = unwrap(var)
val = unwrap(fixpoint_sub(var, varmap; operator = Symbolics.Operator))
if !isequal(val, var)
values[var] = val
T = promote_type(T, typeof(val))
end
end
missingvars = setdiff(varlist, collect(keys(values)))
check && (isempty(missingvars) || throw(MissingVariablesError(missingvars)))
return [values[unwrap(var)] for var in varlist]
return [T(values[unwrap(var)]) for var in varlist]
end

function varmap_with_toterm(varmap; toterm = Symbolics.diff2term)
Expand Down
4 changes: 2 additions & 2 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1170,14 +1170,14 @@ end
@test getname(unknowns(sys, x)) == :sys₊x
@test size(unknowns(sys, x)) == size(x)

# Issue#2667
# Issue#2667 and Issue#2953
@testset "ForwardDiff through ODEProblem constructor" begin
@parameters P
@variables x(t)
sys = structural_simplify(ODESystem([D(x) ~ P], t, [x], [P]; name = :sys))

function x_at_1(P)
prob = ODEProblem(sys, [x => 0.0], (0.0, 1.0), [sys.P => P])
prob = ODEProblem(sys, [x => P], (0.0, 1.0), [sys.P => P])
return solve(prob, Tsit5())(1.0)
end

Expand Down

0 comments on commit 6cc9816

Please sign in to comment.