dstl / Stone-Soup

A software project to provide the target tracking community with a framework for the development and testing of tracking algorithms.
https://stonesoup.rtfd.io
MIT License
400 stars 131 forks source link

Make StateVectors Hashable #728

Closed gawebb-dstl closed 1 year ago

gawebb-dstl commented 1 year ago

The most noticable difference would be the change to equals

A small code snippet to display the differences

sv1 = StateVector([1, 2])
sv2 = StateVector([2, 3])
sv3 = StateVector([1, 2])

print(sv1 == sv2)
print(sv1 == sv3)
print(sv1 is sv3)

x = {sv1: 1, sv2: 2, sv3: 3}
print(x[sv1], x[sv2], x[sv3])
sdhiscocks commented 1 year ago

One requirement of hashable objects in Python, is the hash must never change in it's lifetime. Not easily done with NumPy array. It may be safer in cases where you need hashable state vector, to convert it to a tuple representation.

gawebb-dstl commented 1 year ago

Good point, which I hadn't considered