Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/batched_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function setsym_oop(bi::BatchedInterface)
push!(curexpr.args, :($paramssym = $parameter_values($prob)))
else
param_idxssym = Symbol(:param_idxs_, sys_i)
param_idxs = indp_idxs[.!isstate]
param_idxs = (indp_idxs[.!isstate]...,)
param_valssym = Symbol(:param_vals, sys_i)
vals_idxs = union_idxs[.!isstate]
push!(curexpr.args, :($param_idxssym = $param_idxs))
Expand Down
4 changes: 4 additions & 0 deletions src/state_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ for (t1, t2) in [
throw(NotVariableOrParameter("setsym_oop", s))
end
end
if sym isa Tuple
vars = Tuple(vars)
pars = Tuple(pars)
end
indp = _root_indp(indp)
return FullSetter(isempty(vars) ? nothing : OOPSetter(indp, identity.(vars), true),
isempty(pars) ? nothing : OOPSetter(indp, identity.(pars), false),
Expand Down
31 changes: 19 additions & 12 deletions src/value_provider_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,27 +231,34 @@ function (fn::Fix1Multiple)(args...)
fn.f(fn.arg, args...)
end

struct OOPSetter{I, D}
struct OOPSetter{S, I, D}
indp::I
idxs::D
is_state::Bool
end

function (os::OOPSetter)(valp, val)
buffer = if os.is_state
hasmethod(state_values, Tuple{typeof(valp)}) ? state_values(valp) : valp
else
hasmethod(parameter_values, Tuple{typeof(valp)}) ? parameter_values(valp) : valp
end
OOPSetter(indp, idxs, isstate) = OOPSetter{isstate, typeof(indp), typeof(idxs)}(indp, idxs)

function (os::OOPSetter{true})(valp, val)
buffer = hasmethod(state_values, Tuple{typeof(valp)}) ? state_values(valp) : valp
return remake_buffer(os.indp, buffer, (os.idxs,), (val,))
end

function (os::OOPSetter{false})(valp, val)
buffer = hasmethod(parameter_values, Tuple{typeof(valp)}) ? parameter_values(valp) : valp
return remake_buffer(os.indp, buffer, (os.idxs,), (val,))
end

function (os::OOPSetter)(valp, val::Union{Tuple, AbstractArray})
buffer = if os.is_state
hasmethod(state_values, Tuple{typeof(valp)}) ? state_values(valp) : valp
function (os::OOPSetter{true})(valp, val::Union{Tuple, AbstractArray})
buffer = hasmethod(state_values, Tuple{typeof(valp)}) ? state_values(valp) : valp
if os.idxs isa Union{Tuple, AbstractArray}
return remake_buffer(os.indp, buffer, os.idxs, val)
else
hasmethod(parameter_values, Tuple{typeof(valp)}) ? parameter_values(valp) : valp
return remake_buffer(os.indp, buffer, (os.idxs,), (val,))
end
end

function (os::OOPSetter{false})(valp, val::Union{Tuple, AbstractArray})
buffer = hasmethod(parameter_values, Tuple{typeof(valp)}) ? parameter_values(valp) : valp
if os.idxs isa Union{Tuple, AbstractArray}
return remake_buffer(os.indp, buffer, os.idxs, val)
else
Expand Down
Loading