@@ -128,25 +128,56 @@ function deleteFactor!(dfg::GraphsDFG, label::Symbol; suppressGetFactor::Bool =
128128 return 1
129129end
130130
131+ # """
132+ # tagsFilter = ⊇([:x1])
133+ # tagsFilter([:x1, :x2])
134+ # true
135+ # tagsFilter = Base.Fix1(in, :x1)
136+ # tagsFilter([:x1, :x2])
137+ # true
138+ # """
139+
131140function getVariables (
132141 dfg:: GraphsDFG ,
133- regexFilter :: Union{Nothing, Regex} = nothing ;
142+ regex :: Union{Nothing, Regex} = nothing ;
134143 tags:: Vector{Symbol} = Symbol[],
135- solvable:: Int = 0 ,
136- solvableFilter:: Union{Nothing, Base.Fix2} = nothing ,
144+ solvable:: Union{Nothing, Int} = nothing ,
145+ solvableFilter:: Union{Nothing, Function} = nothing ,
146+ labelFilter:: Union{Nothing, Function} = nothing ,
147+ tagsFilter:: Union{Nothing, Function} = nothing ,
148+ typeFilter:: Union{Nothing, Function} = nothing ,
137149)
138-
139- # variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa VariableCompute, vertices(dfg.g)))
140150 variables = collect (values (dfg. g. variables))
141151
142- ! isnothing (regexFilter) &&
143- filter! (v -> occursin (regexFilter, String (v. label)), variables)
144-
145- solvable != 0 && filter! (v -> _isSolvable (dfg, v. label, solvable), variables)
146-
147- ! isempty (tags) && filter! (v -> ! isempty (intersect (v. tags, tags)), variables)
152+ if ! isnothing (regex)
153+ # NOTE that contains(regex::Regex) is not supported by the NvaDFG.
154+ Base. depwarn (
155+ " The regex filter argument is deprecated, use kwarg `labelFilter=contains(regex)` instead" , # v0.28
156+ :getVariable ,
157+ )
158+ filterDFG! (variables, contains (regex), (String ∘ getLabel))
159+ end
160+ if ! isempty (tags)
161+ # NOTE that !isdisjoint is not supported by NvaDFG.
162+ Base. depwarn (
163+ " tags kwarg is deprecated, use kwarg `tagsFilter = !isdisjoint(tags)`` instead" , # v0.28
164+ :getVariable ,
165+ )
166+ filterDFG! (variables, ! isdisjoint (tags), getTags)
167+ end
168+ if ! isnothing (solvable)
169+ # TODO review. just one solvableFilter or keep solvable as well.
170+ Base. depwarn (
171+ " solvable kwarg is deprecated, use kwarg `solvableFilter = (>=solvable)`` instead" , # v0.28
172+ :getVariable ,
173+ )
174+ filterDFG! (variables, >= (solvable), getSolvable)
175+ end
148176
149- ! isnothing (solvableFilter) && filter! (v -> solvableFilter (getSolvable (v)), variables)
177+ filterDFG! (variables, labelFilter, (String ∘ getLabel))
178+ filterDFG! (variables, solvableFilter, getSolvable)
179+ filterDFG! (variables, tagsFilter, getTags)
180+ filterDFG! (variables, typeFilter, getVariableType)
150181
151182 return variables
152183end
@@ -155,23 +186,36 @@ function listVariables(
155186 dfg:: GraphsDFG ,
156187 regexFilter:: Union{Nothing, Regex} = nothing ;
157188 tags:: Vector{Symbol} = Symbol[],
158- solvable:: Int = 0 ,
159- solvableFilter:: Union{Nothing, Base.Fix2} = nothing ,
189+ solvable:: Union{Nothing, Int} = nothing ,
190+ solvableFilter:: Union{Nothing, Function} = nothing ,
191+ tagsFilter:: Union{Nothing, Function} = nothing ,
192+ typeFilter:: Union{Nothing, Function} = nothing ,
193+ labelFilter:: Union{Nothing, Function} = nothing ,
160194)
161-
162- # variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa VariableCompute, vertices(dfg.g)))
163- if length (tags) > 0
195+ if ! isnothing (solvableFilter) ||
196+ ! isnothing (tagsFilter) ||
197+ ! isnothing (typeFilter) ||
198+ ! isnothing (regexFilter) || # TODO deprecated
199+ ! isempty (tags) || # TODO deprecated
200+ ! isnothing (solvable) # TODO Maybe deprecated?
164201 return map (
165- v -> v. label,
166- getVariables (dfg, regexFilter; tags = tags, solvable = solvable),
167- ):: Vector{Symbol}
202+ getLabel,
203+ getVariables (
204+ dfg,
205+ regexFilter;
206+ tags,
207+ solvable,
208+ solvableFilter,
209+ tagsFilter,
210+ typeFilter,
211+ labelFilter,
212+ ),
213+ )
168214 else
169- variables = copy (dfg. g. variables. keys)
170- ! isnothing (regexFilter) && filter! (v -> occursin (regexFilter, String (v)), variables)
171- solvable != 0 && filter! (vId -> _isSolvable (dfg, vId, solvable), variables)
172- ! isnothing (solvableFilter) &&
173- filter! (v -> solvableFilter (getSolvable (dfg, v)), variables)
174- return variables:: Vector{Symbol}
215+ # Is it ok to continue using the internal keys property? collect(keys(dfg.g.variables)) allowcates a lot.
216+ labels = copy (dfg. g. variables. keys)
217+ filterDFG! (labels, labelFilter, string)
218+ return labels
175219 end
176220end
177221
0 commit comments