From 0abbbaffef8b435bc62a0049a12891bcc9658118 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Wed, 20 Jan 2021 12:42:21 -0600
Subject: [PATCH] Make {Scalar,Vector,Other}Arg hashable

---
 pyopencl/tools.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/pyopencl/tools.py b/pyopencl/tools.py
index 4800b15b..3be95ee2 100644
--- a/pyopencl/tools.py
+++ b/pyopencl/tools.py
@@ -339,6 +339,12 @@ class DtypedArgument(Argument):
                 and self.dtype == other.dtype
                 and self.name == other.name)
 
+    def __hash__(self):
+        return (
+                hash(type(self))
+                ^ hash(self.dtype)
+                ^ hash(self.name))
+
 
 class VectorArg(DtypedArgument):
     def __init__(self, dtype, name, with_offset=False):
@@ -359,6 +365,9 @@ class VectorArg(DtypedArgument):
         return (super().__eq__(other)
                 and self.with_offset == other.with_offset)
 
+    def __hash__(self):
+        return super.__hash__() ^ hash(self.with_offset)
+
 
 class ScalarArg(DtypedArgument):
     def declarator(self):
@@ -373,6 +382,17 @@ class OtherArg(Argument):
     def declarator(self):
         return self.decl
 
+    def __eq__(self, other):
+        return (type(self) == type(other)
+                and self.decl == other.decl
+                and self.name == other.name)
+
+    def __hash__(self):
+        return (
+                hash(type(self))
+                ^ hash(self.decl)
+                ^ hash(self.name))
+
 
 def parse_c_arg(c_arg, with_offset=False):
     for aspace in ["__local", "__constant"]:
-- 
GitLab