Skip to content

Commit 88883d8

Browse files
committed
Cleanup and additional testing. Need to merge v051 cleanup before reenabling the CGDFG test
1 parent 9e181a9 commit 88883d8

File tree

5 files changed

+76
-58
lines changed

5 files changed

+76
-58
lines changed

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ Optionally specify a label regular expression to retrieves a subset of the varia
238238
function getVariables(dfg::GraphsDFG,
239239
regexFilter::Union{Nothing, Regex}=nothing;
240240
tags::Vector{Symbol}=Symbol[],
241-
solvable::Union{Nothing, Int}=nothing)::Vector{DFGVariable}
241+
solvable::Int=0)::Vector{DFGVariable}
242242
#
243-
variables = map(v -> v.dfgNode, filter(n -> (n.dfgNode isa DFGVariable) && (solvable != nothing ? solvable <= isSolvable(n.dfgNode) : true), Graphs.vertices(dfg.g)))
243+
variables = map(v -> v.dfgNode, filter(n -> (n.dfgNode isa DFGVariable) && (solvable != 0 ? solvable <= isSolvable(n.dfgNode) : true), Graphs.vertices(dfg.g)))
244244
# filter on solvable
245245

246246
# filter on regex
@@ -261,8 +261,8 @@ end
261261
List the DFGFactors in the DFG.
262262
Optionally specify a label regular expression to retrieves a subset of the factors.
263263
"""
264-
function getFactors(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Union{Nothing, Int}=nothing)::Vector{DFGFactor}
265-
factors = map(v -> v.dfgNode, filter(n -> (n.dfgNode isa DFGFactor) && (solvable != nothing ? solvable <= isSolvable(n.dfgNode) : true), Graphs.vertices(dfg.g)))
264+
function getFactors(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{DFGFactor}
265+
factors = map(v -> v.dfgNode, filter(n -> (n.dfgNode isa DFGFactor) && (solvable != 0 ? solvable <= isSolvable(n.dfgNode) : true), Graphs.vertices(dfg.g)))
266266

267267
if regexFilter != nothing
268268
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
@@ -282,14 +282,14 @@ end
282282
$(SIGNATURES)
283283
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
284284
"""
285-
function getNeighbors(dfg::GraphsDFG, node::T; solvable::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
285+
function getNeighbors(dfg::GraphsDFG, node::T; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
286286
if !haskey(dfg.labelDict, node.label)
287287
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
288288
end
289289
vert = dfg.g.vertices[dfg.labelDict[node.label]]
290290
neighbors = in_neighbors(vert, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
291291
# Additional filtering
292-
neighbors = solvable != nothing ? filter(v -> solvable <= isSolvable(v.dfgNode), neighbors) : neighbors
292+
neighbors = solvable != 0 ? filter(v -> solvable <= isSolvable(v.dfgNode), neighbors) : neighbors
293293
neighbors = backendset != nothing ? filter(v -> isSolveInProgress(v.dfgNode) == backendset, neighbors) : neighbors
294294
# Variable sorting (order is important)
295295
if node isa DFGFactor
@@ -303,14 +303,14 @@ end
303303
$(SIGNATURES)
304304
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
305305
"""
306-
function getNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
306+
function getNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
307307
if !haskey(dfg.labelDict, label)
308308
error("Variable/factor with label '$(label)' does not exist in the factor graph")
309309
end
310310
vert = dfg.g.vertices[dfg.labelDict[label]]
311311
neighbors = in_neighbors(vert, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
312312
# Additional filtering
313-
neighbors = solvable != nothing ? filter(v -> isSolvable(v.dfgNode) >= solvable, neighbors) : neighbors
313+
neighbors = solvable != 0 ? filter(v -> isSolvable(v.dfgNode) >= solvable, neighbors) : neighbors
314314
neighbors = backendset != nothing ? filter(v -> isSolveInProgress(v.dfgNode) == backendset, neighbors) : neighbors
315315
# Variable sorting when using a factor (function order is important)
316316
if vert.dfgNode isa DFGFactor

src/LightDFG/services/LightDFG.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ end
194194
List the DFGVariables in the DFG.
195195
Optionally specify a label regular expression to retrieves a subset of the variables.
196196
"""
197-
function getVariables(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Union{Nothing, Int}=nothing)::Vector{AbstractDFGVariable}
197+
function getVariables(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{AbstractDFGVariable}
198198

199199
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
200200
variables = collect(values(dfg.g.variables))
201201
if regexFilter != nothing
202202
variables = filter(v -> occursin(regexFilter, String(v.label)), variables)
203203
end
204-
if solvable != nothing
204+
if solvable != 0
205205
variables = filter(v -> _isSolvable(dfg, v.label, solvable), variables)
206206
end
207207
if length(tags) > 0
@@ -226,15 +226,15 @@ Related
226226
ls
227227
"""
228228

229-
function getVariableIds(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Union{Nothing, Int}=nothing)::Vector{Symbol}
229+
function getVariableIds(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{Symbol}
230230

231231
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
232232
if length(tags) > 0
233233
return map(v -> v.label, getVariables(dfg, regexFilter, tags=tags, solvable=solvable))
234234
else
235235
variables = collect(keys(dfg.g.variables))
236236
regexFilter != nothing && (variables = filter(v -> occursin(regexFilter, String(v)), variables))
237-
solvable != nothing && (variables = filter(vId -> _isSolvable(dfg, vId, solvable), variables))
237+
solvable != 0 && (variables = filter(vId -> _isSolvable(dfg, vId, solvable), variables))
238238
return variables
239239
end
240240
end
@@ -244,13 +244,13 @@ end
244244
List the DFGFactors in the DFG.
245245
Optionally specify a label regular expression to retrieves a subset of the factors.
246246
"""
247-
function getFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Union{Nothing, Int}=nothing)::Vector{AbstractDFGFactor}
247+
function getFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{AbstractDFGFactor}
248248
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
249249
factors = collect(values(dfg.g.factors))
250250
if regexFilter != nothing
251251
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
252252
end
253-
if solvable != nothing
253+
if solvable != 0
254254
factors = filter(f -> _isSolvable(dfg, f.label, solvable), factors)
255255
end
256256
return factors
@@ -261,13 +261,13 @@ end
261261
Get a list of the IDs of the DFGFactors in the DFG.
262262
Optionally specify a label regular expression to retrieves a subset of the factors.
263263
"""
264-
function getFactorIds(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Union{Nothing, Int}=nothing)::Vector{Symbol}
264+
function getFactorIds(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{Symbol}
265265
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
266266
factors = collect(keys(dfg.g.factors))
267267
if regexFilter != nothing
268268
factors = filter(f -> occursin(regexFilter, String(f)), factors)
269269
end
270-
if solvable != nothing
270+
if solvable != 0
271271
factors = filter(fId -> _isSolvable(dfg, fId, solvable), factors)
272272
end
273273
return factors
@@ -304,7 +304,7 @@ end
304304
$(SIGNATURES)
305305
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
306306
"""
307-
function getNeighbors(dfg::LightDFG, node::DFGNode; solvable::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
307+
function getNeighbors(dfg::LightDFG, node::DFGNode; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
308308
label = node.label
309309
if !exists(dfg, label)
310310
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
@@ -313,7 +313,7 @@ function getNeighbors(dfg::LightDFG, node::DFGNode; solvable::Union{Nothing, Int
313313
neighbors_il = FactorGraphs.outneighbors(dfg.g, dfg.g.labels[label])
314314
neighbors_ll = [dfg.g.labels[i] for i in neighbors_il]
315315
# Additional filtering
316-
solvable != nothing && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
316+
solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
317317
backendset != nothing && filter!(lbl -> _isbackendset(dfg, lbl, backendset), neighbors_ll)
318318

319319
# Variable sorting (order is important)
@@ -330,15 +330,15 @@ end
330330
$(SIGNATURES)
331331
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
332332
"""
333-
function getNeighbors(dfg::LightDFG, label::Symbol; solvable::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
333+
function getNeighbors(dfg::LightDFG, label::Symbol; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
334334
if !exists(dfg, label)
335335
error("Variable/factor with label '$(label)' does not exist in the factor graph")
336336
end
337337

338338
neighbors_il = FactorGraphs.outneighbors(dfg.g, dfg.g.labels[label])
339339
neighbors_ll = [dfg.g.labels[i] for i in neighbors_il]
340340
# Additional filtering
341-
solvable != nothing && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
341+
solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
342342
backendset != nothing && filter!(lbl -> _isbackendset(dfg, lbl, backendset), neighbors_ll)
343343

344344
# Variable sorting (order is important)
@@ -436,10 +436,10 @@ Get an adjacency matrix for the DFG, returned as a Matrix{Union{Nothing, Symbol}
436436
Rows are all factors, columns are all variables, and each cell contains either nothing or the symbol of the relating factor.
437437
The first row and first column are factor and variable headings respectively.
438438
"""
439-
function getAdjacencyMatrix(dfg::LightDFG; solvable::Union{Nothing, Int}=nothing)::Matrix{Union{Nothing, Symbol}}
439+
function getAdjacencyMatrix(dfg::LightDFG; solvable::Int=0)::Matrix{Union{Nothing, Symbol}}
440440
#TODO Why does it need to be sorted?
441-
varLabels = sort(collect(getVariableIds(dfg, solvable=solvable)))#ort(map(v->v.label, getVariables(dfg)))
442-
factLabels = sort(collect(getFactorIds(dfg, solvable=solvable)))#sort(map(f->f.label, getFactors(dfg)))
441+
varLabels = sort(getVariableIds(dfg, solvable=solvable))#ort(map(v->v.label, getVariables(dfg)))
442+
factLabels = sort(getFactorIds(dfg, solvable=solvable))#sort(map(f->f.label, getFactors(dfg)))
443443
vDict = Dict(varLabels .=> [1:length(varLabels)...].+1)
444444

445445
adjMat = Matrix{Union{Nothing, Symbol}}(nothing, length(factLabels)+1, length(varLabels)+1)
@@ -453,9 +453,9 @@ function getAdjacencyMatrix(dfg::LightDFG; solvable::Union{Nothing, Int}=nothing
453453
return adjMat
454454
end
455455

456-
function getAdjacencyMatrixSparse(dfg::LightDFG; solvable::Union{Nothing, Int}=nothing)::Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
457-
varLabels = collect(getVariableIds(dfg, solvable=solvable))
458-
factLabels = collect(getFactorIds(dfg, solvable=solvable))
456+
function getAdjacencyMatrixSparse(dfg::LightDFG; solvable::Int=0)::Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
457+
varLabels = getVariableIds(dfg, solvable=solvable)
458+
factLabels = getFactorIds(dfg, solvable=solvable)
459459
varIndex = [dfg.g.labels[s] for s in varLabels]
460460
factIndex = [dfg.g.labels[s] for s in factLabels]
461461

src/SymbolDFG/services/SymbolDFG.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ deleteFactor!(dfg::SymbolDFG, factor::DFGFactor)::DFGFactor = deleteFactor!(dfg,
183183
List the DFGVariables in the DFG.
184184
Optionally specify a label regular expression to retrieves a subset of the variables.
185185
"""
186-
function getVariables(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Union{Nothing, Int}=nothing)::Vector{DFGVariable}
186+
function getVariables(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{DFGVariable}
187187

188188
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
189189
variables = collect(values(dfg.g.variables))
190190
if regexFilter != nothing
191191
variables = filter(v -> occursin(regexFilter, String(v.label)), variables)
192192
end
193-
if solvable != nothing
193+
if solvable != 0
194194
variables = filter(v -> _isSolvable(dfg, v.label, solvable), variables)
195195
end
196196
if length(tags) > 0
@@ -214,28 +214,28 @@ Related
214214
215215
ls
216216
"""
217-
getVariableIds(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Union{Nothing, Int}=nothing)::Vector{Symbol} = map(v -> v.label, getVariables(dfg, regexFilter, tags=tags, solvable=solvable))
217+
getVariableIds(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{Symbol} = map(v -> v.label, getVariables(dfg, regexFilter, tags=tags, solvable=solvable))
218218

219219
# Alias
220220
"""
221221
$(SIGNATURES)
222222
List the DFGVariables in the DFG.
223223
Optionally specify a label regular expression to retrieves a subset of the variables.
224224
"""
225-
ls(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Union{Nothing, Int}=nothing)::Vector{Symbol} = getVariableIds(dfg, regexFilter, tags=tags, solvable=solvable)
225+
ls(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{Symbol} = getVariableIds(dfg, regexFilter, tags=tags, solvable=solvable)
226226

227227
"""
228228
$(SIGNATURES)
229229
List the DFGFactors in the DFG.
230230
Optionally specify a label regular expression to retrieves a subset of the factors.
231231
"""
232-
function getFactors(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Union{Nothing, Int}=nothing)::Vector{DFGFactor}
232+
function getFactors(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{DFGFactor}
233233
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
234234
factors = collect(values(dfg.g.factors))
235235
if regexFilter != nothing
236236
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
237237
end
238-
if solvable != nothing
238+
if solvable != 0
239239
factors = filter(f -> _isSolvable(dfg, f.label, solvable), factors)
240240
end
241241
return factors
@@ -246,7 +246,7 @@ end
246246
Get a list of the IDs of the DFGFactors in the DFG.
247247
Optionally specify a label regular expression to retrieves a subset of the factors.
248248
"""
249-
getFactorIds(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Union{Nothing, Int}=nothing)::Vector{Symbol} = map(f -> f.label, getFactors(dfg, regexFilter, solvable=solvable))
249+
getFactorIds(dfg::SymbolDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{Symbol} = map(f -> f.label, getFactors(dfg, regexFilter, solvable=solvable))
250250

251251
"""
252252
$(SIGNATURES)
@@ -286,15 +286,15 @@ end
286286
$(SIGNATURES)
287287
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
288288
"""
289-
function getNeighbors(dfg::SymbolDFG, node::DFGNode; solvable::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
289+
function getNeighbors(dfg::SymbolDFG, node::DFGNode; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
290290
label = node.label
291291
if !haskey(dfg.g.fadjdict, label)
292292
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
293293
end
294294

295295
neighbors_ll = copy(outneighbors(dfg.g, label))
296296
# Additional filtering
297-
solvable != nothing && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
297+
solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
298298
backendset != nothing && filter!(lbl -> _isbackendset(dfg, lbl, backendset), neighbors_ll)
299299

300300
# Variable sorting (order is important)
@@ -311,14 +311,14 @@ end
311311
$(SIGNATURES)
312312
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
313313
"""
314-
function getNeighbors(dfg::SymbolDFG, label::Symbol; solvable::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
314+
function getNeighbors(dfg::SymbolDFG, label::Symbol; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
315315
if !haskey(dfg.g.fadjdict, label)
316316
error("Variable/factor with label '$(label)' does not exist in the factor graph")
317317
end
318318

319319
neighbors_ll = copy(outneighbors(dfg.g, label))
320320
# Additional filtering
321-
solvable != nothing && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
321+
solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
322322
backendset != nothing && filter!(lbl -> _isbackendset(dfg, lbl, backendset), neighbors_ll)
323323

324324
# Variable sorting (order is important)
@@ -428,7 +428,7 @@ Get an adjacency matrix for the DFG, returned as a Matrix{Union{Nothing, Symbol}
428428
Rows are all factors, columns are all variables, and each cell contains either nothing or the symbol of the relating factor.
429429
The first row and first column are factor and variable headings respectively.
430430
"""
431-
function getAdjacencyMatrix(dfg::SymbolDFG; solvable::Union{Nothing, Int}=nothing)::Matrix{Union{Nothing, Symbol}}
431+
function getAdjacencyMatrix(dfg::SymbolDFG; solvable::Int=0)::Matrix{Union{Nothing, Symbol}}
432432
varLabels = map(v->v.label, getVariables(dfg, solvable=solvable))
433433
factLabels = map(f->f.label, getFactors(dfg, solvable=solvable))
434434
vDict = Dict(varLabels .=> [1:length(varLabels)...].+1)
@@ -445,7 +445,7 @@ function getAdjacencyMatrix(dfg::SymbolDFG; solvable::Union{Nothing, Int}=nothin
445445
end
446446

447447

448-
function getAdjacencyMatrixSparse(dfg::SymbolDFG; solvable::Union{Nothing, Int}=nothing)::Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
448+
function getAdjacencyMatrixSparse(dfg::SymbolDFG; solvable::Int=0)::Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
449449
varLabels = getVariableIds(dfg, solvable=solvable)
450450
factLabels = getFactorIds(dfg, solvable=solvable)
451451

0 commit comments

Comments
 (0)