Skip to content

Commit 58e030a

Browse files
committed
Raise exceptions when calling array.to_* if array is empty
1 parent 14d5bc6 commit 58e030a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arrayfire/array.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ def __setitem__(self, key, val):
453453
raise IndexError(str(e))
454454

455455
def to_ctype(self, row_major=False, return_shape=False):
456+
457+
if (self.arr.value == 0):
458+
raise RuntimeError("Can not call to_ctype on empty array")
459+
456460
tmp = transpose(self) if row_major else self
457461
ctype_type = to_c_type[self.type()] * self.elements()
458462
res = ctype_type()
@@ -463,6 +467,10 @@ def to_ctype(self, row_major=False, return_shape=False):
463467
return res
464468

465469
def to_array(self, row_major=False, return_shape=False):
470+
471+
if (self.arr.value == 0):
472+
raise RuntimeError("Can not call to_array on empty array")
473+
466474
res = self.to_ctype(row_major, return_shape)
467475

468476
host = __import__("array")

0 commit comments

Comments
 (0)