Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8e84d60

Browse files
committed
FEAT: Adding array.scalar()
1 parent 15af431 commit 8e84d60

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎arrayfire/array.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,19 @@ def to_list(self, row_major=False):
12531253
ct_array, shape = self.to_ctype(row_major, True)
12541254
return _ctype_to_lists(ct_array, len(shape) - 1, shape)
12551255

1256+
def scalar(self):
1257+
"""
1258+
Return the first element of the array
1259+
"""
1260+
1261+
if (self.arr.value == 0):
1262+
raise RuntimeError("Can not call to_ctype on empty array")
1263+
1264+
ctype_type = to_c_type[self.type()]
1265+
res = ctype_type()
1266+
safe_call(backend.get().af_get_scalar(c_pointer(res), self.arr))
1267+
return res.value
1268+
12561269
def __str__(self):
12571270
"""
12581271
Converts the arrayfire array to string showing its meta data and contents.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /