Skip to content

Commit fb7d8a8

Browse files
authored
Fix force return types Vector{Symbol} (#1103)
1 parent 1db77c8 commit fb7d8a8

File tree

3 files changed

+13
-30
lines changed

3 files changed

+13
-30
lines changed

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function listVariables(
228228
return map(
229229
v -> v.label,
230230
getVariables(dfg, regexFilter; tags = tags, solvable = solvable),
231-
)
231+
)::Vector{Symbol}
232232
else
233233
variables = copy(dfg.g.variables.keys)
234234
!isnothing(regexFilter) && filter!(v -> occursin(regexFilter, String(v)), variables)
@@ -247,7 +247,7 @@ function getFactors(
247247
)
248248
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
249249
factors = collect(values(dfg.g.factors))
250-
if regexFilter != nothing
250+
if !isnothing(regexFilter)
251251
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
252252
end
253253
if solvable != 0
@@ -274,7 +274,7 @@ function listFactors(
274274
)
275275
end
276276
factors = copy(dfg.g.factors.keys)
277-
if regexFilter != nothing
277+
if !isnothing(regexFilter)
278278
factors = filter(f -> occursin(regexFilter, String(f)), factors)
279279
end
280280
if solvable != 0
@@ -298,25 +298,7 @@ function _isSolvable(dfg::GraphsDFG, label::Symbol, ready::Int)
298298
end
299299

300300
function listNeighbors(dfg::GraphsDFG, node::DFGNode; solvable::Int = 0)
301-
label = node.label
302-
if !exists(dfg, label)
303-
error(
304-
"Variable/factor with label '$(node.label)' does not exist in the factor graph",
305-
)
306-
end
307-
308-
neighbors_il = FactorGraphs.outneighbors(dfg.g, dfg.g.labels[label])
309-
neighbors_ll = [dfg.g.labels[i] for i in neighbors_il]
310-
# Additional filtering
311-
solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
312-
313-
# Variable sorting (order is important)
314-
if typeof(node) <: AbstractDFGFactor
315-
order = intersect(node._variableOrderSymbols, neighbors_ll)#map(v->v.dfgNode.label, neighbors))
316-
return order
317-
end
318-
319-
return neighbors_ll::Vector{Symbol}
301+
return listNeighbors(dfg, node.label; solvable)
320302
end
321303

322304
function listNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int = 0)
@@ -332,10 +314,10 @@ function listNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int = 0)
332314
# Variable sorting (order is important)
333315
if haskey(dfg.g.factors, label)
334316
order = intersect(dfg.g.factors[label]._variableOrderSymbols, neighbors_ll)#map(v->v.dfgNode.label, neighbors))
335-
return order
317+
return order::Vector{Symbol}
336318
end
337319

338-
return neighbors_ll
320+
return neighbors_ll::Vector{Symbol}
339321
end
340322

341323
function getNeighborhood(

src/services/AbstractDFG.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,15 @@ Get a list of the labels of the DFGFactors in the DFG.
583583
Optionally specify a label regular expression to retrieves a subset of the factors.
584584
"""
585585
function listFactors(
586-
dfg::G,
586+
dfg::AbstractDFG,
587587
regexFilter::Union{Nothing, Regex} = nothing;
588588
tags::Vector{Symbol} = Symbol[],
589589
solvable::Int = 0,
590-
) where {G <: AbstractDFG}
591-
return map(f -> f.label, getFactors(dfg, regexFilter; tags = tags, solvable = solvable))
590+
)
591+
return map(
592+
f -> f.label,
593+
getFactors(dfg, regexFilter; tags = tags, solvable = solvable),
594+
)::Vector{Symbol}
592595
end
593596

594597
"""

src/services/CustomPrinting.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function Base.show(io::IO, ::MIME"text/plain", f::DFGFactor)
207207
return printFactor(io, f; short = true, limit = false)
208208
end
209209

210-
function Base.show(io::IO, dfg::AbstractDFG)
210+
function Base.show(io::IO, ::MIME"text/plain", dfg::AbstractDFG)
211211
summary(io, dfg)
212212
println(io, " AgentLabel: ", getAgentLabel(dfg))
213213
println(io, " FactorgraphLabel: ", getGraphLabel(dfg))
@@ -219,8 +219,6 @@ function Base.show(io::IO, dfg::AbstractDFG)
219219
return
220220
end
221221

222-
Base.show(io::IO, ::MIME"text/plain", dfg::AbstractDFG) = show(io, dfg)
223-
224222
#default for Atom/Juno
225223
function Base.show(
226224
io::IO,

0 commit comments

Comments
 (0)