Skip to content

Commit 3f616ee

Browse files
committed
FEAT: Adding .as_type method to Array class
1 parent 3c4bfcd commit 3f616ee

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

arrayfire/array.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,15 @@ def __init__(self, src=None, dims=(0,), dtype=None, is_device=False):
423423
idims[n] = dims[n]
424424
self.arr = _create_empty_array(numdims, idims, to_dtype[type_char])
425425

426+
def as_type(self, ty):
427+
"""
428+
Cast current array to a specified data type
429+
430+
Parameters
431+
----------
432+
ty : Return data type
433+
"""
434+
return cast(self, ty)
426435

427436
def copy(self):
428437
"""
@@ -1134,3 +1143,4 @@ def read_array(filename, index=None, key=None):
11341143
return out
11351144

11361145
from .algorithm import sum
1146+
from .arith import cast

tests/simple/array_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def simple_array(verbose=False):
1818

1919
a = af.Array([1, 2, 3])
2020
display_func(a)
21+
22+
b = a.as_type(af.Dtype.s32)
23+
display_func(b)
24+
2125
print_func(a.elements(), a.type(), a.dims(), a.numdims())
2226
print_func(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
2327
print_func(a.is_complex(), a.is_real(), a.is_double(), a.is_single())

0 commit comments

Comments
 (0)