Skip to content

Commit 5b33e8f

Browse files
authored
Merge pull request #695 from JuliaRobotics/master
v0.10.11-rc1
2 parents 7f812e2 + 19179d1 commit 5b33e8f

File tree

7 files changed

+114
-67
lines changed

7 files changed

+114
-67
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.10.10"
3+
version = "0.10.11"
44

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

src/DFGPlots/DFGPlots.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module DFGPlots
22

33
using Colors
44
using LightGraphs
5-
using GraphPlot
5+
using ..GraphPlot
66
using DocStringExtensions
7-
import GraphPlot: gplot
7+
import ..GraphPlot: gplot
88

99
using ...DistributedFactorGraphs
1010

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function __init__()
317317
@warn("BREAKING CHANGE coming to DistributedFactorGraphs v0.12: deprecating AbstractRelativeFactorMinimize, use AbstractRelativeMinimize instead")
318318

319319
@require GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231" begin
320-
@info "Including Plots"
320+
@info "DistributedFactorGraphs.jl is adding tools using GraphPlot.jl"
321321
include("DFGPlots/DFGPlots.jl")
322322
@reexport using .DFGPlots
323323
end

src/services/AbstractDFG.jl

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -495,23 +495,23 @@ listVariables(dfg, r"l", tags=[:APRILTAG;])
495495
Related:
496496
- ls
497497
"""
498-
function listVariables(dfg::AbstractDFG,
499-
regexFilter::Union{Nothing, Regex}=nothing;
500-
tags::Vector{Symbol}=Symbol[],
501-
solvable::Int=0 )
502-
#
503-
vars = getVariables(dfg, regexFilter, tags=tags, solvable=solvable)
504-
return map(v -> v.label, vars)::Vector{Symbol}
498+
function listVariables( dfg::AbstractDFG,
499+
regexFilter::Union{Nothing, Regex}=nothing;
500+
tags::Vector{Symbol}=Symbol[],
501+
solvable::Int=0 )
502+
#
503+
vars = getVariables(dfg, regexFilter, tags=tags, solvable=solvable)
504+
return map(v -> v.label, vars)::Vector{Symbol}
505505
end
506506

507507
# to be consolidated, see #612
508-
function listVariables(dfg::AbstractDFG,
509-
typeFilter::Type{<:InferenceVariable};
510-
tags::Vector{Symbol}=Symbol[],
511-
solvable::Int=0 )
512-
#
513-
retlist::Vector{Symbol} = ls(dfg, typeFilter)
514-
0 < length(tags) || solvable != 0 ? intersect(retlist, ls(dfg, tags=tags, solvable=solvable)) : retlist
508+
function listVariables( dfg::AbstractDFG,
509+
typeFilter::Type{<:InferenceVariable};
510+
tags::Vector{Symbol}=Symbol[],
511+
solvable::Int=0 )
512+
#
513+
retlist::Vector{Symbol} = ls(dfg, typeFilter)
514+
0 < length(tags) || solvable != 0 ? intersect(retlist, ls(dfg, tags=tags, solvable=solvable)) : retlist
515515
end
516516

517517
"""
@@ -520,31 +520,50 @@ Get a list of the IDs (labels) of the DFGFactors in the DFG.
520520
Optionally specify a label regular expression to retrieves a subset of the factors.
521521
"""
522522
function listFactors(dfg::G, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{Symbol} where G <: AbstractDFG
523-
return map(f -> f.label, getFactors(dfg, regexFilter, tags=tags, solvable=solvable))
523+
return map(f -> f.label, getFactors(dfg, regexFilter, tags=tags, solvable=solvable))
524524
end
525525

526526
"""
527-
$SIGNATURES
527+
$TYPEDSIGNATURES
528528
List all the solvekeys used amongst all variables in the distributed factor graph object.
529529
530530
Related
531531
532-
listSupersolves, getSolverDataDict, listVariables
532+
[`listSupersolves`](@ref), [`getSolverDataDict`](@ref), [`listVariables`](@ref)
533533
"""
534-
function listSolveKeys(dfg::AbstractDFG,
535-
filterVariables::Union{Type{<:InferenceVariable},Regex, Nothing}=nothing;
536-
filterSolveKeys::Union{Regex,Nothing}=nothing,
537-
tags::Vector{Symbol}=Symbol[],
538-
solvable::Int=0 )
539-
#
540-
skeys = Set{Symbol}()
541-
varList = listVariables(dfg, filterVariables, tags=tags, solvable=solvable)
542-
for vs in varList, ky in keys(getSolverDataDict(getVariable(dfg, vs)))
534+
function listSolveKeys( variable::DFGVariable,
535+
filterSolveKeys::Union{Regex,Nothing}=nothing,
536+
skeys = Set{Symbol}() )
537+
#
538+
for ky in keys(getSolverDataDict(variable))
543539
push!(skeys, ky)
544540
end
545541

546542
#filter the solveKey set with filterSolveKeys regex
547543
!isnothing(filterSolveKeys) && return filter!(k -> occursin(filterSolveKeys, string(k)), skeys)
544+
return skeys
545+
end
546+
547+
listSolveKeys( dfg::AbstractDFG, lbl::Symbol,
548+
filterSolveKeys::Union{Regex,Nothing}=nothing,
549+
skeys = Set{Symbol}() ) = listSolveKeys(getVariable(dfg, lbl), filterSolveKeys, skeys)
550+
#
551+
552+
function listSolveKeys( dfg::AbstractDFG,
553+
filterVariables::Union{Type{<:InferenceVariable},Regex, Nothing}=nothing;
554+
filterSolveKeys::Union{Regex,Nothing}=nothing,
555+
tags::Vector{Symbol}=Symbol[],
556+
solvable::Int=0 )
557+
#
558+
skeys = Set{Symbol}()
559+
varList = listVariables(dfg, filterVariables, tags=tags, solvable=solvable)
560+
for vs in varList #, ky in keys(getSolverDataDict(getVariable(dfg, vs)))
561+
listSolveKeys(dfg, vs, filterSolveKeys, skeys)
562+
end
563+
564+
# done inside the loop
565+
# #filter the solveKey set with filterSolveKeys regex
566+
# !isnothing(filterSolveKeys) && return filter!(k -> occursin(filterSolveKeys, string(k)), skeys)
548567

549568
return skeys
550569
end

src/services/CustomPrinting.jl

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,44 @@
44

55
printVariable(vert::DFGVariable; kwargs...) = printVariable(stdout::IO, vert; kwargs...)
66

7-
function printVariable(io::IO, vert::DFGVariable;
8-
short::Bool=false,
9-
compact::Bool=true,
10-
limit::Bool=true,
11-
skipfields::Vector{Symbol}=Symbol[],
12-
solveKeys::Vector{Symbol}=Symbol[])
7+
function printVariable( io::IO, vert::DFGVariable;
8+
short::Bool=false,
9+
compact::Bool=true,
10+
limit::Bool=true,
11+
skipfields::Vector{Symbol}=Symbol[],
12+
solveKeys::Vector{Symbol}=Symbol[])
1313

1414
ioc = IOContext(io, :limit=>limit, :compact=>compact)
1515

1616
if short
17-
printstyled(ioc, summary(vert),"\n", bold=true)
17+
# opmemt = (getSofttype(vert) |> typeof ).name
18+
vari = getSofttype(vert) |> typeof
19+
printstyled(ioc, typeof(vert).name, "{",vari.name,"...}","\n", bold=true)
20+
# printstyled(ioc, summary(vert),"\n", bold=true)
21+
1822
vnd = getSolverData(vert)
19-
println(ioc, "label: $(vert.label)")
20-
println(ioc, "tags: $(getTags(vert))")
21-
println(ioc, "size marginal samples: $(size(vnd.val))")
22-
println(ioc, "kde bandwidths: $((vnd.bw)[:,1])")
23+
println(ioc, " timestamp: ", vert.timestamp)
24+
println(ioc, " label: ", vert.label)
25+
println(ioc, " solvable: ", getSolvable(vert))
26+
println(ioc, " tags: ", getTags(vert))
27+
try
28+
println(ioc, " manifold: ", getManifolds(vert))
29+
catch e
30+
end
31+
solk = listSolveKeys(vert) |> collect
32+
lsolk = length(solk)
33+
smsk = (rand(1:lsolk,100) |> unique)[1:minimum([4,lsolk])]
34+
println(ioc, " Nr SolveKeys=$(lsolk): ", solk[smsk], 4<lsolk ? "..." : "")
35+
printstyled(ioc, " :default", "\n", bold=true)
36+
println(ioc, " size marginal samples: ", size(vnd.val))
37+
println(ioc, " kde bandwidths: ", round.((vnd.bw)[:,1], digits=4))
2338
if 0 < length(getPPEDict(vert))
24-
println(ioc, "PPE.suggested: $(round.(getPPE(vert).suggested,digits=4))")
39+
println(ioc, " PPE.suggested: ", round.(getPPE(vert).suggested,digits=4) )
2540
else
26-
println(ioc, "No PPEs")
41+
println(ioc, " No PPEs yet")
2742
end
43+
printstyled(ioc, " TYPE: ", bold=true, color=:blue)
44+
println(ioc, vari)
2845
# println(ioc, "kde max: $(round.(getKDEMax(getKDE(vnd)),digits=4))")
2946
# println(ioc, "kde max: $(round.(getKDEMax(getKDE(vnd)),digits=4))")
3047
else
@@ -47,11 +64,11 @@ function printVariable(io::IO, vert::DFGVariable;
4764
end
4865

4966
printFactor(vert::DFGFactor; kwargs...) = printFactor(stdout::IO, vert; kwargs...)
50-
function printFactor(io::IO, vert::DFGFactor;
51-
short::Bool=false,
52-
compact::Bool=true,
53-
limit::Bool=true,
54-
skipfields::Vector{Symbol}=Symbol[])
67+
function printFactor( io::IO, vert::DFGFactor;
68+
short::Bool=false,
69+
compact::Bool=true,
70+
limit::Bool=true,
71+
skipfields::Vector{Symbol}=Symbol[])
5572

5673
ioc = IOContext(io, :limit=>limit, :compact=>compact)
5774

@@ -60,15 +77,16 @@ function printFactor(io::IO, vert::DFGFactor;
6077
fct = getFactorType(vert)
6178
fctt = fct |> typeof
6279
printstyled(ioc, typeof(vert).name, "{",opmemt,"{",fctt.name,"...}}","\n", bold=true)
80+
println(ioc, " timestamp: ", vert.timestamp)
81+
println(ioc, " nstime: ",vert.nstime)
6382
println(ioc, " label: ", vert.label)
6483
println(ioc, " solvable: ", vert.solvable)
6584
println(ioc, " VariableOrder: ", vert._variableOrderSymbols)
6685
println(ioc, " multihypo: ", getSolverData(vert).multihypo) # FIXME #477
6786
println(ioc, " nullhypo: ", getSolverData(vert).nullhypo)
68-
println(ioc, " timestamp: ", vert.timestamp)
69-
println(ioc, " nstime: ",vert.nstime)
7087
println(ioc, " tags: ", vert.tags)
71-
println(ioc, " TYPE: ", fctt)
88+
printstyled(ioc, " TYPE: ", bold=true, color=:blue)
89+
println(ioc, fctt)
7290
# show(ioc, fctt)
7391
for f in setdiff(fieldnames(fctt), skipfields)
7492
printstyled(ioc, f,":\n", color=:blue)
@@ -118,7 +136,7 @@ printNode(dfg::AbstractDFG, sym::Symbol; kwargs...) = isVariable(dfg,sym) ? prin
118136
## Overloading show
119137
##==============================================================================
120138
# Base.show_default(io, v)
121-
Base.show(io::IO, ::MIME"text/plain", v::DFGVariable) = show(IOContext(io, :limit=>true, :compact=>true), v)
139+
Base.show(io::IO, ::MIME"text/plain", v::DFGVariable) = printVariable(io, v, short=true, limit=false)
122140

123141
Base.show(io::IO, ::MIME"text/plain", f::DFGFactor) = printFactor(io, f, short=true, limit=false)
124142

test/interfaceTests.jl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,27 @@ end
5959

6060
iobuf = IOBuffer()
6161
# for now just test the interface and a bit of output
62-
@test printVariable(var1) == nothing
63-
@test printFactor(fac1) == nothing
62+
@test printVariable(var1) === nothing
63+
@test printFactor(fac1) === nothing
6464

65-
@test printVariable(iobuf, var1, skipfields=[:timestamp, :solver, :ppe, :nstime]) == nothing
65+
@test printVariable(iobuf, var1, skipfields=[:timestamp, :solver, :ppe, :nstime]) === nothing
6666
@test String(take!(iobuf)) == "DFGVariable{TestSofttype1}\nlabel:\n:a\ntags:\nSet([:VARIABLE, :POSE])\nsmallData:\nDict{Symbol,Union{Bool, Float64, Int64, Array{Bool,1}, Array{Float64,1}, Array{Int64,1}, Array{String,1}, String}}(:small=>\"data\")\ndataDict:\nDict{Symbol,AbstractDataEntry}()\nsolvable:\n0\n"
6767

68-
@test printVariable(iobuf, var1, short=true) == nothing
69-
@test String(take!(iobuf)) == "DFGVariable{TestSofttype1}\nlabel: a\ntags: Set([:VARIABLE, :POSE])\nsize marginal samples: (1, 1)\nkde bandwidths: [0.0]\nNo PPEs\n"
68+
@test printVariable(iobuf, var1, short=true) === nothing
69+
varstr = String(take!(iobuf))
70+
@test occursin(r"DFGVariable", varstr)
71+
@test occursin(r"timestamp", varstr)
72+
@test occursin(r"label", varstr)
73+
@test occursin(r"bandwidths", varstr)
74+
# == "DFGVariable{TestSofttype1}\nlabel: a\ntags: Set([:VARIABLE, :POSE])\nsize marginal samples: (1, 1)\nkde bandwidths: [0.0]\nNo PPEs\n"
7075

7176

72-
@test printFactor(iobuf, fac1, skipfields=[:timestamp, :solver, :nstime]) == nothing
77+
@test printFactor(iobuf, fac1, skipfields=[:timestamp, :solver, :nstime]) === nothing
7378
@test occursin(r"DFGFactor.*\nlabel:\n:abf1", String(take!(iobuf)))
7479

7580
String(take!(iobuf)) == "DFGFactor{TestCCW{TestFunctorInferenceType1}}\nlabel:\n:abf1\ntags:\nSet([:tag1, :tag2])\nsolvable:\n0\nsolvable:\n1\n_variableOrderSymbols:\n[:a, :b]\n"
7681

77-
@test printFactor(iobuf, fac1, short=true) == nothing
82+
@test printFactor(iobuf, fac1, short=true) === nothing
7883
@show teststr = String(take!(iobuf))
7984
@test occursin(r"DFGFactor", teststr)
8085
@test occursin(r"label", teststr)
@@ -84,19 +89,19 @@ end
8489

8590
# s = String(take!(iobuf))
8691

87-
@test show(var1) == nothing
88-
@test show(fac1) == nothing
92+
@test show(var1) === nothing
93+
@test show(fac1) === nothing
8994

90-
@test show(iobuf, MIME("text/plain"), var1) == nothing
95+
@test show(iobuf, MIME("text/plain"), var1) === nothing
9196
isapprox(length(take!(iobuf)), 452, atol=10)
92-
@test show(iobuf, MIME("text/plain"), fac1) == nothing
97+
@test show(iobuf, MIME("text/plain"), fac1) === nothing
9398
isapprox(length(take!(iobuf)), 301, atol=10)
9499

95-
@test printVariable(fg1, :a) == nothing
96-
@test printFactor(fg1, :abf1) == nothing
100+
@test printVariable(fg1, :a) === nothing
101+
@test printFactor(fg1, :abf1) === nothing
97102

98-
@test printNode(fg1, :a) == nothing
99-
@test printNode(fg1, :abf1) == nothing
103+
@test printNode(fg1, :a) === nothing
104+
@test printNode(fg1, :abf1) === nothing
100105

101106
show(stdout, MIME("application/prs.juno.inline"), var1) == var1
102107
show(stdout, MIME("application/prs.juno.inline"), fac1) == fac1

test/testBlocks.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,18 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2)
397397
@test addVariable!(fg, v1) == v1
398398
@test addVariable!(fg, v2) == v2
399399

400+
# test getindex
401+
@test getLabel(fg[getLabel(v1)]) == getLabel(v1)
402+
400403
#TODO standardize this error and res also for that matter
401404
@test_throws Exception addFactor!(fg, [:a, :nope], f1)
402405
@test_throws Exception addFactor!(fg, [v1, v2, v3], f1)
403406

404407
@test addFactor!(fg, [v1, v2], f1) == f1
405408
@test_throws ErrorException addFactor!(fg, [v1, v2], f1)
406409

410+
@test getLabel(fg[getLabel(f1)]) == getLabel(f1)
411+
407412
@test @test_logs (:warn, Regex("'$(v3.label)' does not exist")) match_mode=:any updateVariable!(fg, v3) == v3
408413
@test updateVariable!(fg, v3) == v3
409414
@test_throws ErrorException addVariable!(fg, v3)

0 commit comments

Comments
 (0)