diff --git a/Project.toml b/Project.toml index aa147267..128b0e13 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DistributedFactorGraphs" uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04" -version = "0.15.1" +version = "0.15.2" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -46,7 +46,8 @@ GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Manifolds = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "GraphPlot", "LinearAlgebra", "Manifolds", "Pkg"] +test = ["Test", "GraphPlot", "LinearAlgebra", "Manifolds", "Pkg", "Statistics"] diff --git a/src/FileDFG/services/FileDFG.jl b/src/FileDFG/services/FileDFG.jl index 4455ed17..5421e6d3 100644 --- a/src/FileDFG/services/FileDFG.jl +++ b/src/FileDFG/services/FileDFG.jl @@ -152,6 +152,7 @@ function loadDFG!(dfgLoadInto::AbstractDFG, dst::AbstractString) map(f->addFactor!(dfgLoadInto, f), factors) # Finally, rebuild the CCW's for the factors to completely reinflate them + # NOTE CREATES A NEW DFGFactor IF CCW TYPE CHANGES @info "Rebuilding CCW's for the factors..." for factor in factors rebuildFactorMetadata!(dfgLoadInto, factor) diff --git a/src/LightDFG/services/LightDFG.jl b/src/LightDFG/services/LightDFG.jl index cb39cfbe..b4e8b9b9 100644 --- a/src/LightDFG/services/LightDFG.jl +++ b/src/LightDFG/services/LightDFG.jl @@ -79,13 +79,13 @@ end # end -function addFactor!(dfg::LightDFG{<:AbstractParams, <:AbstractDFGVariable, F}, factor::F)::F where F <: AbstractDFGFactor +function addFactor!(dfg::LightDFG{<:AbstractParams, <:AbstractDFGVariable, F}, factor::F) where F <: AbstractDFGFactor if haskey(dfg.g.factors, factor.label) error("Factor '$(factor.label)' already exists in the factor graph") end # TODO # @assert FactorGraphs.addFactor!(dfg.g, getVariableOrder(factor), factor) - @assert FactorGraphs.addFactor!(dfg.g, factor._variableOrderSymbols, factor) + @assert FactorGraphs.addFactor!(dfg.g, Symbol[factor._variableOrderSymbols...], factor) return factor end diff --git a/src/entities/DFGFactor.jl b/src/entities/DFGFactor.jl index 83d22b83..3744794f 100644 --- a/src/entities/DFGFactor.jl +++ b/src/entities/DFGFactor.jl @@ -38,7 +38,7 @@ Designing (WIP) - in DFG.AbstractRelativeMinimize <: FunctorInferenceType - in Main.SomeFactor <: AbstractRelativeMinimize """ -mutable struct GenericFunctionNodeData{T<:Union{PackedInferenceType, FunctorInferenceType, FactorOperationalMemory}} +mutable struct GenericFunctionNodeData{T<:Union{<:PackedInferenceType, <:AbstractFactor, <:FactorOperationalMemory}} eliminated::Bool potentialused::Bool edgeIDs::Vector{Int} @@ -80,7 +80,7 @@ end const PackedFunctionNodeData{T} = GenericFunctionNodeData{T} where T <: AbstractPackedFactor PackedFunctionNodeData(args...) = PackedFunctionNodeData{typeof(args[4])}(args...) -const FunctionNodeData{T} = GenericFunctionNodeData{T} where T <: Union{AbstractFactor, FactorOperationalMemory} +const FunctionNodeData{T} = GenericFunctionNodeData{T} where T <: Union{<:AbstractFactor, <:FactorOperationalMemory} FunctionNodeData(args...) = FunctionNodeData{typeof(args[4])}(args...) diff --git a/src/entities/DFGVariable.jl b/src/entities/DFGVariable.jl index daae9c60..b11e7474 100644 --- a/src/entities/DFGVariable.jl +++ b/src/entities/DFGVariable.jl @@ -226,7 +226,8 @@ abstract type AbstractPointParametricEst end Data container to store Parameteric Point Estimate (PPE) for mean and max. """ struct MeanMaxPPE <: AbstractPointParametricEst - solveKey::Symbol #repeated because of Sam's request + # repeat key value internally (from a design request by Sam) + solveKey::Symbol suggested::Vector{Float64} max::Vector{Float64} mean::Vector{Float64} diff --git a/src/services/AbstractDFG.jl b/src/services/AbstractDFG.jl index 2812ffce..2f3c8b6b 100644 --- a/src/services/AbstractDFG.jl +++ b/src/services/AbstractDFG.jl @@ -76,7 +76,7 @@ getFactorOperationalMemoryType(dfg::AbstractDFG) = getFactorOperationalMemoryTyp Method must be overloaded by the user for Serialization to work. """ -rebuildFactorMetadata!(dfg::AbstractDFG{<:AbstractParams}, factor::AbstractDFGFactor) = error("rebuildFactorMetadata! is not implemented for $(typeof(dfg))") +rebuildFactorMetadata!(dfg::AbstractDFG{<:AbstractParams}, factor::AbstractDFGFactor, neighbors=[]) = error("rebuildFactorMetadata! is not implemented for $(typeof(dfg))") ##------------------------------------------------------------------------------ ## Setters diff --git a/src/services/CompareUtils.jl b/src/services/CompareUtils.jl index d4ab0331..9ef53d81 100644 --- a/src/services/CompareUtils.jl +++ b/src/services/CompareUtils.jl @@ -43,27 +43,29 @@ end """ $(SIGNATURES) -Compare the all fields of T that are not in `skip` for objects `Al` and `Bl`. +Compare the all fields of T that are not in `skip` for objects `Al` and `Bl` and returns `::Bool`. TODO > add to func_ref.md """ -function compareFields(Al::T, - Bl::T; - show::Bool=true, - skip::Vector{Symbol}=Symbol[] )::Bool where {T} - for field in fieldnames(T) +function compareFields( Al::T1, + Bl::T2; + show::Bool=true, + skip::Vector{Symbol}=Symbol[] ) where {T1,T2} + # + T1 == T2 ? nothing : @warn("different types in compareFields", T1, T2) + for field in fieldnames(T1) (field in skip) && continue tp = compareField(Al, Bl, field) - show && @debug(" $tp : $field")==nothing + show && @debug(" $tp : $field") === nothing !tp && return false end return true end -function compareFields(Al::T, - Bl::T; - show::Bool=true, - skip::Vector{Symbol}=Symbol[] )::Bool where {T <: Union{Number, AbstractString}} +function compareFields( Al::T, + Bl::T; + show::Bool=true, + skip::Vector{Symbol}=Symbol[] )::Bool where {T <: Union{Number, AbstractString}} # return Al == Bl end @@ -130,12 +132,15 @@ function compareAll(Al::T, return true end -function compareAll(Al::T, Bl::T; show::Bool=true, skip::Vector{Symbol}=Symbol[]) where T - @debug "Comparing types $T:" +function compareAll(Al::T1, Bl::T2; show::Bool=true, skip::Vector{Symbol}=Symbol[]) where {T1,T2} + @debug "Comparing types $T1, $T2" + if T1 != T2 + @warn "Types are different" T1 T2 + end # @debug " Al = $Al" # @debug " Bl = $Bl" !compareFields(Al, Bl, show=show, skip=skip) && return false - for field in fieldnames(T) + for field in fieldnames(T1) field in skip && continue @debug(" Checking field: $field") (!isdefined(Al, field) && !isdefined(Al, field)) && return true @@ -202,10 +207,11 @@ function compareAllSpecial(A::T1, skip=Symbol[], show::Bool=true) where {T1 <: GenericFunctionNodeData, T2 <: GenericFunctionNodeData} if T1 != T2 - return false - else - return compareAll(A, B, skip=skip, show=show) + @warn "compareAllSpecial is comparing different types" T1 T2 + # return false + # else end + return compareAll(A, B, skip=skip, show=show) end @@ -236,17 +242,20 @@ function compareFactor(A::DFGFactor, skipsamples::Bool=true, skipcompute::Bool=true ) # - skip_ = - TP = compareAll(A, B, skip=union([:attributes;:solverData;:_variableOrderSymbols;:_gradients],skip), show=show) - # TP = TP & compareAll(A.attributes, B.attributes, skip=[:data;], show=show) + skip_ = union([:attributes;:solverData;:_variableOrderSymbols;:_gradients],skip) + TP = compareAll(A, B, skip=skip_, show=show) + @debug "compareFactor 1/5" TP TP = TP & compareAllSpecial(getSolverData(A), getSolverData(B), skip=union([:fnc;:_gradients], skip), show=show) - if :fnc in skip + @debug "compareFactor 2/5" TP + if !TP || :fnc in skip return TP end TP = TP & compareAllSpecial(getSolverData(A).fnc, getSolverData(B).fnc, skip=union([:cpt;:measurement;:params;:varidx;:threadmodel;:_gradients], skip), show=show) + @debug "compareFactor 3/5" TP if !(:measurement in skip) - TP = TP & (skipsamples || compareAll(getSolverData(A).fnc.measurement, getSolverData(B).fnc.measurement, show=show, skip=skip)) + TP = TP & (skipsamples || compareAll(getSolverData(A).fnc.measurement, getSolverData(B).fnc.measurement, show=show, skip=skip)) end + @debug "compareFactor 4/5" TP if !(:params in skip) TP = TP & (skipcompute || compareAll(getSolverData(A).fnc.params, getSolverData(B).fnc.params, show=show, skip=skip)) end diff --git a/src/services/Serialization.jl b/src/services/Serialization.jl index ba533021..f35b7b5b 100644 --- a/src/services/Serialization.jl +++ b/src/services/Serialization.jl @@ -373,14 +373,14 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any})::DFGFactor where G # Rebuild DFGFactor #TODO use constuctor to create factor - factor = DFGFactor(Symbol(label), - timestamp, - nstime, - Set(tags), - fullFactorData, - solvable, - Tuple(_variableOrderSymbols)) - + factor = DFGFactor( Symbol(label), + timestamp, + nstime, + Set(tags), + fullFactorData, + solvable, + Tuple(_variableOrderSymbols)) + # # Note, once inserted, you still need to call rebuildFactorMetadata! return factor