Skip to content

Commit eb92d26

Browse files
committed
fix hash for Operation
1 parent c9678ab commit eb92d26

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/operations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Base.isequal(::Variable , ::Operation) = false
5454
Base.isequal(::Operation, ::Constant ) = false
5555
Base.isequal(::Constant , ::Operation) = false
5656

57+
Base.hash(o::Operation, salt::UInt) = hash(o.args, hash(o.op, salt))
58+
5759
# provide iszero for Operations to help sparse addition and multiplication
5860
# e.g., we want to tell the sparse library that iszero(zero(Operation) + zero(Operation)) == true
5961
Base.iszero(x::Operation) = (_x = simplify(x); _x isa Constant && iszero(_x.value))

test/operation_overloads.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ using Test
55

66
@variables a,b,c,d
77

8+
# test hashing
9+
aa = a; # old a
10+
11+
@variables a
12+
13+
@test isequal(a, aa)
14+
@test hash(a) == hash(aa)
15+
16+
@test isequal(get_variables(a+aa+1), [a])
17+
818
# test some matrix operations don't throw errors
919
X = [a b;c d]
1020
det(X)

0 commit comments

Comments
 (0)