@@ -1185,20 +1185,35 @@ def to_list(self, row_major=False):
11851185 ct_array , shape = self .to_ctype (row_major , True )
11861186 return _ctype_to_lists (ct_array , len (shape ) - 1 , shape )
11871187
1188- def __repr__ (self ):
1188+ def to_string (self ):
11891189 """
1190- Displays the meta data and contents of the arrayfire array .
1190+ Converts the arrayfire array to string showing its meta data and contents .
11911191
11921192 Note
11931193 ----
11941194 You can also use af.display(a, pres) to display the contents of the array with better precision.
11951195 """
11961196
11971197 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+ """
11991214
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 ()) )
12021217
12031218 def __array__ (self ):
12041219 """
0 commit comments