47
47
Sort a variable list which may have nested structure such as `:x1_2` -- does not sort for alphabetic characters.
48
48
"""
49
49
function sortVarNested (vars:: Vector{Symbol} ):: Vector{Symbol}
50
- # whos nested and first numeric character offset
51
- sv = string .(vars)
52
- offsets = getFirstNumericalOffset .(sv)
53
- masknested = isnestednum .(sv)
54
- masknotnested = true .⊻ masknested
55
-
56
- # strip alphabetic characters from front
57
- msv = sv[masknotnested]
58
- msvO = offsets[masknotnested]
59
- nsv = sv[masknested]
60
- nsvO = offsets[masknested]
61
-
62
- # do nonnested list separately
63
- nnreducelist = map ((s,o) -> s[o: end ], msv, msvO)
64
- nnintlist = parse .(Int, nnreducelist)
65
- nnp = sortperm (nnintlist)
66
- nnNums = nnintlist[nnp] # used in mixing later
67
- nonnested = msv[nnp]
68
- smsv = vars[masknotnested][nnp]
69
-
70
- # do nested list separately
71
- nestedreducelist = map ((s,o) -> s[o: end ], nsv, nsvO)
72
- nestedp = sortnestedperm (nestedreducelist)
73
- nesNums = parse .(Int, getindex .(split .(nestedreducelist[nestedp], ' _' ),1 )) # used in mixing later
74
- nested = nsv[nestedp]
75
- snsv = vars[masknested][nestedp]
76
-
77
- # mix back together, pick next sorted item from either pile
78
- retvars = Vector {Symbol} (undef, length (vars))
79
- nni = 1
80
- nesi = 1
81
- lsmsv = length (smsv)
82
- lsnsv = length (snsv)
83
- MAXMAX = 999999999999
84
- for i in 1 : length (vars)
85
- # inner ifs to ensure bounds and correct sorting at end of each list
86
- if (nni<= lsmsv ? nnNums[nni] : MAXMAX) <= (nesi<= lsnsv ? nesNums[nesi] : MAXMAX)
87
- retvars[i] = smsv[nni]
88
- nni += 1
89
- else
90
- retvars[i] = snsv[nesi]
91
- nesi += 1
92
- end
93
- end
94
- return retvars
50
+ # whos nested and first numeric character offset
51
+ sv = string .(vars)
52
+ offsets = getFirstNumericalOffset .(sv)
53
+ masknested = isnestednum .(sv)
54
+ masknotnested = true .⊻ masknested
55
+
56
+ # strip alphabetic characters from front
57
+ msv = sv[masknotnested]
58
+ msvO = offsets[masknotnested]
59
+ nsv = sv[masknested]
60
+ nsvO = offsets[masknested]
61
+
62
+ # do nonnested list separately
63
+ nnreducelist = map ((s,o) -> s[o: end ], msv, msvO)
64
+ nnintlist = parse .(Int, nnreducelist)
65
+ nnp = sortperm (nnintlist)
66
+ nnNums = nnintlist[nnp] # used in mixing later
67
+ nonnested = msv[nnp]
68
+ smsv = vars[masknotnested][nnp]
69
+
70
+ # do nested list separately
71
+ nestedreducelist = map ((s,o) -> s[o: end ], nsv, nsvO)
72
+ nestedp = sortnestedperm (nestedreducelist)
73
+ nesNums = parse .(Int, getindex .(split .(nestedreducelist[nestedp], ' _' ),1 )) # used in mixing later
74
+ nested = nsv[nestedp]
75
+ snsv = vars[masknested][nestedp]
76
+
77
+ # mix back together, pick next sorted item from either pile
78
+ retvars = Vector {Symbol} (undef, length (vars))
79
+ nni = 1
80
+ nesi = 1
81
+ lsmsv = length (smsv)
82
+ lsnsv = length (snsv)
83
+ MAXMAX = 999999999999
84
+ for i in 1 : length (vars)
85
+ # inner ifs to ensure bounds and correct sorting at end of each list
86
+ if (nni<= lsmsv ? nnNums[nni] : MAXMAX) <= (nesi<= lsnsv ? nesNums[nesi] : MAXMAX)
87
+ retvars[i] = smsv[nni]
88
+ nni += 1
89
+ else
90
+ retvars[i] = snsv[nesi]
91
+ nesi += 1
92
+ end
93
+ end
94
+ return retvars
95
95
end
96
96
97
97
"""
277
277
"""
278
278
$(SIGNATURES)
279
279
Gives back all factor labels that fit the bill:
280
- lsWho(dfg, :Pose3)
280
+ lsWho(dfg, :Pose3)
281
281
282
282
Dev Notes
283
283
- Cloud versions will benefit from less data transfer
@@ -289,19 +289,19 @@ ls, lsf, lsfPriors
289
289
"""
290
290
function lsWho (dfg:: AbstractDFG , type:: Symbol ; solveKey:: Symbol = :default ):: Vector{Symbol}
291
291
vars = getVariables (dfg)
292
- labels = Symbol[]
292
+ labels = Symbol[]
293
293
for v in vars
294
- varType = typeof (getVariableType (v, solveKey= solveKey)). name |> Symbol
295
- varType == type && push! (labels, v. label)
296
- end
297
- return labels
294
+ varType = typeof (getVariableType (v, solveKey= solveKey)). name |> Symbol
295
+ varType == type && push! (labels, v. label)
296
+ end
297
+ return labels
298
298
end
299
299
300
300
301
301
"""
302
302
$(SIGNATURES)
303
303
Gives back all factor labels that fit the bill:
304
- lsfWho(dfg, :Point2Point2)
304
+ lsfWho(dfg, :Point2Point2)
305
305
306
306
Dev Notes
307
307
- Cloud versions will benefit from less data transfer
@@ -312,11 +312,11 @@ Related
312
312
ls, lsf, lsfPriors
313
313
"""
314
314
function lsfWho (dfg:: AbstractDFG , type:: Symbol ):: Vector{Symbol}
315
- facs = getFactors (dfg)
316
- labels = Symbol[]
315
+ facs = getFactors (dfg)
316
+ labels = Symbol[]
317
317
for f in facs
318
- facType = typeof (getFactorType (f)). name |> Symbol
319
- facType == type && push! (labels, f. label)
320
- end
321
- return labels
318
+ facType = typeof (getFactorType (f)). name |> Symbol
319
+ facType == type && push! (labels, f. label)
320
+ end
321
+ return labels
322
322
end
0 commit comments