|
17 | 17 | @deprecate updateVariable!(args...) mergeVariable!(args...) |
18 | 18 | @deprecate updateFactor!(args...) mergeFactor!(args...) |
19 | 19 |
|
| 20 | +@deprecate updateBlobEntry!(args...) mergeBlobentry!(args...) |
| 21 | +@deprecate updateGraphBlobEntry!(args...) mergeGraphBlobentry!(args...) |
| 22 | +@deprecate updateAgentBlobEntry!(args...) mergeAgentBlobentry!(args...) |
| 23 | + |
| 24 | +export updateVariableSolverData! |
| 25 | + |
| 26 | +#TODO possibly completely deprecated or not exported until update verb is standardized |
| 27 | +function updateVariableSolverData!( |
| 28 | + dfg::AbstractDFG, |
| 29 | + variablekey::Symbol, |
| 30 | + vnd::VariableNodeData, |
| 31 | + useCopy::Bool = false, |
| 32 | + fields::Vector{Symbol} = Symbol[]; |
| 33 | + warn_if_absent::Bool = true, |
| 34 | +) |
| 35 | + #This is basically just setSolverData |
| 36 | + var = getVariable(dfg, variablekey) |
| 37 | + warn_if_absent && |
| 38 | + !haskey(var.solverDataDict, vnd.solveKey) && |
| 39 | + @warn "VariableNodeData '$(vnd.solveKey)' does not exist, adding" |
| 40 | + |
| 41 | + # for InMemoryDFGTypes do memory copy or repointing, for cloud this would be an different kind of update. |
| 42 | + usevnd = vnd # useCopy ? deepcopy(vnd) : vnd |
| 43 | + # should just one, or many pointers be updated? |
| 44 | + useExisting = |
| 45 | + haskey(var.solverDataDict, vnd.solveKey) && |
| 46 | + isa(var.solverDataDict[vnd.solveKey], VariableNodeData) && |
| 47 | + length(fields) != 0 |
| 48 | + # @error useExisting vnd.solveKey |
| 49 | + if useExisting |
| 50 | + # change multiple pointers inside the VND var.solverDataDict[solvekey] |
| 51 | + for field in fields |
| 52 | + destField = getfield(var.solverDataDict[vnd.solveKey], field) |
| 53 | + srcField = getfield(usevnd, field) |
| 54 | + if isa(destField, Array) && size(destField) == size(srcField) |
| 55 | + # use broadcast (in-place operation) |
| 56 | + destField .= srcField |
| 57 | + else |
| 58 | + # change pointer of destination VND object member |
| 59 | + setfield!(var.solverDataDict[vnd.solveKey], field, srcField) |
| 60 | + end |
| 61 | + end |
| 62 | + else |
| 63 | + # change a single pointer in var.solverDataDict |
| 64 | + var.solverDataDict[vnd.solveKey] = usevnd |
| 65 | + end |
| 66 | + |
| 67 | + return var.solverDataDict[vnd.solveKey] |
| 68 | +end |
| 69 | + |
| 70 | +function updateVariableSolverData!( |
| 71 | + dfg::AbstractDFG, |
| 72 | + variablekey::Symbol, |
| 73 | + vnd::VariableNodeData, |
| 74 | + solveKey::Symbol, |
| 75 | + useCopy::Bool = false, |
| 76 | + fields::Vector{Symbol} = Symbol[]; |
| 77 | + warn_if_absent::Bool = true, |
| 78 | +) |
| 79 | + # TODO not very clean |
| 80 | + if vnd.solveKey != solveKey |
| 81 | + @warn( |
| 82 | + "updateVariableSolverData with solveKey parameter might change in the future, see DFG #565. Future warnings are suppressed", |
| 83 | + maxlog = 1 |
| 84 | + ) |
| 85 | + usevnd = useCopy ? deepcopy(vnd) : vnd |
| 86 | + usevnd.solveKey = solveKey |
| 87 | + return updateVariableSolverData!( |
| 88 | + dfg, |
| 89 | + variablekey, |
| 90 | + usevnd, |
| 91 | + useCopy, |
| 92 | + fields; |
| 93 | + warn_if_absent = warn_if_absent, |
| 94 | + ) |
| 95 | + else |
| 96 | + return updateVariableSolverData!( |
| 97 | + dfg, |
| 98 | + variablekey, |
| 99 | + vnd, |
| 100 | + useCopy, |
| 101 | + fields; |
| 102 | + warn_if_absent = warn_if_absent, |
| 103 | + ) |
| 104 | + end |
| 105 | +end |
| 106 | + |
| 107 | +function updateVariableSolverData!( |
| 108 | + dfg::AbstractDFG, |
| 109 | + sourceVariable::VariableCompute, |
| 110 | + solveKey::Symbol = :default, |
| 111 | + useCopy::Bool = false, |
| 112 | + fields::Vector{Symbol} = Symbol[]; |
| 113 | + warn_if_absent::Bool = true, |
| 114 | +) |
| 115 | + # |
| 116 | + vnd = getSolverData(sourceVariable, solveKey) |
| 117 | + # toshow = listSolveKeys(sourceVariable) |> collect |
| 118 | + # @info "update DFGVar solveKey" solveKey vnd.solveKey |
| 119 | + # @show toshow |
| 120 | + @assert solveKey == vnd.solveKey "VariableNodeData's solveKey=:$(vnd.solveKey) does not match requested :$solveKey" |
| 121 | + return updateVariableSolverData!( |
| 122 | + dfg, |
| 123 | + sourceVariable.label, |
| 124 | + vnd, |
| 125 | + useCopy, |
| 126 | + fields; |
| 127 | + warn_if_absent = warn_if_absent, |
| 128 | + ) |
| 129 | +end |
| 130 | + |
| 131 | +function updateVariableSolverData!( |
| 132 | + dfg::AbstractDFG, |
| 133 | + sourceVariables::Vector{<:VariableCompute}, |
| 134 | + solveKey::Symbol = :default, |
| 135 | + useCopy::Bool = false, |
| 136 | + fields::Vector{Symbol} = Symbol[]; |
| 137 | + warn_if_absent::Bool = true, |
| 138 | +) |
| 139 | + #I think cloud would do this in bulk for speed |
| 140 | + for var in sourceVariables |
| 141 | + updateVariableSolverData!( |
| 142 | + dfg, |
| 143 | + var.label, |
| 144 | + getSolverData(var, solveKey), |
| 145 | + useCopy, |
| 146 | + fields; |
| 147 | + warn_if_absent = warn_if_absent, |
| 148 | + ) |
| 149 | + end |
| 150 | +end |
| 151 | + |
20 | 152 | ## ================================================================================ |
21 | 153 | ## Deprecated in v0.25 |
22 | 154 | ##================================================================================= |
|
0 commit comments