Skip to content

Commit 6f18313

Browse files
committed
updateSolveData! useDeepcopy standard
1 parent 7d55fde commit 6f18313

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/services/DFGVariable.jl

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ end
224224
"""
225225
$SIGNATURES
226226
227-
Return full dictionary of PPEs in a variable, recommended to rather use CRUD: [`getPPE`](@ref),
227+
Return full dictionary of PPEs in a variable, recommended to rather use CRUD: [`getPPE`](@ref),
228228
"""
229229
getVariablePPEDict(vari::VariableDataLevel1) = getPPEDict(vari)
230230

@@ -361,34 +361,37 @@ addVariableSolverData!(dfg::AbstractDFG, sourceVariable::DFGVariable, solvekey::
361361
"""
362362
$(SIGNATURES)
363363
Update variable solver data if it exists, otherwise add it.
364-
"""
365-
function updateVariableSolverData!(dfg::AbstractDFG, variablekey::Symbol, vnd::VariableNodeData, solvekey::Symbol=:default)::VariableNodeData
364+
Notes:
365+
- `useDeepcopy=true` to copy solver data and keep separate memory.
366+
"""
367+
function updateVariableSolverData!(dfg::AbstractDFG,
368+
variablekey::Symbol,
369+
vnd::VariableNodeData,
370+
solvekey::Symbol=:default,
371+
useDeepcopy::Bool=true )::VariableNodeData
372+
#
366373
#This is basically just setSolverData
367374
var = getVariable(dfg, variablekey)
368375
if !haskey(var.solverDataDict, solvekey)
369376
@warn "VariableNodeData '$(solvekey)' does not exist, adding"
370377
end
371378
#for InMemoryDFGTypes, cloud would update here
372-
var.solverDataDict[solvekey] = vnd
379+
var.solverDataDict[solvekey] = useDeepcopy ? deepcopy(vnd) : vnd
373380
return vnd
374381
end
375382

376-
"""
377-
$(SIGNATURES)
378-
Update variable solver data if it exists, otherwise add it.
379-
NOTE: Copies the solver data.
380-
"""
381-
updateVariableSolverData!(dfg::AbstractDFG, sourceVariable::DFGVariable, solvekey::Symbol=:default) =
382-
updateVariableSolverData!(dfg, sourceVariable.label, deepcopy(getSolverData(sourceVariable, solvekey)), solvekey)
383+
updateVariableSolverData!(dfg::AbstractDFG,
384+
sourceVariable::DFGVariable,
385+
solvekey::Symbol=:default, useDeepcopy::Bool=true) =
386+
updateVariableSolverData!(dfg, sourceVariable.label, getSolverData(sourceVariable, solvekey), solvekey, useDeepcopy)
383387

384-
"""
385-
$(SIGNATURES)
386-
Update variable solver data if it exists, otherwise add it.
387-
"""
388-
function updateVariableSolverData!(dfg::AbstractDFG, sourceVariables::Vector{<:DFGVariable}, solvekey::Symbol=:default)
388+
function updateVariableSolverData!(dfg::AbstractDFG,
389+
sourceVariables::Vector{<:DFGVariable},
390+
solvekey::Symbol=:default,
391+
useDeepcopy::Bool=true )
389392
#I think cloud would do this in bulk for speed
390393
for var in sourceVariables
391-
updateVariableSolverData!(dfg, var.label, getSolverData(var, solvekey), solvekey)
394+
updateVariableSolverData!(dfg, var.label, getSolverData(var, solvekey), solvekey, useDeepcopy)
392395
end
393396
end
394397

0 commit comments

Comments
 (0)