Skip to content

Commit 57b4310

Browse files
committed
Add proper conversion to bool.
1 parent 61fe479 commit 57b4310

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pygpu/gpuarray.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,16 @@ cdef class GpuArray:
16571657
"""
16581658
return pygpu_as_ndarray(self)
16591659

1660+
def __bool__(self):
1661+
if self.ga.nd == 0:
1662+
return True
1663+
if self.ga.nd == 1:
1664+
if self.ga.dimensions[0] == 0:
1665+
return False
1666+
if self.ga.dimensions[0] == 1:
1667+
return bool(numpy.asarray(self))
1668+
raise ValueError('The truth value of a multi-element array is ambiguous')
1669+
16601670
def _empty_like_me(self, dtype=None, order='C'):
16611671
"""
16621672
_empty_like_me(dtype=None, order='C')

0 commit comments

Comments
 (0)