File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -196,9 +196,13 @@ def __setitem__(
196196 self .data [key ] = value
197197
198198 def __bool__ (self ):
199- # TODO: more complete implementation
200- if self .shape == (1 ,) or self .shape == ():
201- return bool (self .data )
199+ if self .shape == () or self .size == 1 :
200+ return bool (self .data .flat [0 ])
201+ # todo: add complete implementation later
202+ raise ValueError (
203+ "The truth value of a View with more than one element is ambiguous. "
204+ "Use a.any() or a.all()"
205+ )
202206
203207 def __len__ (self ) -> int :
204208 """
@@ -542,11 +546,10 @@ def __eq__(self, other):
542546 return equal (self , new_other )
543547
544548 def __hash__ (self ):
545- try :
546- hash_value = hash (self .array )
547- except TypeError :
548- hash_value = hash (self .array .data .tobytes ())
549- return hash_value
549+ # Identity-based hash ensures WeakSet never triggers __eq__ for
550+ # deduplication. View.__eq__ returns a View (not a bool), so
551+ # content-based hash would cause WeakSet.add to call bool(View) → TypeError.
552+ return id (self )
550553
551554 def __index__ (self ) -> int :
552555 return int (self .data [0 ])
@@ -720,8 +723,7 @@ def __mul__(self, other):
720723 return result
721724
722725 def __hash__ (self ):
723- hash_value = hash (self .array )
724- return hash_value
726+ return id (self )
725727
726728
727729def from_numpy (
You can’t perform that action at this time.
0 commit comments