Commit 8c124ade authored by Martin Bauer's avatar Martin Bauer
Browse files

Fix field and field access equality problem

- field access are now equal if their underlying fields compare as equal
  not only if the id of their fields are equal
parent 01cc1db2
...@@ -379,15 +379,16 @@ class Field: ...@@ -379,15 +379,16 @@ class Field:
center = tuple([0] * self.spatial_dimensions) center = tuple([0] * self.spatial_dimensions)
return Field.Access(self, center)(*args, **kwargs) return Field.Access(self, center)(*args, **kwargs)
def hashable_contents(self):
return self._layout, self.shape, self.strides, hash(self._dtype), self.field_type, self._field_name
def __hash__(self): def __hash__(self):
return hash((self._layout, self.shape, self.strides, self._dtype, self.field_type, self._field_name)) return hash(self.hashable_contents())
def __eq__(self, other): def __eq__(self, other):
if not isinstance(other, Field): if not isinstance(other, Field):
return False return False
self_tuple = (self.shape, self.strides, self.name, self.dtype, self.field_type) return self.hashable_contents() == other.hashable_contents()
other_tuple = (other.shape, other.strides, other.name, other.dtype, other.field_type)
return self_tuple == other_tuple
PREFIX = "f" PREFIX = "f"
STRIDE_PREFIX = PREFIX + "stride_" STRIDE_PREFIX = PREFIX + "stride_"
...@@ -457,6 +458,7 @@ class Field: ...@@ -457,6 +458,7 @@ class Field:
obj._offsets.append(o) obj._offsets.append(o)
else: else:
obj._offsets.append(int(o)) obj._offsets.append(int(o))
obj._offsets = tuple(obj._offsets)
obj._offsetName = offset_name obj._offsetName = offset_name
obj._superscript = superscript obj._superscript = superscript
obj._index = idx obj._index = idx
...@@ -507,7 +509,7 @@ class Field: ...@@ -507,7 +509,7 @@ class Field:
@property @property
def offsets(self) -> Tuple: def offsets(self) -> Tuple:
"""Spatial offset as tuple""" """Spatial offset as tuple"""
return tuple(self._offsets) return self._offsets
@property @property
def required_ghost_layers(self) -> int: def required_ghost_layers(self) -> int:
...@@ -584,9 +586,8 @@ class Field: ...@@ -584,9 +586,8 @@ class Field:
return self._indirect_addressing_fields return self._indirect_addressing_fields
def _hashable_content(self): def _hashable_content(self):
super_class_contents = list(super(Field.Access, self)._hashable_content()) super_class_contents = super(Field.Access, self)._hashable_content()
t = tuple(super_class_contents + [id(self._field), self._index] + self._offsets) return (super_class_contents, self._field.hashable_contents(), *self._index, *self._offsets)
return t
def _latex(self, _): def _latex(self, _):
n = self._field.latex_name if self._field.latex_name else self._field.name n = self._field.latex_name if self._field.latex_name else self._field.name
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment