From e99423d87ee84c3cf83de27097ea59150b03c24f Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sat, 23 Sep 2017 18:56:23 -0500 Subject: [PATCH 1/2] Add an identity check to non-trivial __eq__ implementations. Kernel.__eq__ might be especially useful in conjunction with pytools!4. --- loopy/kernel/__init__.py | 3 +++ loopy/kernel/array.py | 3 +++ loopy/kernel/data.py | 3 +++ loopy/target/__init__.py | 3 +++ 4 files changed, 12 insertions(+) diff --git a/loopy/kernel/__init__.py b/loopy/kernel/__init__.py index 084c37b45..4e2819a82 100644 --- a/loopy/kernel/__init__.py +++ b/loopy/kernel/__init__.py @@ -1474,6 +1474,9 @@ class LoopKernel(ImmutableRecordWithoutPickling): return hash(key_hash.digest()) def __eq__(self, other): + if self is other: + return True + if not isinstance(other, LoopKernel): return False diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index 5d4240b9a..7e3cf9133 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -808,6 +808,9 @@ class ArrayBase(ImmutableRecord): **kwargs) def __eq__(self, other): + if self is other: + return True + from loopy.symbolic import ( is_tuple_of_expressions_equal as istoee, is_expression_equal as isee) diff --git a/loopy/kernel/data.py b/loopy/kernel/data.py index 94b31df12..facb3c9a0 100644 --- a/loopy/kernel/data.py +++ b/loopy/kernel/data.py @@ -480,6 +480,9 @@ class TemporaryVariable(ArrayBase): " scope:%s" % scope_str) def __eq__(self, other): + if self is other: + return True + return ( super(TemporaryVariable, self).__eq__(other) and self.storage_shape == other.storage_shape diff --git a/loopy/target/__init__.py b/loopy/target/__init__.py index 7e307ef8b..42eef5b50 100644 --- a/loopy/target/__init__.py +++ b/loopy/target/__init__.py @@ -60,6 +60,9 @@ class TargetBase(object): key_builder.rec(key_hash, getattr(self, field_name)) def __eq__(self, other): + if self is other: + return True + if type(self) != type(other): return False -- GitLab From 809c49a26345bf2cc678441b42004bb33d3d6345 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sat, 23 Sep 2017 19:04:04 -0500 Subject: [PATCH 2/2] Add an identity check to LazilyUnpicklingListWithEqAndPersistentHashing --- loopy/tools.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/loopy/tools.py b/loopy/tools.py index 1ebbe5c8a..d26fa2ae9 100644 --- a/loopy/tools.py +++ b/loopy/tools.py @@ -537,6 +537,9 @@ class LazilyUnpicklingListWithEqAndPersistentHashing(LazilyUnpicklingList): return self.persistent_hash_key_getter(obj) def __eq__(self, other): + if self is other: + return True + if not isinstance(other, (list, LazilyUnpicklingList)): return NotImplemented -- GitLab