Skip to content

Commit

Permalink
Merge pull request #1092 from JuliaRobotics/24Q3/maintanance
Browse files Browse the repository at this point in the history
remove all return types and deprecate lsfWho
  • Loading branch information
Affie authored Sep 13, 2024
2 parents afff497 + e98bc54 commit 817eb84
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ $(SIGNATURES)
Returns true if the label is valid for a session, robot, or user ID.
"""
function isValidLabel(id::Union{Symbol, String})::Bool
function isValidLabel(id::Union{Symbol, String})
if typeof(id) == Symbol
id = String(id)
end
Expand Down
2 changes: 2 additions & 0 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
##=================================================================================
@deprecate getBlobEntry(var::AbstractDFGVariable, key::AbstractString) getBlobEntryFirst(var, Regex(key))

@deprecate lsfWho(dfg::AbstractDFG, type::Symbol) lsf(dfg, getfield(Main, type))

## ================================================================================
## Deprecated in v0.23
##=================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export isValidLabel
## List
export ls, lsf, ls2
export lsTypes, lsfTypes, lsTypesDict, lsfTypesDict
export lsWho, lsfWho
export lsWho
export isPrior, lsfPriors
export hasTags, hasTagsNeighbors

Expand Down
2 changes: 1 addition & 1 deletion src/GraphsDFG/FactorGraphs/FactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function addFactor!(
g::FactorGraph{T, V, F},
variableLabels::Vector{Symbol},
factor::F,
)::Bool where {T, V, F}
) where {T, V, F}
haskey(g.labels, factor.label) &&
(@error "Label $(factor.label) already in fg"; return false)

Expand Down
19 changes: 8 additions & 11 deletions src/GraphsDFG/services/GraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ end
function addVariable!(
dfg::GraphsDFG{<:AbstractParams, V, <:AbstractDFGFactor},
variable::V,
)::V where {V <: AbstractDFGVariable}
) where {V <: AbstractDFGVariable}
#TODO should this be an error
if haskey(dfg.g.variables, variable.label)
error("Variable '$(variable.label)' already exists in the factor graph")
Expand All @@ -58,7 +58,7 @@ end
function addVariable!(
dfg::GraphsDFG{<:AbstractParams, VD, <:AbstractDFGFactor},
variable::AbstractDFGVariable,
)::VD where {VD <: AbstractDFGVariable}
) where {VD <: AbstractDFGVariable}
return addVariable!(dfg, VD(variable))
end

Expand Down Expand Up @@ -186,7 +186,7 @@ function deleteFactor!(
dfg::GraphsDFG,
label::Symbol;
suppressGetFactor::Bool = false,
)::AbstractDFGFactor
)
if !haskey(dfg.g.factors, label)
error("Factor label '$(label)' does not exist in the factor graph")
end
Expand Down Expand Up @@ -285,12 +285,12 @@ function listFactors(
return factors::Vector{Symbol}
end

function isConnected(dfg::GraphsDFG)::Bool
function isConnected(dfg::GraphsDFG)
return Graphs.is_connected(dfg.g)
# return length(Graphs.connected_components(dfg.g)) == 1
end

function _isSolvable(dfg::GraphsDFG, label::Symbol, ready::Int)::Bool
function _isSolvable(dfg::GraphsDFG, label::Symbol, ready::Int)
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].solvable >= ready)
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].solvable >= ready)

Expand Down Expand Up @@ -321,7 +321,7 @@ function listNeighbors(dfg::GraphsDFG, node::DFGNode; solvable::Int = 0)
return neighbors_ll::Vector{Symbol}
end

function listNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int = 0)::Vector{Symbol}
function listNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int = 0)
if !exists(dfg, label)
error("Variable/factor with label '$(label)' does not exist in the factor graph")
end
Expand All @@ -345,7 +345,7 @@ function getNeighborhood(
variableFactorLabels::Vector{Symbol},
distance::Int;
solvable::Int = 0,
)::Vector{Symbol}
)
# find neighbors at distance to add
nbhood = Int[]

Expand Down Expand Up @@ -375,10 +375,7 @@ function getBiadjacencyMatrix(
solvable::Int = 0,
varLabels = listVariables(dfg; solvable = solvable),
factLabels = listFactors(dfg; solvable = solvable),
)::NamedTuple{
(:B, :varLabels, :facLabels),
Tuple{Graphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}},
}
)
varIndex = [dfg.g.labels[s] for s in varLabels]
factIndex = [dfg.g.labels[s] for s in factLabels]

Expand Down
39 changes: 11 additions & 28 deletions src/services/AbstractDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ function listFactors(
regexFilter::Union{Nothing, Regex} = nothing;
tags::Vector{Symbol} = Symbol[],
solvable::Int = 0,
)::Vector{Symbol} where {G <: AbstractDFG}
) where {G <: AbstractDFG}
return map(f -> f.label, getFactors(dfg, regexFilter; tags = tags, solvable = solvable))
end

Expand Down Expand Up @@ -754,7 +754,7 @@ function lsf(
dfg::G,
label::Symbol;
solvable::Int = 0,
)::Vector{Symbol} where {G <: AbstractDFG}
) where {G <: AbstractDFG}
return listNeighbors(dfg, label; solvable = solvable)
end

Expand All @@ -775,6 +775,15 @@ function ls(dfg::G, ::Type{T}) where {G <: AbstractDFG, T <: AbstractFactor}
return map(x -> x.label, vxx)
end

"""
$(SIGNATURES)
Lists the factors of a specific type in the factor graph.
Example, list all the Point2Point2 factors in the factor graph `dfg`:
lsfWho(dfg, :Point2Point2)
Notes
- Return `Vector{Symbol}`
"""
function lsf(dfg::G, ::Type{T}) where {G <: AbstractDFG, T <: AbstractFactor}
return ls(dfg, T)
end
Expand Down Expand Up @@ -837,32 +846,6 @@ function lsWho(dfg::AbstractDFG, type::Symbol)
return labels
end

"""
$(SIGNATURES)
Gives back all factor labels that fit the bill:
lsfWho(dfg, :Point2Point2)
Notes
- Returns `Vector{Symbol}`
Dev Notes
- Cloud versions will benefit from less data transfer
- `ls(dfg::C, ::T) where {C <: CloudDFG, T <: ..}`
Related
ls, lsf, lsfPriors
"""
function lsfWho(dfg::AbstractDFG, type::Symbol)
facs = getFactors(dfg)
labels = Symbol[]
for f in facs
facType = typeof(getFactorType(f)) |> nameof
facType == type && push!(labels, f.label)
end
return labels
end

## list types
##-----------

Expand Down
10 changes: 5 additions & 5 deletions src/services/CommonAccessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ Variables or factors may or may not be 'solvable', depending on a user definitio
Related:
- isSolveInProgress
"""
getSolvable(var::Union{DFGVariable, DFGFactor})::Int = var.solvable
getSolvable(var::Union{DFGVariable, DFGFactor}) = var.solvable
#TODO DataLevel2

"""
$SIGNATURES
Get 'solvable' parameter for either a variable or factor.
"""
function getSolvable(dfg::AbstractDFG, sym::Symbol)::Int
function getSolvable(dfg::AbstractDFG, sym::Symbol)
if isVariable(dfg, sym)
return getVariable(dfg, sym).solvable
elseif isFactor(dfg, sym)
Expand All @@ -110,7 +110,7 @@ end
Set the `solvable` parameter for either a variable or factor.
"""
function setSolvable!(node::N, solvable::Int)::Int where {N <: DFGNode}
function setSolvable!(node::N, solvable::Int) where {N <: DFGNode}
node.solvable = solvable
return solvable
end
Expand All @@ -120,7 +120,7 @@ end
Set the `solvable` parameter for either a variable or factor.
"""
function setSolvable!(dfg::AbstractDFG, sym::Symbol, solvable::Int)::Int
function setSolvable!(dfg::AbstractDFG, sym::Symbol, solvable::Int)
if isVariable(dfg, sym)
getVariable(dfg, sym).solvable = solvable
elseif isFactor(dfg, sym)
Expand Down Expand Up @@ -158,7 +158,7 @@ isSolvable
function getSolveInProgress(
var::Union{DFGVariable, DFGFactor},
solveKey::Symbol = :default,
)::Int
)
# Variable
if var isa DFGVariable
if haskey(getSolverDataDict(var), solveKey)
Expand Down
4 changes: 2 additions & 2 deletions src/services/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ Retrieve the soft type name symbol for a DFGVariableSummary. ie :Point2, Pose2,
"""
getVariableTypeName(v::DFGVariableSummary) = v.variableTypeName::Symbol

function getVariableType(v::DFGVariableSummary)::InferenceVariable
function getVariableType(v::DFGVariableSummary)
@warn "Looking for type in `Main`. Only use if `variableType` has only one implementation, ie. Pose2. Otherwise use the full variable."
return getfield(Main, v.variableTypeName)()
end
Expand Down Expand Up @@ -921,7 +921,7 @@ end
$(SIGNATURES)
List all the solver data keys in the variable.
"""
function listVariableSolverData(dfg::AbstractDFG, variablekey::Symbol)::Vector{Symbol}
function listVariableSolverData(dfg::AbstractDFG, variablekey::Symbol)
v = getVariable(dfg, variablekey)
return collect(keys(v.solverDataDict))
end
Expand Down
1 change: 0 additions & 1 deletion test/iifInterfaceTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ end

@test ls(dfg, LinearRelative) == [:abf1]
@test lsf(dfg, LinearRelative) == [:abf1]
@test lsfWho(dfg, :LinearRelative) == [:abf1]

@test getVariableType(v1) isa Position{1}
@test getVariableType(dfg, :a) isa Position{1}
Expand Down
1 change: 0 additions & 1 deletion test/testBlocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,6 @@ function testGroup!(fg, v1, v2, f0, f1)

@test ls(fg, TestFunctorInferenceType1) == [:abf1]
@test lsf(fg, TestAbstractPrior) == [:af1]
@test lsfWho(fg, :TestFunctorInferenceType1) == [:abf1]

@test getVariableType(v1) == TestVariableType1()
@test getVariableType(fg, :a) == TestVariableType1()
Expand Down

0 comments on commit 817eb84

Please sign in to comment.