Skip to content

Commit 626336d

Browse files
committed
deprecate hasTagsNeighbors
1 parent b6e0d90 commit 626336d

File tree

5 files changed

+56
-32
lines changed

5 files changed

+56
-32
lines changed

src/Deprecated.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,27 @@ end
321321
varlabel,
322322
)
323323

324+
# """
325+
# $SIGNATURES
326+
327+
# Determine if the variable or factor neighbors have the `tags:;Vector{Symbol}`, and `matchAll::Bool`.
328+
# """
329+
function hasTagsNeighbors(
330+
dfg::AbstractDFG,
331+
node_label::Symbol,
332+
tags::Vector{Symbol};
333+
matchAll::Bool = true,
334+
)
335+
#
336+
Base.depwarn(
337+
"hasTagsNeighbors is deprecated, use listNeighbors with tagsFilter instead",
338+
:hasTagsNeighbors,
339+
)
340+
# assume only variables or factors are neighbors
341+
alltags = union((listNeighbors(dfg, node_label) .|> x -> listTags(dfg, x))...)
342+
return length(filter(x -> x in alltags, tags)) >= (matchAll ? length(tags) : 1)
343+
end
344+
324345
## ================================================================================
325346
## Deprecated in v0.28
326347
##=================================================================================

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ export listTags
276276
export mergeTags!
277277
export emptyTags!
278278
export removeTags! #TODO do we want this one
279-
export hasTags
280279

281280
##------------------------------------------------------------------------------
282281
## Bloblets
@@ -378,7 +377,6 @@ const unstable_functions::Vector{Symbol} = [
378377
:getVariableLabelNumber,# TODO somewhat used, do we deprecate?
379378
:getfirstBlobentry,# TODO somewhat used, do we deprecate?
380379
:getSolveInProgress,#TODO unused, do we deprecate?
381-
:hasTagsNeighbors,
382380
:isVariable,
383381
:isFactor,
384382
:isConnected,
@@ -401,6 +399,7 @@ const unstable_functions::Vector{Symbol} = [
401399
:packState,
402400
:unpack,
403401
:unpackDistribution,
402+
:hasTags,
404403
# :unpackVariable,
405404
# :unpackFactor,
406405
:unpackBlob,
@@ -426,6 +425,7 @@ const unstable_functions::Vector{Symbol} = [
426425
# no set on these
427426

428427
#deprecated in v0.29
428+
:hasTagsNeighbors,
429429
# :updateBlobstore!,## TODO deprecated or obsolete
430430
:emptyMetadata!, #TODO maybe deprecate for just deleteMetadata!
431431
# :emptyBlobstore!, #TODO maybe deprecate for just deleteBlobstore!

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ function listVariables(
205205
if !isnothing(solvableFilter) ||
206206
!isnothing(tagsFilter) ||
207207
!isnothing(typeFilter) ||
208-
!isnothing(regexFilter) || #TODO deprecated
209-
!isempty(tags) || #TODO deprecated
208+
!isnothing(regexFilter) || #TODO deprecated v0.28
209+
!isempty(tags) || #TODO deprecated v0.28
210210
!isnothing(solvable) #TODO Maybe deprecated?
211211
return map(
212212
getLabel,
@@ -333,16 +333,31 @@ end
333333
function listNeighbors(
334334
dfg::GraphsDFG,
335335
label::Symbol;
336-
solvable::Union{Nothing, Int} = nothing,
336+
solvableFilter::Union{Nothing, Function} = nothing,
337+
tagsFilter::Union{Nothing, Function} = nothing,
338+
solvable::Union{Nothing, Int} = nothing, #TODO deprecated for solvableFilter v0.29
337339
)
340+
if !isnothing(solvable)
341+
Base.depwarn(
342+
"solvable kwarg is deprecated, use kwarg `solvableFilter = (>=solvable)` instead", #v0.29
343+
:listNeighbors,
344+
)
345+
!isnothing(solvableFilter) &&
346+
error("Cannot use both solvable and solvableFilter kwargs.")
347+
solvableFilter = >=(solvable)
348+
end
349+
338350
if !(hasVariable(dfg, label) || hasFactor(dfg, label))
339351
throw(LabelNotFoundError(label))
340352
end
341353

342354
neighbors_il = FactorGraphs.outneighbors(dfg.g, dfg.g.labels[label])
343355
neighbors_ll = [dfg.g.labels[i] for i in neighbors_il]
356+
344357
# Additional filtering
345-
solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
358+
# solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
359+
filterDFG!(neighbors_ll, solvableFilter, l->getSolvable(dfg, l))
360+
filterDFG!(neighbors_ll, tagsFilter, l->getTags(dfg, l))
346361

347362
# Variable sorting (order is important)
348363
if haskey(dfg.g.factors, label)

src/services/Tags.jl

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $SIGNATURES
88
99
Return the tags for a Node.
1010
"""
11-
getTags(node) = node.tags
11+
refTags(node) = node.tags
1212

1313
"""
1414
$SIGNATURES
@@ -105,22 +105,22 @@ end
105105

106106
function listTags(dfg::AbstractDFG, sym::Symbol)
107107
getFnc = isVariable(dfg, sym) ? getVariable : getFactor
108-
return getTags(getFnc(dfg, sym))
108+
return refTags(getFnc(dfg, sym))
109109
end
110110

111111
function mergeTags!(dfg::InMemoryDFGTypes, sym::Symbol, tags)
112112
getFnc = isVariable(dfg, sym) ? getVariable : getFactor
113-
return union!(getTags(getFnc(dfg, sym)), tags)
113+
return union!(refTags(getFnc(dfg, sym)), tags)
114114
end
115115

116116
function removeTags!(dfg::InMemoryDFGTypes, sym::Symbol, tags)
117117
getFnc = isVariable(dfg, sym) ? getVariable : getFactor
118-
return setdiff!(getTags(getFnc(dfg, sym)), tags)
118+
return setdiff!(refTags(getFnc(dfg, sym)), tags)
119119
end
120120

121121
function emptyTags!(dfg::InMemoryDFGTypes, sym::Symbol)
122122
getFnc = isVariable(dfg, sym) ? getVariable : getFactor
123-
return empty!(getTags(getFnc(dfg, sym)))
123+
return empty!(refTags(getFnc(dfg, sym)))
124124
end
125125

126126
##------------------------------------------------------------------------------
@@ -134,23 +134,5 @@ Determine if the variable or factor neighbors have the `tags:;Vector{Symbol}`, a
134134
function hasTags(dfg::AbstractDFG, sym::Symbol, tags::Vector{Symbol}; matchAll::Bool = true)
135135
#
136136
alltags = listTags(dfg, sym)
137-
return length(filter(x -> x in alltags, tags)) >= (matchAll ? length(tags) : 1)
138-
end
139-
140-
"""
141-
$SIGNATURES
142-
143-
Determine if the variable or factor neighbors have the `tags:;Vector{Symbol}`, and `matchAll::Bool`.
144-
"""
145-
function hasTagsNeighbors(
146-
dfg::AbstractDFG,
147-
sym::Symbol,
148-
tags::Vector{Symbol};
149-
matchAll::Bool = true,
150-
)
151-
#
152-
# assume only variables or factors are neighbors
153-
getNeiFnc = isVariable(dfg, sym) ? getFactor : getVariable
154-
alltags = union((ls(dfg, sym) .|> x -> getTags(getNeiFnc(dfg, x)))...)
155-
return length(filter(x -> x in alltags, tags)) >= (matchAll ? length(tags) : 1)
137+
return length(alltags tags) >= (matchAll ? length(tags) : 1)
156138
end

test/testBlocks.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,14 @@ function tagsTestBlock!(fg, v1, v1_tags)
556556
@test hasTags(fg, :b, [v2Tags...])
557557
@test hasTags(fg, :b, [:LANDMARK, :TAG], matchAll = false)
558558

559-
@test hasTagsNeighbors(fg, :abf1, [:LANDMARK])
560-
@test !hasTagsNeighbors(fg, :abf1, [:LANDMARK, :TAG])
559+
#TODO can be simplified but require julia v1.11
560+
# @test listNeighbors(fg, :abf1; tagsFilter = ⊇([:LANDMARK])) == [:b]
561+
# @test isempty(listNeighbors(fg, :abf1; tagsFilter = ⊇([:LANDMARK, :TAG])))
562+
563+
@test listNeighbors(fg, :abf1; tagsFilter = Base.Fix1(issubset, [:LANDMARK])) == [:b]
564+
@test isempty(
565+
listNeighbors(fg, :abf1; tagsFilter = Base.Fix1(issubset, [:LANDMARK, :TAG])),
566+
)
561567
end
562568

563569
function VSDTestBlock!(fg, v1)

0 commit comments

Comments
 (0)