Skip to content

Commit 8568cff

Browse files
authored
Merge pull request #907 from JuliaRobotics/master
v0.18.7-rc1
2 parents d8ee0fa + e807599 commit 8568cff

File tree

8 files changed

+71
-13
lines changed

8 files changed

+71
-13
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.18.6"
3+
version = "0.18.7"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/DataBlobs/services/AbstractDataEntries.jl

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ buildSourceString(dfg::AbstractDFG, label::Symbol) =
2727
"""
2828
$(SIGNATURES)
2929
Get data entry
30+
31+
Also see: [`addDataEntry`](@ref), [`getDataBlob`](@ref), [`listDataEntries`](@ref)
3032
"""
3133
function getDataEntry(var::AbstractDFGVariable, key::Symbol)
3234
!hasDataEntry(var, key) && error("No dataEntry label $(key) found in variable $(getLabel(var))")
@@ -42,25 +44,23 @@ function getDataEntry(var::AbstractDFGVariable, blobId::UUID)
4244
error("No dataEntry with blobId $(blobId) found in variable $(getLabel(var))")
4345
end
4446

45-
getDataEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol,UUID}) = getDataEntry(getVariable(dfg, label), key)
47+
getDataEntry(dfg::AbstractDFG, label::Symbol, key::UUID) = getDataEntry(getVariable(dfg, label), key)
48+
getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getDataEntry(getVariable(dfg, label), key)
4649

4750

4851
"""
4952
$(SIGNATURES)
5053
Add Data Entry to a DFG variable
54+
Should be extended if DFG variable is not returned by reference.
55+
56+
Also see: [`getDataEntry`](@ref), [`addDataBlob`](@ref), [`mergeDataEntries!`](@ref)
5157
"""
5258
function addDataEntry!(var::AbstractDFGVariable, bde::AbstractDataEntry)
5359
haskey(var.dataDict, bde.label) && error("Data entry $(bde.label) already exists in variable $(getLabel(var))")
5460
var.dataDict[bde.label] = bde
5561
return bde
5662
end
5763

58-
59-
"""
60-
$(SIGNATURES)
61-
Add Data Entry to distributed factor graph.
62-
Should be extended if DFG variable is not returned by reference.
63-
"""
6464
function addDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractDataEntry)
6565
return addDataEntry!(getVariable(dfg, label), bde)
6666
end
@@ -173,3 +173,46 @@ function listDataEntrySequence( dfg::AbstractDFG,
173173
entMsk = entReg .!== nothing
174174
ents_[findall(entMsk)] |> _sort
175175
end
176+
177+
"""
178+
$SIGNATURES
179+
180+
Add a data entry into the destination variable which already exists
181+
in a source variable.
182+
183+
See also: [`addDataEntry!`](@ref), [`getDataEntry`](@ref), [`listDataEntries`](@ref), [`getDataBlob`](@ref)
184+
"""
185+
function mergeDataEntries!(
186+
dst::AbstractDFG,
187+
dlbl::Symbol,
188+
src::AbstractDFG,
189+
slbl::Symbol,
190+
bllb::Union{Symbol, UUID, <:AbstractString, Regex}
191+
)
192+
#
193+
_makevec(s) = [s;]
194+
_makevec(s::AbstractVector) = s
195+
des_ = getDataEntry(src, slbl, bllb)
196+
des = _makevec(des_)
197+
# don't add data entries that already exist
198+
dde = listDataEntries(dst, dlbl)
199+
uids = (s->s.id).(dde)
200+
filter!(s -> !(s.id in uids), des)
201+
# add any data entries not already in the destination variable, by uuid
202+
addDataEntry!.(dst, dlbl, des)
203+
end
204+
205+
function mergeDataEntries!(
206+
dst::AbstractDFG,
207+
dlbl::Symbol,
208+
src::AbstractDFG,
209+
slbl::Symbol,
210+
::Colon=:
211+
)
212+
des = listDataEntries(src, slbl)
213+
# don't add data entries that already exist
214+
dde = listDataEntries(dst, dlbl)
215+
uids = (s->s.id).(dde)
216+
filter!(s -> !(s.id in uids), des)
217+
union(((s->mergeDataEntries!(dst, dlbl, src, slbl, s.id)).(des))...)
218+
end

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph, mergeGraph!
197197
export addDataEntry!, getDataEntry, updateDataEntry!, deleteDataEntry!, getDataEntries, listDataEntries, hasDataEntry, hasDataEntry
198198
export listDataEntrySequence
199199
# convenience wrappers
200-
export addDataEntry!
200+
export addDataEntry!, mergeDataEntries!
201201
# aliases
202202
export addData!
203203

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function deleteFactor!(dfg::GraphsDFG, label::Symbol; suppressGetFactor::Bool=fa
155155
return factor
156156
end
157157

158-
function getVariables(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)
158+
function getVariables(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0, detail=nothing)
159159

160160
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
161161
variables = collect(values(dfg.g.variables))

src/LightDFG/services/LightDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function deleteFactor!(dfg::LightDFG, label::Symbol; suppressGetFactor::Bool=fal
155155
return factor
156156
end
157157

158-
function getVariables(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)
158+
function getVariables(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0, detail=nothing)
159159

160160
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
161161
variables = collect(values(dfg.g.variables))

src/Neo4jDFG/services/Neo4jDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ end
384384
# Alias
385385
deleteFactor!(dfg::Neo4jDFG, factor::DFGFactor; suppressGetFactor::Bool=false) = deleteFactor!(dfg, factor.label, suppressGetFactor=suppressGetFactor)
386386

387-
function getVariables(dfg::Neo4jDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{DFGVariable}
387+
function getVariables(dfg::Neo4jDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0, detail=nothing)::Vector{DFGVariable}
388388
variableIds = listVariables(dfg, regexFilter, tags=tags, solvable=solvable)
389389
# TODO: Optimize to use tags in query here!
390390
variables = map(vId->getVariable(dfg, vId), variableIds)

src/services/AbstractDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ List the DFGVariables in the DFG.
295295
Optionally specify a label regular expression to retrieves a subset of the variables.
296296
Tags is a list of any tags that a node must have (at least one match).
297297
"""
298-
function getVariables(dfg::G, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0) where G <: AbstractDFG
298+
function getVariables(dfg::G, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0, detail=nothing) where G <: AbstractDFG
299299
error("getVariables not implemented for $(typeof(dfg))")
300300
end
301301

test/consol_DataEntryBlobTests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,23 @@ ade3,adb3 = updateData!(dfg, :x2, deepcopy(ade))
4545
@test ade == ade2 == ade3
4646
@test adb == adb2 == adb3
4747

48+
49+
@test :random in listDataEntries(dfg, :x2)
50+
@test length(listDataEntries(dfg, :x1)) === 0
51+
@test length(listDataEntries(dfg, :x2)) === 1
52+
53+
mergeDataEntries!(dfg, :x1, dfg, :x2, :random)
54+
55+
@test length(listDataEntries(dfg, :x1)) === 1
56+
@test :random in listDataEntries(dfg, :x1)
57+
@test length(listDataEntries(dfg, :x2)) === 1
58+
59+
deleteData!(dfg, :x1, :random)
4860
deleteData!(dfg, :x2, :random)
4961

62+
@test length(listDataEntries(dfg, :x1)) === 0
63+
@test length(listDataEntries(dfg, :x2)) === 0
64+
5065
##==============================================================================
5166
## FileDataEntry
5267
##==============================================================================

0 commit comments

Comments
 (0)