Skip to content

Commit 3956990

Browse files
committed
Fixing equality operators
1 parent 3d90bf7 commit 3956990

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

src/services/DFGVariable.jl

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,20 @@ function unpack(dfg::G, d::PackedVariableNodeData)::VariableNodeData where G <:
8383
end
8484

8585
function compare(a::VariableNodeData, b::VariableNodeData)
86-
TP = true
87-
TP = TP && a.val == b.val
88-
TP = TP && a.bw == b.bw
89-
TP = TP && a.BayesNetOutVertIDs == b.BayesNetOutVertIDs
90-
TP = TP && a.dimIDs == b.dimIDs
91-
TP = TP && a.dims == b.dims
92-
TP = TP && a.eliminated == b.eliminated
93-
TP = TP && a.BayesNetVertID == b.BayesNetVertID
94-
TP = TP && a.separator == b.separator
95-
TP = TP && a.initialized == b.initialized
96-
TP = TP && abs(a.inferdim - b.inferdim) < 1e-14
97-
TP = TP && a.ismargin == b.ismargin
98-
TP = TP && a.dontmargin == b.dontmargin
99-
TP = TP && typeof(a.softtype) == typeof(b.softtype) # Can't do equals, need to check type.
100-
return TP
86+
a.val != b.val && @debug("val is not equal")==nothing && return false
87+
a.bw != b.bw && @debug("bw is not equal")==nothing && return false
88+
a.BayesNetOutVertIDs != b.BayesNetOutVertIDs && @debug("BayesNetOutVertIDs is not equal")==nothing && return false
89+
a.dimIDs != b.dimIDs && @debug("dimIDs is not equal")==nothing && return false
90+
a.dims != b.dims && @debug("dims is not equal")==nothing && return false
91+
a.eliminated != b.eliminated && @debug("eliminated is not equal")==nothing && return false
92+
a.BayesNetVertID != b.BayesNetVertID && @debug("BayesNetVertID is not equal")==nothing && return false
93+
a.separator != b.separator && @debug("separator is not equal")==nothing && return false
94+
a.initialized != b.initialized && @debug("initialized is not equal")==nothing && return false
95+
abs(a.inferdim - b.inferdim) > 1e-14 && @debug("inferdim is not equal")==nothing && return false
96+
a.ismargin != b.ismargin && @debug("ismargin is not equal")==nothing && return false
97+
a.dontmargin != b.dontmargin && @debug("dontmargin is not equal")==nothing && return false
98+
typeof(a.softtype) != typeof(b.softtype) && @debug("softtype is not equal")==nothing && return false
99+
return true
101100
end
102101

103102
"""
@@ -113,10 +112,10 @@ end
113112
Equality check for VariableEstimate.
114113
"""
115114
function ==(a::VariableEstimate, b::VariableEstimate)::Bool
116-
a.solverKey != b.solverKey && return false
117-
a.type != b.type && return false
118-
a.estimate != b.estimate && return false
119-
a.lastUpdatedTimestamp != b.lastUpdatedTimestamp && return false
115+
a.solverKey != b.solverKey && @debug("solverKey are not equal")==nothing && return false
116+
a.type != b.type && @debug("type is not equal")==nothing && return false
117+
a.estimate != b.estimate && @debug("estimate are not equal")==nothing && return false
118+
a.lastUpdatedTimestamp != b.lastUpdatedTimestamp && @debug("lastUpdatedTimestamp is not equal")==nothing && return false
120119
return true
121120
end
122121

@@ -125,22 +124,22 @@ end
125124
Equality check for DFGVariable.
126125
"""
127126
function ==(a::DFGVariable, b::DFGVariable)::Bool
128-
a.label != b.label && return false
129-
a.timestamp != b.timestamp && return false
130-
a.tags != b.tags && return false
131-
symdiff(keys(a.estimateDict), keys(b.estimateDict)) != Set(Symbol[]) && return false
127+
a.label != b.label && @debug("label is not equal")==nothing && return false
128+
a.timestamp != b.timestamp && @debug("timestamp is not equal")==nothing && return false
129+
a.tags != b.tags && @debug("tags is not equal")==nothing && return false
130+
symdiff(keys(a.estimateDict), keys(b.estimateDict)) != Set(Symbol[]) && @debug("estimateDict keys are not equal")==nothing && return false
132131
for k in keys(a.estimateDict)
133-
a.estimateDict[k] != b.estimateDict[k] && return false
132+
a.estimateDict[k] != b.estimateDict[k] && @debug("estimateDict[$k] is not equal")==nothing && return false
134133
end
135-
symdiff(keys(a.solverDataDict), keys(b.solverDataDict)) != [] && return false
134+
symdiff(keys(a.solverDataDict), keys(b.solverDataDict)) != Set(Symbol[]) && @debug("solverDataDict keys are not equal")==nothing && return false
136135
for k in keys(a.solverDataDict)
137-
a.solverDataDict[k] != b.solverDataDict[k] && return false
136+
a.solverDataDict[k] != b.solverDataDict[k] && @debug("solverDataDict[$k] is not equal")==nothing && return false
138137
end
139-
a.smallData != b.smallData && return false
140-
a.bigData != b.bigData && return false
141-
a.ready != b.ready && return false
142-
a.backendset != b.backendset && return false
143-
a._internalId != b._internalId && return false
138+
a.smallData != b.smallData && @debug("smallData is not equal")==nothing && return false
139+
a.bigData != b.bigData && @debug("bigData is not equal")==nothing && return false
140+
a.ready != b.ready && @debug("ready is not equal")==nothing && return false
141+
a.backendset != b.backendset && @debug("backendset is not equal")==nothing && return false
142+
a._internalId != b._internalId && @debug("_internalId is not equal")==nothing && return false
144143
return true
145144
end
146145

test/interfaceTests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ end
7171
@testset "Gets, Sets, and Accessors" begin
7272
global dfg,v1,v2,f1
7373
@test getVariable(dfg, v1.label) == v1
74+
@test getVariable(dfg, v2.label) != v1
7475
@test getFactor(dfg, f1.label) == f1
76+
f2 = deepcopy(f1)
77+
f2.label = :something
78+
@test f2 != f1
7579
@test_throws Exception getVariable(dfg, :nope)
7680
@test_throws Exception getVariable(dfg, "nope")
7781
@test_throws Exception getFactor(dfg, :nope)

0 commit comments

Comments
 (0)