|
224 | 224 | """
|
225 | 225 | $SIGNATURES
|
226 | 226 |
|
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), |
228 | 228 | """
|
229 | 229 | getVariablePPEDict(vari::VariableDataLevel1) = getPPEDict(vari)
|
230 | 230 |
|
@@ -361,34 +361,67 @@ addVariableSolverData!(dfg::AbstractDFG, sourceVariable::DFGVariable, solvekey::
|
361 | 361 | """
|
362 | 362 | $(SIGNATURES)
|
363 | 363 | Update variable solver data if it exists, otherwise add it.
|
| 364 | +
|
| 365 | +Notes: |
| 366 | +- `useCopy=true` to copy solver data and keep separate memory. |
| 367 | +- Use `fields` to updated only a few VND.fields while adhering to `useCopy`. |
| 368 | +
|
| 369 | +Related |
| 370 | +
|
| 371 | +mergeVariableSolverData! |
364 | 372 | """
|
365 |
| -function updateVariableSolverData!(dfg::AbstractDFG, variablekey::Symbol, vnd::VariableNodeData, solvekey::Symbol=:default)::VariableNodeData |
| 373 | +function updateVariableSolverData!(dfg::AbstractDFG, |
| 374 | + variablekey::Symbol, |
| 375 | + vnd::VariableNodeData, |
| 376 | + solvekey::Symbol=:default, |
| 377 | + useCopy::Bool=true, |
| 378 | + fields::Vector{Symbol}=Symbol[] )::VariableNodeData |
| 379 | + # |
366 | 380 | #This is basically just setSolverData
|
367 | 381 | var = getVariable(dfg, variablekey)
|
368 | 382 | if !haskey(var.solverDataDict, solvekey)
|
369 | 383 | @warn "VariableNodeData '$(solvekey)' does not exist, adding"
|
370 | 384 | end
|
371 |
| - #for InMemoryDFGTypes, cloud would update here |
372 |
| - var.solverDataDict[solvekey] = vnd |
373 |
| - return vnd |
374 |
| -end |
375 | 385 |
|
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) |
| 386 | + # for InMemoryDFGTypes do memory copy or repointing, for cloud this would be an different kind of update. |
| 387 | + usevnd = useCopy ? deepcopy(vnd) : vnd |
| 388 | + # should just one, or many pointers be updated? |
| 389 | + if haskey(var.solverDataDict, solvekey) && isa(var.solverDataDict[solvekey], VariableNodeData) && length(fields) != 0 |
| 390 | + # change multiple pointers inside the VND var.solverDataDict[solvekey] |
| 391 | + for field in fields |
| 392 | + destField = getfield(var.solverDataDict[solvekey], field) |
| 393 | + srcField = getfield(usevnd, field) |
| 394 | + if isa(destField, Array) && size(destField) == size(srcField) |
| 395 | + # use broadcast (in-place operation) |
| 396 | + destField .= srcField |
| 397 | + else |
| 398 | + # change pointer of destination VND object member |
| 399 | + setfield!(var.solverDataDict[solvekey], field, srcField) |
| 400 | + end |
| 401 | + end |
| 402 | + else |
| 403 | + # change a single pointer in var.solverDataDict |
| 404 | + var.solverDataDict[solvekey] = usevnd |
| 405 | + end |
383 | 406 |
|
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) |
| 407 | + return var.solverDataDict[solvekey] |
| 408 | +end |
| 409 | + |
| 410 | +updateVariableSolverData!(dfg::AbstractDFG, |
| 411 | + sourceVariable::DFGVariable, |
| 412 | + solvekey::Symbol=:default, |
| 413 | + useCopy::Bool=true, |
| 414 | + fields::Vector{Symbol}=Symbol[] ) = |
| 415 | + updateVariableSolverData!(dfg, sourceVariable.label, getSolverData(sourceVariable, solvekey), solvekey, useCopy, fields) |
| 416 | + |
| 417 | +function updateVariableSolverData!(dfg::AbstractDFG, |
| 418 | + sourceVariables::Vector{<:DFGVariable}, |
| 419 | + solvekey::Symbol=:default, |
| 420 | + useCopy::Bool=true, |
| 421 | + fields::Vector{Symbol}=Symbol[] ) |
389 | 422 | #I think cloud would do this in bulk for speed
|
390 | 423 | for var in sourceVariables
|
391 |
| - updateVariableSolverData!(dfg, var.label, getSolverData(var, solvekey), solvekey) |
| 424 | + updateVariableSolverData!(dfg, var.label, getSolverData(var, solvekey), solvekey, useCopy, fields) |
392 | 425 | end
|
393 | 426 | end
|
394 | 427 |
|
|
0 commit comments