Skip to content

Commit

Permalink
update for set-or-update
Browse files Browse the repository at this point in the history
  • Loading branch information
jrising committed Apr 23, 2021
1 parent bc53e78 commit 1daf475
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/OptiMimi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ function setparameters(model::Model, components::Vector{Symbol}, names::Vector{S
startindex = 1
for (ii, len, isscalar) in Channel((chnl) -> nameindexes(model, components, names, chnl))
if isscalar
set_param!(model, components[ii], names[ii], xx[startindex])
set_or_update_param!(model, components[ii], names[ii], xx[startindex])
else
shape = getdims(model, components[ii], names[ii])
reshaped = reshape(collect(model.md.number_type, xx[startindex:(startindex+len - 1)]), tuple(shape...))
set_param!(model, components[ii], names[ii], reshaped)
set_or_update_param!(model, components[ii], names[ii], reshaped)
end
startindex += len
end
Expand Down
12 changes: 12 additions & 0 deletions src/metamimi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ function getdimnames(model::Model, component::Symbol, name::Symbol)
variable_dimensions(model, component, name)
end
end

"""
Avoid the distinction between set_param! and update_param!
"""
function set_or_update_param!(model::Model, component::Symbol, name::Symbol, value)
try
update_param!(model, name, value)
catch
set_param!(model, component, name, value)
end
end

0 comments on commit 1daf475

Please sign in to comment.