Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions pykokkos/interface/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,13 @@ def __setitem__(
self.data[key] = value

def __bool__(self):
# TODO: more complete implementation
if self.shape == (1,) or self.shape == ():
return bool(self.data)
if self.shape == () or self.size == 1:
return bool(self.data.flat[0])
# todo: add complete implementation later
raise ValueError(
"The truth value of a View with more than one element is ambiguous. "
"Use a.any() or a.all()"
)

def __len__(self) -> int:
"""
Expand Down Expand Up @@ -542,11 +546,7 @@ def __eq__(self, other):
return equal(self, new_other)

def __hash__(self):
try:
hash_value = hash(self.array)
except TypeError:
hash_value = hash(self.array.data.tobytes())
return hash_value
return id(self)

def __index__(self) -> int:
return int(self.data[0])
Expand Down Expand Up @@ -720,8 +720,7 @@ def __mul__(self, other):
return result

def __hash__(self):
hash_value = hash(self.array)
return hash_value
return id(self)


def from_numpy(
Expand Down
Loading