@@ -1185,20 +1185,35 @@ def to_list(self, row_major=False):
1185
1185
ct_array , shape = self .to_ctype (row_major , True )
1186
1186
return _ctype_to_lists (ct_array , len (shape ) - 1 , shape )
1187
1187
1188
- def __repr__ (self ):
1188
+ def to_string (self ):
1189
1189
"""
1190
- Displays the meta data and contents of the arrayfire array .
1190
+ Converts the arrayfire array to string showing its meta data and contents .
1191
1191
1192
1192
Note
1193
1193
----
1194
1194
You can also use af.display(a, pres) to display the contents of the array with better precision.
1195
1195
"""
1196
1196
1197
1197
arr_str = c_char_ptr_t (0 )
1198
- safe_call (backend .get ().af_array_to_string (c_pointer (arr_str ), "" , self .arr , 4 , True ))
1198
+ be = backend .get ()
1199
+ safe_call (be .af_array_to_string (c_pointer (arr_str ), "" , self .arr , 4 , True ))
1200
+ py_str = to_str (arr_str )
1201
+ safe_call (be .af_free_host (arr_str ))
1202
+
1203
+ return 'arrayfire.Array()\n Type: {}\n Dims: {}\n Data: {}' \
1204
+ .format (to_typename [self .type ()], str (self .dims ()), py_str )
1205
+
1206
+ def __repr__ (self ):
1207
+ """
1208
+ Displays the meta data of the arrayfire array.
1209
+
1210
+ Note
1211
+ ----
1212
+ You can use af.display(a, pres) to display the contents of the array.
1213
+ """
1199
1214
1200
- return 'arrayfire.Array()\n Type: %s' % \
1201
- (to_typename [self .type ()]) + to_str ( arr_str )
1215
+ return 'arrayfire.Array()\n Type: {} \n Dims: {}' \
1216
+ . format (to_typename [self .type ()], str ( self . dims ()) )
1202
1217
1203
1218
def __array__ (self ):
1204
1219
"""
0 commit comments