Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash function for Arr does not consider array structure and size #1145

Open
bowenszhu opened this issue May 20, 2024 · 1 comment
Open

Hash function for Arr does not consider array structure and size #1145

bowenszhu opened this issue May 20, 2024 · 1 comment

Comments

@bowenszhu
Copy link
Member

Currently, the hash function for Arr only considers its value field.

Symbolics.jl/src/arrays.jl

Lines 495 to 499 in 1da13fd

@symbolic_wrap struct Arr{T,N} <: AbstractArray{T, N}
value
end
Base.hash(x::Arr, u::UInt) = hash(unwrap(x), u)

This means that two Arr objects with identical symbolic elements but different array structures and sizes will have the same hash value.

For example, the following code snippet demonstrates this issue:

using Symbolics

a1 = only(@variables a[1:5])
a2 = only(@variables a[1:4, 1:6])
a3 = only(@variables a)

h1 = hash(a1)
h2 = hash(a2)
h3 = hash(a3)

h1 == h2 == h3 # This returns true, but we expect it to be false
@ChrisRackauckas
Copy link
Member

Yeah it seems to me that should hash differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants