Skip to content

Commit 4db06a8

Browse files
committed
ref verb and filter improvements
1 parent d3fb2fa commit 4db06a8

File tree

11 files changed

+58
-27
lines changed

11 files changed

+58
-27
lines changed

src/Common.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ function filterDFG!(nodes, predicate::Function, by::Function = identity)
126126
return filter!(predicate by, nodes)
127127
end
128128

129+
# specialized for label::Symbol filtering
130+
function filterDFG!(nodes, predicate::Function, by::typeof(getLabel))
131+
# TODO this is not as clean as it should be, revisit if any issues arise
132+
# Standard predicates that needs to be converted to string to work with Symbols
133+
# OR look for the type if predicate isa Base.Fix2 && (predicate.x isa AbstractString || predicate.x isa Regex)
134+
if predicate isa Base.Fix2 && typeof(predicate.f) in [typeof(contains), typeof(startswith), typeof(endswith)]
135+
return filter!(predicate string by, nodes)
136+
else
137+
return filter!(predicate by, nodes)
138+
end
139+
end
140+
129141
##==============================================================================
130142
## Validation of session, robot, and user labels.
131143
##==============================================================================

src/DataBlobs/services/BlobEntry.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function getBlobentries(
218218
blobIdFilter::Union{Nothing, Function} = nothing,
219219
)
220220
entries = getBlobentries(v)
221-
filterDFG!(entries, labelFilter, x -> string(x.label))
221+
filterDFG!(entries, labelFilter, getLabel)
222222
filterDFG!(entries, blobIdFilter, x -> string(x.blobId))
223223
return entries
224224
end

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ function mergeVariable!(dfg::GraphsDFG, variable::AbstractGraphVariable)
9191
return 1
9292
end
9393

94+
function mergeVariables!(dfg::GraphsDFG, variables)
95+
cnts = map(mergeVariable!, variables)
96+
return sum(cnts)
97+
end
98+
9499
function mergeFactor!(dfg::GraphsDFG, factor::AbstractGraphFactor)
95100
if !haskey(dfg.g.factors, factor.label)
96101
addFactor!(dfg, factor)
@@ -174,7 +179,7 @@ function getVariables(
174179
filterDFG!(variables, >=(solvable), getSolvable)
175180
end
176181

177-
filterDFG!(variables, labelFilter, (String getLabel))
182+
filterDFG!(variables, labelFilter, getLabel)
178183
filterDFG!(variables, solvableFilter, getSolvable)
179184
filterDFG!(variables, tagsFilter, getTags)
180185
filterDFG!(variables, typeFilter, getVariableType)
@@ -236,7 +241,7 @@ function getFactors(
236241
"The regex filter argument is deprecated, use kwarg `labelFilter=contains(regex)` instead", #v0.28
237242
:getFactors,
238243
)
239-
filterDFG!(factors, contains(regex), (String getLabel))
244+
filterDFG!(factors, contains(regex), getLabel)
240245
end
241246
if !isempty(tags)
242247
# NOTE that !isdisjoint is not supported by NvaDFG.
@@ -255,7 +260,7 @@ function getFactors(
255260
filterDFG!(factors, >=(solvable), getSolvable)
256261
end
257262

258-
filterDFG!(factors, labelFilter, (String getLabel))
263+
filterDFG!(factors, labelFilter, getLabel)
259264
filterDFG!(factors, solvableFilter, getSolvable)
260265
filterDFG!(factors, tagsFilter, getTags)
261266
filterDFG!(factors, typeFilter, typeof getFactorType)
@@ -557,7 +562,7 @@ end
557562

558563
function getGraphBlobentries(fg::GraphsDFG; labelFilter::Union{Nothing, Function} = nothing)
559564
entries = collect(values(fg.graph.blobEntries))
560-
filterDFG!(entries, labelFilter, (String getLabel))
565+
filterDFG!(entries, labelFilter, getLabel)
561566
return entries
562567
end
563568

@@ -566,7 +571,7 @@ function listGraphBlobentries(
566571
labelFilter::Union{Nothing, Function} = nothing,
567572
)
568573
labels = collect(keys(fg.graph.blobEntries))
569-
filterDFG!(labels, labelFilter, String)
574+
filterDFG!(labels, labelFilter, string)
570575
return labels
571576
end
572577

src/entities/AbstractDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# TODO consider enforcing the full structure.
33
# This is not explicitly inforced, but surves as extra information of how the structure is put together.
4-
# AbstractDFGNode are all nodes that make up a DFG, including Agent, Graph, Variable, Factor, Blobstore, etc.
4+
# AbstractDFGNode are all nodes that make up a DFG, including Agent, Graph, Variable, Factor, Blobstore, Blobentry etc.
55
# abstract type AbstractDFGNode end
66
# any DFGNode shall have a label.
77
# abstract type AbstractGraphNode end <: AbstractDFGNode

src/entities/DFGFactor.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ Base.@kwdef struct FactorCompute{FT <: AbstractObservation, N} <: AbstractGraphF
223223
solvercache::Base.RefValue{<:FactorCache} #TODO easy of use vs. performance as container is abstract in any case.
224224
end
225225

226+
#FIXME rename smallData to metadata
227+
refMetadata(node::FactorCompute) = node.smallData
228+
226229
##------------------------------------------------------------------------------
227230
## Constructors
228231

src/entities/DFGVariable.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Base.@kwdef mutable struct State{T <: StateType, P, N}
4444
Flag used by junction (Bayes) tree construction algorithm to know whether this variable has yet been included in the tree construction.
4545
"""
4646
eliminated::Bool = false
47-
BayesNetVertID::Symbol = :NOTHING # Union{Nothing, }
47+
BayesNetVertID::Symbol = :NOTHING # Union{Nothing, } #TODO deprecate
4848
separator::Vector{Symbol} = Symbol[]
4949
"""
5050
False if initial numerical values are not yet available or stored values are not ready for further processing yet.
@@ -118,7 +118,7 @@ Base.@kwdef mutable struct PackedState
118118
dimIDs::Vector{Int}
119119
dims::Int
120120
eliminated::Bool
121-
BayesNetVertID::Symbol # Int
121+
BayesNetVertID::Symbol # Int #TODO deprecate
122122
separator::Vector{Symbol} # Int
123123
variableType::String
124124
initialized::Bool
@@ -163,7 +163,6 @@ Data container to store Parameteric Point Estimate (PPE) for mean and max.
163163
"""
164164
Base.@kwdef struct MeanMaxPPE <: AbstractPointParametricEst
165165
id::Union{UUID, Nothing} = nothing # If it's blank it doesn't exist in the DB.
166-
# repeat key value internally (from a design request by Sam)
167166
solveKey::Symbol
168167
suggested::Vector{Float64}
169168
max::Vector{Float64}
@@ -326,6 +325,10 @@ Base.@kwdef struct VariableCompute{T <: StateType, P, N} <: AbstractGraphVariabl
326325
solvable::Base.RefValue{Int} = Ref(1)
327326
end
328327

328+
refStates(v::VariableCompute) = v.solverDataDict
329+
refMetadata(v::VariableCompute) = v.smallData
330+
refBlobentries(v::VariableCompute) = v.dataDict
331+
329332
##------------------------------------------------------------------------------
330333
## Constructors
331334

src/services/AbstractDFG.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,8 @@ Related
10991099
"""
11001100
function findShortestPathDijkstra end
11011101

1102+
1103+
#TODO deprecate
11021104
"""
11031105
$SIGNATURES
11041106

src/services/CommonAccessors.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
##==============================================================================
22
## Common Accessors
33
##==============================================================================
4+
5+
refTags(node) = node.tags
6+
refMetadata(node) = node.metadata
7+
refBlobentries(node) = node.blobEntries # FIXME rename blobEntries to blobentries to match noun
8+
49
# Common get and set methods
510

611
# NOTE this could be reduced with macros and function generation to even less code.

src/services/CompareUtils.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,37 +196,37 @@ end
196196

197197
#Compare State
198198
function compare(a::State, b::State)
199-
a.val != b.val && @debug("val is not equal") == nothing && return false
200-
a.bw != b.bw && @debug("bw is not equal") == nothing && return false
199+
a.val != b.val && @debug("val is not equal") === nothing && return false
200+
a.bw != b.bw && @debug("bw is not equal") === nothing && return false
201201
a.BayesNetOutVertIDs != b.BayesNetOutVertIDs &&
202-
@debug("BayesNetOutVertIDs is not equal") == nothing &&
202+
@debug("BayesNetOutVertIDs is not equal") === nothing &&
203203
return false
204-
a.dimIDs != b.dimIDs && @debug("dimIDs is not equal") == nothing && return false
205-
a.dims != b.dims && @debug("dims is not equal") == nothing && return false
204+
a.dimIDs != b.dimIDs && @debug("dimIDs is not equal") === nothing && return false
205+
a.dims != b.dims && @debug("dims is not equal") === nothing && return false
206206
a.eliminated != b.eliminated &&
207-
@debug("eliminated is not equal") == nothing &&
207+
@debug("eliminated is not equal") === nothing &&
208208
return false
209209
a.BayesNetVertID != b.BayesNetVertID &&
210-
@debug("BayesNetVertID is not equal") == nothing &&
210+
@debug("BayesNetVertID is not equal") === nothing &&
211211
return false
212212
a.separator != b.separator &&
213-
@debug("separator is not equal") == nothing &&
213+
@debug("separator is not equal") === nothing &&
214214
return false
215215
a.initialized != b.initialized &&
216-
@debug("initialized is not equal") == nothing &&
216+
@debug("initialized is not equal") === nothing &&
217217
return false
218218
!isapprox(a.infoPerCoord, b.infoPerCoord; atol = 1e-13) &&
219-
@debug("infoPerCoord is not equal") == nothing &&
219+
@debug("infoPerCoord is not equal") === nothing &&
220220
return false
221-
a.ismargin != b.ismargin && @debug("ismargin is not equal") == nothing && return false
221+
a.ismargin != b.ismargin && @debug("ismargin is not equal") === nothing && return false
222222
a.dontmargin != b.dontmargin &&
223-
@debug("dontmargin is not equal") == nothing &&
223+
@debug("dontmargin is not equal") === nothing &&
224224
return false
225225
a.solveInProgress != b.solveInProgress &&
226-
@debug("solveInProgress is not equal") == nothing &&
226+
@debug("solveInProgress is not equal") === nothing &&
227227
return false
228228
getVariableType(a) != getVariableType(b) &&
229-
@debug("variableType is not equal") == nothing &&
229+
@debug("variableType is not equal") === nothing &&
230230
return false
231231
return true
232232
end

src/services/DFGFactor.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ See documentation in [Manifolds.jl on making your own](https://juliamanifolds.gi
132132
133133
Example:
134134
```
135-
DFG.@defObservationType Pose2Pose2 RelativeObservation SpecialEuclidean(2)
135+
DFG.@defObservationType Pose2Pose2 RelativeObservation SpecialEuclideanGroup(2)
136136
```
137137
"""
138138
macro defObservationType(structname, factortype, manifold)
@@ -167,6 +167,7 @@ macro defObservationType(structname, factortype, manifold)
167167
end
168168

169169
getManifold(obs::AbstractObservation) = getManifold(typeof(obs))
170+
getManifold(f::AbstractGraphFactor) = getManifold(getObservation(f))
170171

171172
##==============================================================================
172173
## Factors

0 commit comments

Comments
 (0)