From d3638918db2870a34f9e4d762c6c60eeee8b0e3c Mon Sep 17 00:00:00 2001
From: Daniel Bauer <daniel.j.bauer@fau.de>
Date: Mon, 4 Dec 2023 09:55:06 +0100
Subject: [PATCH] implement __eq__ and __hash__ for RNGBase

---
 pystencils/rng.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/pystencils/rng.py b/pystencils/rng.py
index c75c3f97..6e9bc954 100644
--- a/pystencils/rng.py
+++ b/pystencils/rng.py
@@ -61,6 +61,15 @@ class RNGBase(CustomCodeNode):
         return ", ".join([str(s) for s in self.result_symbols]) + " \\leftarrow " + \
             self._name.capitalize() + "_RNG(" + ", ".join([str(a) for a in self.args]) + ")"
 
+    def _hashable_content(self):
+        return (self._name, *self.result_symbols, *self.args)
+
+    def __eq__(self, other):
+        return type(self) == type(other) and self._hashable_content() == other._hashable_content()
+
+    def __hash__(self):
+        return hash(self._hashable_content())
+
 
 class PhiloxTwoDoubles(RNGBase):
     _name = "philox_double2"
-- 
GitLab