Skip to content

Commit 932ff2a

Browse files
committed
getSofttype and getVariableType alias, and getSoftypename
1 parent ad55c92 commit 932ff2a

File tree

7 files changed

+23
-102
lines changed

7 files changed

+23
-102
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/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

test/iifInterfaceTests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ end
481481
@test getproperty(getVariable(dfg, v), field) == getfield(getVariable(summaryGraph, v), field)
482482
else
483483
# Special case to check the symbol softtype is equal to the full softtype.
484-
@test Symbol(typeof(getSofttype(getVariable(dfg, v)))) == getSofttype(getVariable(summaryGraph, v))
484+
@test Symbol(typeof(getSofttype(getVariable(dfg, v)))) == getSofttypename(getVariable(summaryGraph, v))
485485
end
486486
end
487487
end

test/testBlocks.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ function testGroup!(fg, v1, v2, f0, f1)
710710
@test lsf(fg, TestFunctorSingleton) == [:af1]
711711
@test lsfWho(fg, :TestFunctorInferenceType1) == [:abf1]
712712

713+
@test getSofttype(v1) == TestSofttype1()
714+
@test getSofttype(fg,:a) == TestSofttype1()
715+
713716
@test getVariableType(v1) == TestSofttype1()
714717
@test getVariableType(fg,:a) == TestSofttype1()
715718

@@ -1008,7 +1011,8 @@ function Summaries(testDFGAPI)
10081011
@test getproperty(getVariable(dfg, v), field) == getproperty(getVariable(summaryGraph, v), field)
10091012
else
10101013
# Special case to check the symbol softtype is equal to the full softtype.
1011-
@test Symbol(typeof(getSofttype(getVariable(dfg, v)))) == getSofttype(getVariable(summaryGraph, v))
1014+
@test Symbol(typeof(getSofttype(getVariable(dfg, v)))) == getSofttypename(getVariable(summaryGraph, v))
1015+
@test getSofttype(getVariable(dfg, v)) == getSofttype(getVariable(summaryGraph, v))
10121016
end
10131017
end
10141018
end

0 commit comments

Comments
 (0)