Skip to content

Commit 60fc4ac

Browse files
committed
Adding Array.__repr__
1 parent 4a59387 commit 60fc4ac

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

arrayfire/array.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,17 +1018,18 @@ def to_list(self, row_major=False):
10181018

10191019
def __repr__(self):
10201020
"""
1021-
Displays the meta data of the arrayfire array.
1021+
Displays the meta data and contents of the arrayfire array.
10221022
10231023
Note
10241024
----
1025-
Use arrayfire.display(a) to display the contents of the array.
1025+
You can also use af.display(a, pres) to display the contents of the array with better precision.
10261026
"""
1027-
# Having __repr__ directly print things is a bad idea
1028-
# Placeholder for when af_array_to_string is available
1029-
# safe_call(backend.get().af_array_to_string...
1030-
return 'Type: arrayfire.Array()\nShape: %s\nType char: %s' % \
1031-
(self.dims(), to_typecode[self.type()])
1027+
1028+
arr_str = ct.c_char_p(0)
1029+
safe_call(backend.get().af_array_to_string(ct.pointer(arr_str), "", self.arr, 4, True))
1030+
1031+
return 'Type: arrayfire.Array()\nType: %s\n' % \
1032+
(to_typename[self.type()]) + to_str(arr_str)
10321033

10331034
def __array__(self):
10341035
"""

arrayfire/util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,14 @@ def get_version():
115115
Dtype.u64.value : ct.c_ulonglong,
116116
Dtype.c32.value : ct.c_float * 2,
117117
Dtype.c64.value : ct.c_double * 2}
118+
119+
to_typename = {Dtype.f32.value : 'float',
120+
Dtype.f64.value : 'double',
121+
Dtype.b8.value : 'bool',
122+
Dtype.u8.value : 'unsigned char',
123+
Dtype.s32.value : 'int',
124+
Dtype.u32.value : 'unsigned int',
125+
Dtype.s64.value : 'long int',
126+
Dtype.u64.value : 'unsigned long int',
127+
Dtype.c32.value : 'float complex',
128+
Dtype.c64.value : 'double complex'}

0 commit comments

Comments
 (0)