@@ -194,14 +194,14 @@ end
194
194
List the DFGVariables in the DFG.
195
195
Optionally specify a label regular expression to retrieves a subset of the variables.
196
196
"""
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}
198
198
199
199
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
200
200
variables = collect (values (dfg. g. variables))
201
201
if regexFilter != nothing
202
202
variables = filter (v -> occursin (regexFilter, String (v. label)), variables)
203
203
end
204
- if solvable != nothing
204
+ if solvable != 0
205
205
variables = filter (v -> _isSolvable (dfg, v. label, solvable), variables)
206
206
end
207
207
if length (tags) > 0
@@ -226,15 +226,15 @@ Related
226
226
ls
227
227
"""
228
228
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}
230
230
231
231
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
232
232
if length (tags) > 0
233
233
return map (v -> v. label, getVariables (dfg, regexFilter, tags= tags, solvable= solvable))
234
234
else
235
235
variables = collect (keys (dfg. g. variables))
236
236
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))
238
238
return variables
239
239
end
240
240
end
@@ -244,13 +244,13 @@ end
244
244
List the DFGFactors in the DFG.
245
245
Optionally specify a label regular expression to retrieves a subset of the factors.
246
246
"""
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}
248
248
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
249
249
factors = collect (values (dfg. g. factors))
250
250
if regexFilter != nothing
251
251
factors = filter (f -> occursin (regexFilter, String (f. label)), factors)
252
252
end
253
- if solvable != nothing
253
+ if solvable != 0
254
254
factors = filter (f -> _isSolvable (dfg, f. label, solvable), factors)
255
255
end
256
256
return factors
@@ -261,13 +261,13 @@ end
261
261
Get a list of the IDs of the DFGFactors in the DFG.
262
262
Optionally specify a label regular expression to retrieves a subset of the factors.
263
263
"""
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}
265
265
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
266
266
factors = collect (keys (dfg. g. factors))
267
267
if regexFilter != nothing
268
268
factors = filter (f -> occursin (regexFilter, String (f)), factors)
269
269
end
270
- if solvable != nothing
270
+ if solvable != 0
271
271
factors = filter (fId -> _isSolvable (dfg, fId, solvable), factors)
272
272
end
273
273
return factors
304
304
$(SIGNATURES)
305
305
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
306
306
"""
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}
308
308
label = node. label
309
309
if ! exists (dfg, label)
310
310
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
313
313
neighbors_il = FactorGraphs. outneighbors (dfg. g, dfg. g. labels[label])
314
314
neighbors_ll = [dfg. g. labels[i] for i in neighbors_il]
315
315
# Additional filtering
316
- solvable != nothing && filter! (lbl -> _isSolvable (dfg, lbl, solvable), neighbors_ll)
316
+ solvable != 0 && filter! (lbl -> _isSolvable (dfg, lbl, solvable), neighbors_ll)
317
317
backendset != nothing && filter! (lbl -> _isbackendset (dfg, lbl, backendset), neighbors_ll)
318
318
319
319
# Variable sorting (order is important)
@@ -330,15 +330,15 @@ end
330
330
$(SIGNATURES)
331
331
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
332
332
"""
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}
334
334
if ! exists (dfg, label)
335
335
error (" Variable/factor with label '$(label) ' does not exist in the factor graph" )
336
336
end
337
337
338
338
neighbors_il = FactorGraphs. outneighbors (dfg. g, dfg. g. labels[label])
339
339
neighbors_ll = [dfg. g. labels[i] for i in neighbors_il]
340
340
# Additional filtering
341
- solvable != nothing && filter! (lbl -> _isSolvable (dfg, lbl, solvable), neighbors_ll)
341
+ solvable != 0 && filter! (lbl -> _isSolvable (dfg, lbl, solvable), neighbors_ll)
342
342
backendset != nothing && filter! (lbl -> _isbackendset (dfg, lbl, backendset), neighbors_ll)
343
343
344
344
# Variable sorting (order is important)
@@ -436,10 +436,10 @@ Get an adjacency matrix for the DFG, returned as a Matrix{Union{Nothing, Symbol}
436
436
Rows are all factors, columns are all variables, and each cell contains either nothing or the symbol of the relating factor.
437
437
The first row and first column are factor and variable headings respectively.
438
438
"""
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}}
440
440
# 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)))
443
443
vDict = Dict (varLabels .=> [1 : length (varLabels)... ]. + 1 )
444
444
445
445
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
453
453
return adjMat
454
454
end
455
455
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)
459
459
varIndex = [dfg. g. labels[s] for s in varLabels]
460
460
factIndex = [dfg. g. labels[s] for s in factLabels]
461
461
0 commit comments