Skip to content

Commit b643f55

Browse files
unbornchikkenpavanky
authored andcommitted
* __repr__ made IDE friendly
* `to_string()` added to have a method for getting the full string representation * memory leak after calling `af_array_to_string` fixed
1 parent 1078dd0 commit b643f55

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ docs/_build/
5555

5656
# PyBuilder
5757
target/
58+
59+
# IDE
60+
.idea
61+
.vscode

arrayfire/array.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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()\nType: {}\nDims: {}\nData: {}' \
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()\nType: %s' % \
1201-
(to_typename[self.type()]) + to_str(arr_str)
1215+
return 'arrayfire.Array()\nType: {}\nDims: {}' \
1216+
.format(to_typename[self.type()], str(self.dims()))
12021217

12031218
def __array__(self):
12041219
"""

0 commit comments

Comments
 (0)