Skip to content

Commit b0fa998

Browse files
dpctl.tensor.Device.__eq__ and .__hash__ special methods added.
Array API's Device object must support __eq__ special method. Addition of __hash__ also allows to use Device object instances as keys in dictionaries.
1 parent 949711e commit b0fa998

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

dpctl/tensor/_device.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ def wait(self):
124124
"""
125125
self.sycl_queue_.wait()
126126

127+
def __eq__(self, other):
128+
"""Equality comparison based on underlying ``sycl_queue``."""
129+
if isinstance(other, Device):
130+
return self.sycl_queue.__eq__(other.sycl_queue)
131+
elif isinstance(other, dpctl.SyclQueue):
132+
return self.sycl_queue.__eq__(other)
133+
return False
134+
135+
def __hash__(self):
136+
"""Compute object's hash value."""
137+
return self.sycl_queue.__hash__()
138+
127139

128140
def normalize_queue_device(sycl_queue=None, device=None):
129141
"""

0 commit comments

Comments
 (0)