Skip to content

Commit b5b84ff

Browse files
authored
Merge pull request #798 from JuliaRobotics/21Q3/enh/compareccwnt
relax compare types for NamedTuple case
2 parents 1659d71 + 5b8632c commit b5b84ff

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.15.1"
3+
version = "0.15.2"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
@@ -46,7 +46,8 @@ GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
4646
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
4747
Manifolds = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
4848
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
49+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
4950
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5051

5152
[targets]
52-
test = ["Test", "GraphPlot", "LinearAlgebra", "Manifolds", "Pkg"]
53+
test = ["Test", "GraphPlot", "LinearAlgebra", "Manifolds", "Pkg", "Statistics"]

src/services/CompareUtils.jl

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,29 @@ end
4343
"""
4444
$(SIGNATURES)
4545
46-
Compare the all fields of T that are not in `skip` for objects `Al` and `Bl`.
46+
Compare the all fields of T that are not in `skip` for objects `Al` and `Bl` and returns `::Bool`.
4747
4848
TODO > add to func_ref.md
4949
"""
50-
function compareFields(Al::T,
51-
Bl::T;
52-
show::Bool=true,
53-
skip::Vector{Symbol}=Symbol[] )::Bool where {T}
54-
for field in fieldnames(T)
50+
function compareFields( Al::T1,
51+
Bl::T2;
52+
show::Bool=true,
53+
skip::Vector{Symbol}=Symbol[] ) where {T1,T2}
54+
#
55+
T1 == T2 ? nothing : @warn("different types in compareFields", T1, T2)
56+
for field in fieldnames(T1)
5557
(field in skip) && continue
5658
tp = compareField(Al, Bl, field)
57-
show && @debug(" $tp : $field")==nothing
59+
show && @debug(" $tp : $field") === nothing
5860
!tp && return false
5961
end
6062
return true
6163
end
6264

63-
function compareFields(Al::T,
64-
Bl::T;
65-
show::Bool=true,
66-
skip::Vector{Symbol}=Symbol[] )::Bool where {T <: Union{Number, AbstractString}}
65+
function compareFields( Al::T,
66+
Bl::T;
67+
show::Bool=true,
68+
skip::Vector{Symbol}=Symbol[] )::Bool where {T <: Union{Number, AbstractString}}
6769
#
6870
return Al == Bl
6971
end
@@ -130,12 +132,15 @@ function compareAll(Al::T,
130132
return true
131133
end
132134

133-
function compareAll(Al::T, Bl::T; show::Bool=true, skip::Vector{Symbol}=Symbol[]) where T
134-
@debug "Comparing types $T:"
135+
function compareAll(Al::T1, Bl::T2; show::Bool=true, skip::Vector{Symbol}=Symbol[]) where {T1,T2}
136+
@debug "Comparing types $T1, $T2"
137+
if T1 != T2
138+
@warn "Types are different" T1 T2
139+
end
135140
# @debug " Al = $Al"
136141
# @debug " Bl = $Bl"
137142
!compareFields(Al, Bl, show=show, skip=skip) && return false
138-
for field in fieldnames(T)
143+
for field in fieldnames(T1)
139144
field in skip && continue
140145
@debug(" Checking field: $field")
141146
(!isdefined(Al, field) && !isdefined(Al, field)) && return true
@@ -202,10 +207,11 @@ function compareAllSpecial(A::T1,
202207
skip=Symbol[],
203208
show::Bool=true) where {T1 <: GenericFunctionNodeData, T2 <: GenericFunctionNodeData}
204209
if T1 != T2
205-
return false
206-
else
207-
return compareAll(A, B, skip=skip, show=show)
210+
@warn "compareAllSpecial is comparing different types" T1 T2
211+
# return false
212+
# else
208213
end
214+
return compareAll(A, B, skip=skip, show=show)
209215
end
210216

211217

@@ -236,17 +242,20 @@ function compareFactor(A::DFGFactor,
236242
skipsamples::Bool=true,
237243
skipcompute::Bool=true )
238244
#
239-
skip_ =
240-
TP = compareAll(A, B, skip=union([:attributes;:solverData;:_variableOrderSymbols;:_gradients],skip), show=show)
241-
# TP = TP & compareAll(A.attributes, B.attributes, skip=[:data;], show=show)
245+
skip_ = union([:attributes;:solverData;:_variableOrderSymbols;:_gradients],skip)
246+
TP = compareAll(A, B, skip=skip_, show=show)
247+
@debug "compareFactor 1/5" TP
242248
TP = TP & compareAllSpecial(getSolverData(A), getSolverData(B), skip=union([:fnc;:_gradients], skip), show=show)
243-
if :fnc in skip
249+
@debug "compareFactor 2/5" TP
250+
if !TP || :fnc in skip
244251
return TP
245252
end
246253
TP = TP & compareAllSpecial(getSolverData(A).fnc, getSolverData(B).fnc, skip=union([:cpt;:measurement;:params;:varidx;:threadmodel;:_gradients], skip), show=show)
254+
@debug "compareFactor 3/5" TP
247255
if !(:measurement in skip)
248-
TP = TP & (skipsamples || compareAll(getSolverData(A).fnc.measurement, getSolverData(B).fnc.measurement, show=show, skip=skip))
256+
TP = TP & (skipsamples || compareAll(getSolverData(A).fnc.measurement, getSolverData(B).fnc.measurement, show=show, skip=skip))
249257
end
258+
@debug "compareFactor 4/5" TP
250259
if !(:params in skip)
251260
TP = TP & (skipcompute || compareAll(getSolverData(A).fnc.params, getSolverData(B).fnc.params, show=show, skip=skip))
252261
end

0 commit comments

Comments
 (0)