Skip to content

Commit 48f4fa1

Browse files
committed
solverData -> getSolverData and test if deprecated and sort
1 parent 1197c7c commit 48f4fa1

File tree

12 files changed

+68
-54
lines changed

12 files changed

+68
-54
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function getFactor(dfg::CloudGraphsDFG, factorId::Int64)::DFGFactor
163163
factor = dfg.rebuildFactorMetadata!(dfg, factor)
164164
# GUARANTEED never to bite us in the future...
165165
# ... TODO: refactor if changed: https://github.com/JuliaRobotics/IncrementalInference.jl/issues/350
166-
solverData(factor).fncargvID = factor._variableOrderSymbols
166+
getSolverData(factor).fncargvID = factor._variableOrderSymbols
167167

168168
# Add to cache
169169
push!(dfg.factorCache, factor.label=>factor)

src/Common.jl

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ Related
114114
ls, lsf
115115
"""
116116
sortDFG(vars::Vector{Symbol})::Vector{Symbol} = sortVarNested(vars)
117-
118117
"""
119118
$SIGNATURES
120119
@@ -137,7 +136,7 @@ function getfnctype(data::GenericFunctionNodeData)
137136
return data.fnc.usrfnc!
138137
end
139138
function getfnctype(fact::DFGFactor; solveKey::Symbol=:default)
140-
data = solverData(fact) # TODO , solveKey=solveKey)
139+
data = getSolverData(fact) # TODO , solveKey=solveKey)
141140
return getfnctype(data)
142141
end
143142
function getfnctype(dfg::T, lbl::Symbol; solveKey::Symbol=:default) where T <: AbstractDFG
@@ -153,7 +152,7 @@ Notes
153152
- Replaces older `getfnctype`.
154153
"""
155154
getFactorType(data::GenericFunctionNodeData) = data.fnc.usrfnc!
156-
getFactorType(fct::DFGFactor) = getFactorType(solverData(fct))
155+
getFactorType(fct::DFGFactor) = getFactorType(getSolverData(fct))
157156
function getFactorType(dfg::G, lbl::Symbol) where G <: AbstractDFG
158157
getFactorType(getFactor(dfg, lbl))
159158
end
@@ -464,3 +463,29 @@ function hasTagsNeighbors(dfg::InMemoryDFGTypes,
464463
alltags = union( (ls(dfg, sym) .|> x->getTags(getNeiFnc(dfg,x)))... )
465464
length(filter(x->x in alltags, tags)) >= (matchAll ? length(tags) : 1)
466465
end
466+
467+
468+
469+
#Natural Sorting
470+
# Adapted from https://rosettacode.org/wiki/Natural_sorting
471+
# split at digit to not digit change
472+
splitbynum(x::AbstractString) = split(x, r"(?<=\D)(?=\d)|(?<=\d)(?=\D)")
473+
#parse to Int
474+
numstringtonum(arr::Vector{<:AbstractString}) = [(n = tryparse(Int, e)) != nothing ? n : e for e in arr]
475+
#natural less than
476+
function natural_lt(x::T, y::T) where T <: AbstractString
477+
xarr = numstringtonum(splitbynum(x))
478+
yarr = numstringtonum(splitbynum(y))
479+
for i in 1:min(length(xarr), length(yarr))
480+
if typeof(xarr[i]) != typeof(yarr[i])
481+
return isa(xarr[i], Int)
482+
elseif xarr[i] == yarr[i]
483+
continue
484+
else
485+
return xarr[i] < yarr[i]
486+
end
487+
end
488+
return length(xarr) < length(yarr)
489+
end
490+
491+
natural_lt(x::Symbol, y::Symbol) = natural_lt(string(x),string(y))

src/Deprecated.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ end
131131
Retrieve data structure stored in a variable.
132132
"""
133133
function getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData
134-
@warn "getData is deprecated, please use solverData()"
134+
@warn "getData is deprecated, please use getSolverData()"
135135
return v.solverDataDict[solveKey]
136136
end
137137

@@ -153,6 +153,6 @@ end
153153
Retrieve solver data structure stored in a factor.
154154
"""
155155
function data(f::DFGFactor)::GenericFunctionNodeData
156-
@warn "data() is deprecated, please use solverData()"
156+
@warn "data() is deprecated, please use getSolverData()"
157157
return f.data
158158
end

src/FileDFG/services/FileDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function loadDFG(dst::String, iifModule, dfgLoadInto::G; loaddir=joinpath("/","t
138138
# PATCH - To update the fncargvID for factors, it's being cleared somewhere in rebuildFactorMetadata.
139139
# TEMPORARY
140140
# TODO: Remove in future
141-
map(f->solverData(f).fncargvID = f._variableOrderSymbols, getFactors(dfgLoadInto))
141+
map(f->getSolverData(f).fncargvID = f._variableOrderSymbols, getFactors(dfgLoadInto))
142142

143143
return dfgLoadInto
144144
end

src/LightDFG/LightDFG.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ import ...DistributedFactorGraphs: setSolverParams,
4040
getNeighbors,
4141
getSubgraphAroundNode,
4242
getSubgraph,
43-
getIncidenceMatrix,
44-
getIncidenceMatrixSparse,
43+
getBiadjacencyMatrix,
4544
_getDuplicatedEmptyDFG,
4645
toDot,
4746
toDotFile

src/LightDFG/services/LightDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function _copyIntoGraph!(sourceDFG::LightDFG{<:AbstractParams, V, F}, destDFG::L
261261

262262
for v in values(sourceDFG.g.variables)
263263
if v.label in labels
264-
exists(destDFG, v) ? (@warn "_copyIntoGraph $(v.label) exists, ignoring") : addVariable!(destDFG, deepcopy(v))
264+
exists(destDFG, v) ? (@warn "_copyIntoGraph $(v.label) exists, ignoring pending error behaviour decision") : addVariable!(destDFG, deepcopy(v))
265265
end
266266
end
267267

@@ -283,7 +283,7 @@ function _copyIntoGraph!(sourceDFG::LightDFG{<:AbstractParams, V, F}, destDFG::L
283283

284284
# Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
285285
if includeOrphanFactors || length(factVariables) == length(neigh_labels)
286-
exists(destDFG, f.label) ? (@warn "_copyIntoGraph $(f.label) exists, ignoring") : addFactor!(destDFG, factVariables, deepcopy(f))
286+
exists(destDFG, f.label) ? (@warn "_copyIntoGraph $(f.label) exists, ignoring pending error behaviour decision") : addFactor!(destDFG, factVariables, deepcopy(f))
287287
end
288288
end
289289
end

src/services/AbstractDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ function getSolveInProgress(var::Union{DFGVariable, DFGFactor}; solveKey::Symbol
823823
# Variable
824824
var isa DFGVariable && return haskey(getSolverDataDict(var), solveKey) ? getSolverDataDict(var)[solveKey].solveInProgress : 0
825825
# Factor
826-
return solverData(var).solveInProgress
826+
return getSolverData(var).solveInProgress
827827
end
828828

829829
"""
@@ -909,7 +909,7 @@ end
909909
Return reference to the user factor in `<:AbstractDFG` identified by `::Symbol`.
910910
"""
911911
getFactorFunction(fcd::GenericFunctionNodeData) = fcd.fnc.usrfnc!
912-
getFactorFunction(fc::DFGFactor) = getFactorFunction(solverData(fc))
912+
getFactorFunction(fc::DFGFactor) = getFactorFunction(getSolverData(fc))
913913
function getFactorFunction(dfg::G, fsym::Symbol) where G <: AbstractDFG
914914
getFactorFunction(getFactor(dfg, fsym))
915915
end

src/services/CompareUtils.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ function compareVariable(A::DFGVariable,
132132
union!(skiplist, skip)
133133
TP = TP && compareAll(A.solverDataDict, B.solverDataDict, skip=skiplist, show=show)
134134

135-
Ad = solverData(A)
136-
Bd = solverData(B)
135+
Ad = getSolverData(A)
136+
Bd = getSolverData(B)
137137

138138
# TP = TP && compareAll(A.attributes, B.attributes, skip=[:softtype;], show=show)
139139
varskiplist = union(varskiplist, [:softtype;:_internalId])
@@ -169,20 +169,20 @@ function compareFactor(A::DFGFactor,
169169
#
170170
TP = compareAll(A, B, skip=union([:attributes;:data;:_variableOrderSymbols;:_internalId],skip), show=show)
171171
# TP = TP & compareAll(A.attributes, B.attributes, skip=[:data;], show=show)
172-
TP = TP & compareAllSpecial(solverData(A), solverData(B), skip=union([:fnc;:_internalId], skip), show=show)
173-
TP = TP & compareAllSpecial(solverData(A).fnc, solverData(B).fnc, skip=union([:cpt;:measurement;:params;:varidx;:threadmodel], skip), show=show)
174-
TP = TP & (skipsamples || compareAll(solverData(A).fnc.measurement, solverData(B).fnc.measurement, show=show, skip=skip))
175-
TP = TP & (skipcompute || compareAll(solverData(A).fnc.params, solverData(B).fnc.params, show=show, skip=skip))
176-
TP = TP & (skipcompute || compareAll(solverData(A).fnc.varidx, solverData(B).fnc.varidx, show=show, skip=skip))
172+
TP = TP & compareAllSpecial(getSolverData(A), getSolverData(B), skip=union([:fnc;:_internalId], skip), show=show)
173+
TP = TP & compareAllSpecial(getSolverData(A).fnc, getSolverData(B).fnc, skip=union([:cpt;:measurement;:params;:varidx;:threadmodel], skip), show=show)
174+
TP = TP & (skipsamples || compareAll(getSolverData(A).fnc.measurement, getSolverData(B).fnc.measurement, show=show, skip=skip))
175+
TP = TP & (skipcompute || compareAll(getSolverData(A).fnc.params, getSolverData(B).fnc.params, show=show, skip=skip))
176+
TP = TP & (skipcompute || compareAll(getSolverData(A).fnc.varidx, getSolverData(B).fnc.varidx, show=show, skip=skip))
177177

178178
return TP
179179
end
180-
# Ad = solverData(A)
181-
# Bd = solverData(B)
180+
# Ad = getSolverData(A)
181+
# Bd = getSolverData(B)
182182
# TP = compareAll(A, B, skip=[:attributes;:data], show=show)
183183
# TP &= compareAll(A.attributes, B.attributes, skip=[:data;], show=show)
184-
# TP &= compareAllSpecial(solverData(A).fnc, solverData(B).fnc, skip=[:cpt;], show=show)
185-
# TP &= compareAll(solverData(A).fnc.cpt, solverData(B).fnc.cpt, show=show)
184+
# TP &= compareAllSpecial(getSolverData(A).fnc, getSolverData(B).fnc, skip=[:cpt;], show=show)
185+
# TP &= compareAll(getSolverData(A).fnc.cpt, getSolverData(B).fnc.cpt, show=show)
186186

187187

188188
"""

src/services/DFGVariable.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ end
164164
Add Big Data Entry to a DFG variable
165165
"""
166166
function addBigDataEntry!(var::AbstractDFGVariable, bde::AbstractBigDataEntry)::AbstractDFGVariable
167-
haskey(var.bigData,bde.key) && @warn "$(bde.key) already exists in variable, overwriting!"
167+
haskey(var.bigData,bde.key) && error("BigData entry $(bde.key) already exists in variable")
168168
var.bigData[bde.key] = bde
169169
return var
170170
end
@@ -424,5 +424,5 @@ Related
424424
getSolved, isSolved
425425
"""
426426
setSolvedCount!(v::VariableNodeData, val::Int) = v.solvedCount = val
427-
setSolvedCount!(v::VariableDataLevel2, val::Int, solveKey::Symbol=:default) = setSolvedCount!(solverData(v, solveKey), val)
427+
setSolvedCount!(v::VariableDataLevel2, val::Int, solveKey::Symbol=:default) = setSolvedCount!(getSolverData(v, solveKey), val)
428428
setSolvedCount!(dfg::AbstractDFG, sym::Symbol, val::Int, solveKey::Symbol=:default) = setSolvedCount!(getVariable(dfg, sym), val, solveKey)

test/LightDFGSummaryTypes.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ end
6868
@test exists(dfg, :a) == true
6969
@test exists(dfg, v1) == true
7070
@test exists(dfg, :nope) == false
71-
# Sorting of results
72-
# TODO - this function needs to be cleaned up
73-
unsorted = [:x1_3;:x1_6;:l1;:april1] #this will not work for :x1x2f1
74-
@test sortDFG(unsorted) == sortVarNested(unsorted)
75-
@test_skip sortDFG([:x1x2f1, :x1l1f1]) == [:x1l1f1, :x1x2f1]
7671
end
7772

7873
# Gets

0 commit comments

Comments
 (0)