Skip to content

Commit 7f240e4

Browse files
authored
implement mergeStates! (#1145)
1 parent 195cb2d commit 7f240e4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/services/DFGVariable.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,20 @@ function mergeState!(v::VariableCompute, vnd::State)
733733
return 1
734734
end
735735

736+
function mergeStates!(dfg::AbstractDFG, varLabel_state_pairs::Vector{Pair{Symbol, State}})
737+
cnt = asyncmap(varLabel_state_pairs) do (varLabel, state)
738+
return mergeState!(dfg, varLabel, state)
739+
end
740+
return sum(cnt)
741+
end
742+
743+
function mergeStates!(dfg::AbstractDFG, variableLabel::Symbol, states::Vector{<:State})
744+
cnt = asyncmap(states) do state
745+
return mergeState!(dfg, variableLabel, state)
746+
end
747+
return sum(cnt)
748+
end
749+
736750
function copytoState!(
737751
dfg::AbstractDFG,
738752
variableLabel::Symbol,

test/testBlocks.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,9 @@ function VSDTestBlock!(fg, v1)
787787
# Bulk copy update x0
788788
@test DFG.copytoState!(fg, v1.label, :default, getState(fg, v1.label, :default)) == 1
789789

790+
@test DFG.mergeStates!(fg, Vector{Pair{Symbol, State}}([:a=>vnd])) == 1
791+
@test DFG.mergeStates!(fg, [:a=>vnd]) == 1
792+
@test DFG.mergeStates!(fg, :a, [vnd]) == 1
790793
altVnd = vnd |> deepcopy
791794
keepVnd = getState(getVariable(fg, :a), :parametric) |> deepcopy
792795

0 commit comments

Comments
 (0)