Skip to content

Commit 51906c2

Browse files
committed
update [get,list]Factors
1 parent 4ec63c5 commit 51906c2

1 file changed

Lines changed: 64 additions & 28 deletions

File tree

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,23 @@ function getVariables(
153153
# NOTE that contains(regex::Regex) is not supported by the NvaDFG.
154154
Base.depwarn(
155155
"The regex filter argument is deprecated, use kwarg `labelFilter=contains(regex)` instead", #v0.28
156-
:getVariable,
156+
:getVariables,
157157
)
158158
filterDFG!(variables, contains(regex), (String getLabel))
159159
end
160160
if !isempty(tags)
161161
# NOTE that !isdisjoint is not supported by NvaDFG.
162162
Base.depwarn(
163-
"tags kwarg is deprecated, use kwarg `tagsFilter = !isdisjoint(tags)`` instead", #v0.28
164-
:getVariable,
163+
"tags kwarg is deprecated, use kwarg `tagsFilter = !isdisjoint(tags)` instead", #v0.28
164+
:getVariables,
165165
)
166166
filterDFG!(variables, !isdisjoint(tags), getTags)
167167
end
168168
if !isnothing(solvable)
169169
#TODO review. just one solvableFilter or keep solvable as well.
170170
Base.depwarn(
171-
"solvable kwarg is deprecated, use kwarg `solvableFilter = (>=solvable)`` instead", #v0.28
172-
:getVariable,
171+
"solvable kwarg is deprecated, use kwarg `solvableFilter = (>=solvable)` instead", #v0.28
172+
:getVariables,
173173
)
174174
filterDFG!(variables, >=(solvable), getSolvable)
175175
end
@@ -221,46 +221,82 @@ end
221221

222222
function getFactors(
223223
dfg::GraphsDFG,
224-
regexFilter::Union{Nothing, Regex} = nothing;
224+
regex::Union{Nothing, Regex} = nothing;
225225
tags::Vector{Symbol} = Symbol[],
226-
solvable::Int = 0,
226+
solvable::Union{Nothing, Int} = nothing,
227+
solvableFilter::Union{Nothing, Function} = nothing,
228+
tagsFilter::Union{Nothing, Function} = nothing,
229+
typeFilter::Union{Nothing, Function} = nothing,
230+
labelFilter::Union{Nothing, Function} = nothing,
227231
)
228-
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa FactorCompute, vertices(dfg.g)))
229232
factors = collect(values(dfg.g.factors))
230-
if !isnothing(regexFilter)
231-
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
233+
if !isnothing(regex)
234+
# NOTE that contains(regex::Regex) is not supported by the NvaDFG.
235+
Base.depwarn(
236+
"The regex filter argument is deprecated, use kwarg `labelFilter=contains(regex)` instead", #v0.28
237+
:getFactors,
238+
)
239+
filterDFG!(factors, contains(regex), (String getLabel))
232240
end
233-
if solvable != 0
234-
factors = filter(f -> _isSolvable(dfg, f.label, solvable), factors)
241+
if !isempty(tags)
242+
# NOTE that !isdisjoint is not supported by NvaDFG.
243+
Base.depwarn(
244+
"tags kwarg is deprecated, use kwarg `tagsFilter = !isdisjoint(tags)` instead", #v0.28
245+
:getFactors,
246+
)
247+
filterDFG!(factors, !isdisjoint(tags), getTags)
235248
end
236-
if length(tags) > 0
237-
mask = map(v -> length(intersect(v.tags, tags)) > 0, factors)
238-
return factors[mask]
249+
if !isnothing(solvable)
250+
#TODO review. just one solvableFilter or keep solvable as well.
251+
Base.depwarn(
252+
"solvable kwarg is deprecated, use kwarg `solvableFilter = (>=solvable)` instead", #v0.28
253+
:getFactors,
254+
)
255+
filterDFG!(factors, >=(solvable), getSolvable)
239256
end
257+
258+
filterDFG!(factors, labelFilter, (String getLabel))
259+
filterDFG!(factors, solvableFilter, getSolvable)
260+
filterDFG!(factors, tagsFilter, getTags)
261+
filterDFG!(factors, typeFilter, getFactorType)
240262
return factors
241263
end
242264

243265
function listFactors(
244266
dfg::GraphsDFG,
245267
regexFilter::Union{Nothing, Regex} = nothing;
246268
tags::Vector{Symbol} = Symbol[],
247-
solvable::Int = 0,
269+
solvable::Union{Nothing, Int} = nothing,
270+
solvableFilter::Union{Nothing, Function} = nothing,
271+
tagsFilter::Union{Nothing, Function} = nothing,
272+
typeFilter::Union{Nothing, Function} = nothing,
273+
labelFilter::Union{Nothing, Function} = nothing,
248274
)
249-
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa FactorCompute, vertices(dfg.g)))
250-
if length(tags) > 0
275+
if !isnothing(solvableFilter) ||
276+
!isnothing(tagsFilter) ||
277+
!isnothing(typeFilter) ||
278+
!isnothing(regexFilter) || #TODO deprecated
279+
!isempty(tags) || #TODO deprecated
280+
!isnothing(solvable) #TODO Maybe deprecated?
251281
return map(
252-
v -> v.label,
253-
getFactors(dfg, regexFilter; tags = tags, solvable = solvable),
282+
getLabel,
283+
getFactors(
284+
dfg,
285+
regexFilter;
286+
tags,
287+
solvable,
288+
solvableFilter,
289+
tagsFilter,
290+
typeFilter,
291+
labelFilter,
292+
),
254293
)
294+
else
295+
# Is it ok to continue using the internal keys property? collect(keys(dfg.g.factors)) allowcates a lot.
296+
labels = copy(dfg.g.factors.keys)
297+
filterDFG!(labels, labelFilter, string)
298+
return labels
255299
end
256-
factors = copy(dfg.g.factors.keys)
257-
if !isnothing(regexFilter)
258-
factors = filter(f -> occursin(regexFilter, String(f)), factors)
259-
end
260-
if solvable != 0
261-
factors = filter(fId -> _isSolvable(dfg, fId, solvable), factors)
262-
end
263-
return factors::Vector{Symbol}
264300
end
265301

266302
function isConnected(dfg::GraphsDFG)

0 commit comments

Comments
 (0)