Skip to content

Commit 6b903b7

Browse files
authored
Merge pull request #301 from JuliaRobotics/maint/20Q1/cleanup06
Maintenance Cleanup for v0.6
2 parents 24d362c + dab312c commit 6b903b7

File tree

12 files changed

+49
-122
lines changed

12 files changed

+49
-122
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ function getFactors(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=noth
339339
return map(vId->getFactor(dfg, vId), factorIds)
340340
end
341341

342-
function listFactors(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{Symbol}
342+
function listFactors(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{Symbol}
343343
# Optimized for DB call
344+
length(tags) > 0 && (@error "Filter on tags not implemented for CloudGraphsDFG")
344345
if regexFilter == nothing
345346
return _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):FACTOR) where node.solvable >= $solvable")
346347
else

src/Common.jl

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -64,82 +64,3 @@ ls, lsf
6464
"""
6565
sortDFG(vars::Vector{<:DFGNode}; by=getTimestamp, kwargs...) = sort(vars; by=by, kwargs...)
6666
sortDFG(vars::Vector{Symbol}; lt=natural_lt, kwargs...)::Vector{Symbol} = sort(vars; lt=lt, kwargs...)
67-
68-
69-
70-
#TODO confirm this is only used in sortVarNested, then delete
71-
# """
72-
# $(SIGNATURES)
73-
# Test if all elements of the string is a number: Ex, "123" is true, "1_2" is false.
74-
# """
75-
# allnums(str::S) where {S <: AbstractString} = occursin(Regex(string(["[0-9]" for j in 1:length(str)]...)), str)
76-
# occursin(r"_+|,+|-+", node_idx)
77-
78-
# isnestednum(str::S; delim='_') where {S <: AbstractString} = occursin(Regex("[0-9]+$(delim)[0-9]+"), str)
79-
80-
# function sortnestedperm(strs::Vector{<:AbstractString}; delim='_')
81-
# str12 = split.(strs, delim)
82-
# sp1 = sortperm(parse.(Int,getindex.(str12,2)))
83-
# sp2 = sortperm(parse.(Int,getindex.(str12,1)[sp1]))
84-
# return sp1[sp2]
85-
# end
86-
87-
# function getFirstNumericalOffset(st::AS) where AS <: AbstractString
88-
# i = 1
89-
# while !allnums(st[i:i]) i+=1; end
90-
# return i
91-
# end
92-
#
93-
# """
94-
# $SIGNATURES
95-
#
96-
# Sort a variable list which may have nested structure such as `:x1_2` -- does not sort for alphabetic characters.
97-
# """
98-
# function sortVarNested(vars::Vector{Symbol})::Vector{Symbol}
99-
# # whos nested and first numeric character offset
100-
# sv = string.(vars)
101-
# offsets = getFirstNumericalOffset.(sv)
102-
# masknested = isnestednum.(sv)
103-
# masknotnested = true .⊻ masknested
104-
#
105-
# # strip alphabetic characters from front
106-
# msv = sv[masknotnested]
107-
# msvO = offsets[masknotnested]
108-
# nsv = sv[masknested]
109-
# nsvO = offsets[masknested]
110-
#
111-
# # do nonnested list separately
112-
# nnreducelist = map((s,o) -> s[o:end], msv, msvO)
113-
# nnintlist = parse.(Int, nnreducelist)
114-
# nnp = sortperm(nnintlist)
115-
# nnNums = nnintlist[nnp] # used in mixing later
116-
# nonnested = msv[nnp]
117-
# smsv = vars[masknotnested][nnp]
118-
#
119-
# # do nested list separately
120-
# nestedreducelist = map((s,o) -> s[o:end], nsv, nsvO)
121-
# nestedp = sortnestedperm(nestedreducelist)
122-
# nesNums = parse.(Int, getindex.(split.(nestedreducelist[nestedp], '_'),1)) # used in mixing later
123-
# nested = nsv[nestedp]
124-
# snsv = vars[masknested][nestedp]
125-
#
126-
# # mix back together, pick next sorted item from either pile
127-
# retvars = Vector{Symbol}(undef, length(vars))
128-
# nni = 1
129-
# nesi = 1
130-
# lsmsv = length(smsv)
131-
# lsnsv = length(snsv)
132-
# MAXMAX = 999999999999
133-
# for i in 1:length(vars)
134-
# # inner ifs to ensure bounds and correct sorting at end of each list
135-
# if (nni<=lsmsv ? nnNums[nni] : MAXMAX) <= (nesi<=lsnsv ? nesNums[nesi] : MAXMAX)
136-
# retvars[i] = smsv[nni]
137-
# nni += 1
138-
# else
139-
# retvars[i] = snsv[nesi]
140-
# nesi += 1
141-
# end
142-
# end
143-
# return retvars
144-
# end
145-
#END TODO confirm this is only used in sortVarNested, then delete

src/Deprecated.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
## Remove in 0.6.0 or 0.6.1?
99
##==============================================================================
1010

11+
@deprecate getfnctype(args...) getFactorType(args...)
12+
1113
@deprecate getEstimate(v::VariableDataLevel1, key::Symbol=:default) getVariablePPE(v, key)
1214

1315
@deprecate estimate(v::VariableDataLevel1, key::Symbol=:default) getVariablePPE(v, key)
@@ -157,9 +159,6 @@ end
157159

158160
@deprecate internalId(args...) getInternalId(args...)
159161

160-
#FIXME TODO based on API definition of merge, in some cases the Noun is really not needed.
161-
# @deprecate mergeUpdateVariableSolverData!(args...) mergeVariableSolverData!(args...)
162-
163162
@deprecate pack(dfg::AbstractDFG, d::VariableNodeData) packVariableNodeData(dfg, d)
164163
@deprecate unpack(dfg::AbstractDFG, d::PackedVariableNodeData) unpackVariableNodeData(dfg, d)
165164

@@ -191,6 +190,3 @@ function buildSubgraphFromLabels(dfg::G,
191190
end
192191

193192
@deprecate sortVarNested(vars::Vector{Symbol}) sortDFG(vars)
194-
195-
#TODO Deprecated or obsolete?
196-
@deprecate getfnctype(args...) getFactorType(args...)

src/DistributedFactorGraphs.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export isFullyConnected, hasOrphans
7171

7272
export getBiadjacencyMatrix
7373

74-
#summary structure #TODO Abstract name here is confusing
75-
export AbstractDFGSummary
74+
#summary structure
75+
export DFGSummary
7676

7777
export getSummary, getSummaryGraph
7878

@@ -110,7 +110,7 @@ export InferenceVariable
110110

111111
# accessors
112112
export getSolverDataDict, setSolverData!
113-
export getSofttype
113+
export getSofttype, getSofttypename
114114

115115
export getSolverData
116116

src/LightDFG/LightDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module LightDFGs
33
using LightGraphs
44
using DocStringExtensions
55

6-
import ...DistributedFactorGraphs: AbstractDFG, DFGNode, AbstractDFGVariable, AbstractDFGFactor, AbstractDFGSummary, AbstractParams, NoSolverParams, DFGVariable, DFGFactor
6+
import ...DistributedFactorGraphs: AbstractDFG, DFGNode, AbstractDFGVariable, AbstractDFGFactor, DFGSummary, AbstractParams, NoSolverParams, DFGVariable, DFGFactor
77

88
# import DFG functions to extend
99
import ...DistributedFactorGraphs: setSolverParams!,

src/LightDFG/services/LightDFG.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,11 @@ function getFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; t
184184
return factors
185185
end
186186

187-
function listFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{Symbol}
187+
function listFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{Symbol}
188188
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
189+
if length(tags) > 0
190+
return map(v -> v.label, getFactor(dfg, regexFilter, tags=tags, solvable=solvable))
191+
end
189192
factors = collect(keys(dfg.g.factors))
190193
if regexFilter != nothing
191194
factors = filter(f -> occursin(regexFilter, String(f)), factors)

src/entities/AbstractDFGSummary.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
$(TYPEDEF)
33
Structure for a graph summary.
44
"""
5-
# TODO why is this called Abstract...
6-
struct AbstractDFGSummary
5+
6+
struct DFGSummary
77
variables::Dict{Symbol, DFGVariableSummary}
88
factors::Dict{Symbol, DFGFactorSummary}
99
userId::String

src/services/AbstractDFG.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,19 @@ end
292292
$(SIGNATURES)
293293
Checks if the graph is fully connected, returns true if so.
294294
"""
295-
function isFullyConnected(dfg::G)::Bool where G <: AbstractDFG
295+
function isFullyConnected(dfg::AbstractDFG)::Bool
296296
error("isFullyConnected not implemented for $(typeof(dfg))")
297297
end
298298

299299
"""
300300
$(SIGNATURES)
301301
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
302302
"""
303-
function getNeighbors(dfg::G, label::Symbol; solvable::Int=0)::Vector{Symbol} where G <: AbstractDFG
304-
error("getNeighbors not implemented for $(typeof(dfg))")
305-
end
306-
##TODO reduce with getNeighbors(dfg, node.label)
307-
function getNeighbors(dfg::G, node::T; solvable::Int=0)::Vector{Symbol} where {G <: AbstractDFG, T <: DFGNode}
303+
function getNeighbors(dfg::AbstractDFG, label::Symbol; solvable::Int=0)::Vector{Symbol}
308304
error("getNeighbors not implemented for $(typeof(dfg))")
309305
end
310306

307+
311308
##------------------------------------------------------------------------------
312309
## copy and duplication
313310
##------------------------------------------------------------------------------
@@ -416,6 +413,11 @@ end
416413
##------------------------------------------------------------------------------
417414
## Connectivity Alias
418415
##------------------------------------------------------------------------------
416+
417+
function getNeighbors(dfg::AbstractDFG, node::DFGNode; solvable::Int=0)::Vector{Symbol}
418+
getNeighbors(dfg, node.label, solvable=solvable)
419+
end
420+
419421
#Alias
420422
#TODO rather actually check if there are orphaned factors (factors without all variables)
421423
"""
@@ -457,8 +459,8 @@ end
457459
Get a list of the IDs (labels) of the DFGFactors in the DFG.
458460
Optionally specify a label regular expression to retrieves a subset of the factors.
459461
"""
460-
function listFactors(dfg::G, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{Symbol} where G <: AbstractDFG
461-
return map(f -> f.label, getFactors(dfg, regexFilter, solvable=solvable))
462+
function listFactors(dfg::G, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{Symbol} where G <: AbstractDFG
463+
return map(f -> f.label, getFactors(dfg, regexFilter, tags=tags, solvable=solvable))
462464
end
463465

464466
##------------------------------------------------------------------------------
@@ -485,8 +487,8 @@ end
485487
List the DFGFactors in the DFG.
486488
Optionally specify a label regular expression to retrieves a subset of the factors.
487489
"""
488-
function lsf(dfg::G, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{Symbol} where G <: AbstractDFG
489-
return listFactors(dfg, regexFilter, solvable=solvable)
490+
function lsf(dfg::G, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{Symbol} where G <: AbstractDFG
491+
return listFactors(dfg, regexFilter, tags=tags, solvable=solvable)
490492
end
491493

492494

@@ -1036,12 +1038,12 @@ end
10361038
"""
10371039
$(SIGNATURES)
10381040
Get a summary of the graph (first-class citizens of variables and factors).
1039-
Returns a AbstractDFGSummary.
1041+
Returns a DFGSummary.
10401042
"""
1041-
function getSummary(dfg::G)::AbstractDFGSummary where {G <: AbstractDFG}
1043+
function getSummary(dfg::G)::DFGSummary where {G <: AbstractDFG}
10421044
vars = map(v -> convert(DFGVariableSummary, v), getVariables(dfg))
10431045
facts = map(f -> convert(DFGFactorSummary, f), getFactors(dfg))
1044-
return AbstractDFGSummary(
1046+
return DFGSummary(
10451047
Dict(map(v->v.label, vars) .=> vars),
10461048
Dict(map(f->f.label, facts) .=> facts),
10471049
dfg.userId,

src/services/DFGVariable.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,16 @@ function getSofttype(vnd::VariableNodeData)
3434
return vnd.softtype
3535
end
3636

37-
#TODO getSofttype(v::DFGVariable, solvekey::Symbol=:default) getSofttype(getSolverData(v, solvekey))
38-
function getSofttype(v::DFGVariable, solvekey::Symbol=:default)
39-
return v.solverDataDict[solvekey].softtype # Get instantiated form of the parameter for the DFGVariable
40-
end
37+
getSofttype(v::DFGVariable, solvekey::Symbol=:default) = getSofttype(getSolverData(v, solvekey))
38+
39+
getSofttype(dfg::AbstractDFG, lbl::Symbol, solvekey::Symbol=:default) = getSofttype(getVariable(dfg,lbl), solvekey)
4140

42-
## TODO repeated function and broken as it does not pass in solvekey
4341
"""
44-
$SIGNATURES
42+
getVariableType
4543
46-
Return the DFGVariable softtype in factor graph `dfg<:AbstractDFG` and label `::Symbol`.
44+
Alias for [`getSofttype`](@ref).
4745
"""
48-
getVariableType(var::DFGVariable) = getSofttype(var)
49-
function getVariableType(dfg::G, lbl::Symbol) where G <: AbstractDFG
50-
getVariableType(getVariable(dfg, lbl))
51-
end
46+
getVariableType(params...) = getSofttype(params...)
5247

5348
##------------------------------------------------------------------------------
5449
## solvedCount
@@ -284,16 +279,21 @@ end
284279
## TODO this should return the softtype object, or try to. it should be getSofttypename for the accessor
285280
## TODO Consider parameter N in softtype for dims, and storing constructor in softtypename
286281
## TODO or just not having this function at all
282+
# getSofttype(v::DFGVariableSummary) = v.softypename()
287283
##------------------------------------------------------------------------------
288284

289285
"""
290286
$SIGNATURES
291287
292288
Retrieve the soft type name symbol for a DFGVariableSummary. ie :Point2, Pose2, etc.
293-
TODO, DO NOT USE v.softtypename in DFGVariableSummary
294289
"""
295-
getSofttype(v::DFGVariableSummary)::Symbol = v.softtypename
290+
getSofttypename(v::DFGVariableSummary)::Symbol = v.softtypename
291+
296292

293+
function getSofttype(v::DFGVariableSummary)::InferenceVariable
294+
@warn "Looking for type in `Main`. Only use if softtype has only one implementation,ie. Pose2. Otherwise use the full variable."
295+
return getfield(Main, v.softtypename)()
296+
end
297297

298298
##==============================================================================
299299
## Layer 2 CRUD and SET

test/LightDFGSummaryTypes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end
4242
@test getTimestamp(v1) == v1.timestamp
4343
@test getVariablePPEs(v1) == v1.ppeDict
4444
@test_throws KeyError getVariablePPE(v1, :notfound)
45-
@test getSofttype(v1) == :Pose2
45+
@test getSofttypename(v1) == :Pose2
4646
@test getInternalId(v1) == v1._internalId
4747

4848
# FACTYPE == DFGFactorSummary

0 commit comments

Comments
 (0)