From 8c124aded2d316bb6da3a271eb7cd74f59f2a1c8 Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Mon, 29 Oct 2018 10:46:46 +0100
Subject: [PATCH] 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
---
 field.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/field.py b/field.py
index c7e514dfa..7422f1dbe 100644
--- a/field.py
+++ b/field.py
@@ -379,15 +379,16 @@ class Field:
         center = tuple([0] * self.spatial_dimensions)
         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):
-        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):
         if not isinstance(other, Field):
             return False
-        self_tuple = (self.shape, self.strides, self.name, self.dtype, self.field_type)
-        other_tuple = (other.shape, other.strides, other.name, other.dtype, other.field_type)
-        return self_tuple == other_tuple
+        return self.hashable_contents() == other.hashable_contents()
 
     PREFIX = "f"
     STRIDE_PREFIX = PREFIX + "stride_"
@@ -457,6 +458,7 @@ class Field:
                     obj._offsets.append(o)
                 else:
                     obj._offsets.append(int(o))
+            obj._offsets = tuple(obj._offsets)
             obj._offsetName = offset_name
             obj._superscript = superscript
             obj._index = idx
@@ -507,7 +509,7 @@ class Field:
         @property
         def offsets(self) -> Tuple:
             """Spatial offset as tuple"""
-            return tuple(self._offsets)
+            return self._offsets
 
         @property
         def required_ghost_layers(self) -> int:
@@ -584,9 +586,8 @@ class Field:
             return self._indirect_addressing_fields
 
         def _hashable_content(self):
-            super_class_contents = list(super(Field.Access, self)._hashable_content())
-            t = tuple(super_class_contents + [id(self._field), self._index] + self._offsets)
-            return t
+            super_class_contents = super(Field.Access, self)._hashable_content()
+            return (super_class_contents, self._field.hashable_contents(), *self._index, *self._offsets)
 
         def _latex(self, _):
             n = self._field.latex_name if self._field.latex_name else self._field.name
-- 
GitLab