Skip to content

Commit 64a3066

Browse files
unbornchikkenpavanky
authored andcommitted
more fixes and improvements
1 parent 9a463cd commit 64a3066

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

arrayfire/array.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ def get_display_dims_limit():
7070
def _in_display_dims_limit(dims):
7171
if _is_running_in_py_charm:
7272
return False
73-
print(_display_dims_limit)
7473
if _display_dims_limit is not None:
75-
min_dim_len = min(len(_display_dims_limit), len(dims))
76-
for i in range(min_dim_len):
74+
limit_len = len(_display_dims_limit)
75+
len = len(dims)
76+
if len > limit_len:
77+
return False
78+
for i in range(len):
7779
if dims[i] > _display_dims_limit[i]:
7880
return False
7981
return True
@@ -1253,16 +1255,9 @@ def __str__(self):
12531255
"""
12541256

12551257
if not _in_display_dims_limit(self.dims()):
1256-
return self.__repr__()
1258+
return self._get_metadata_str()
12571259

1258-
arr_str = c_char_ptr_t(0)
1259-
be = backend.get()
1260-
safe_call(be.af_array_to_string(c_pointer(arr_str), "", self.arr, 4, True))
1261-
py_str = to_str(arr_str)
1262-
safe_call(be.af_free_host(arr_str))
1263-
1264-
return 'arrayfire.Array()\nType: {}\nDims: {}\nData: {}' \
1265-
.format(to_typename[self.type()], str(self.dims()), py_str)
1260+
return self._get_metadata_str(dims=False) + self._as_str()
12661261

12671262
def __repr__(self):
12681263
"""
@@ -1273,8 +1268,19 @@ def __repr__(self):
12731268
You can use af.display(a, pres) to display the contents of the array.
12741269
"""
12751270

1276-
return 'arrayfire.Array()\nType: {}\nDims: {}' \
1277-
.format(to_typename[self.type()], str(self.dims()))
1271+
return self._get_metadata_str()
1272+
1273+
def _get_metadata_str(self, dims=True):
1274+
return 'arrayfire.Array()\nType: {}\n{}' \
1275+
.format(to_typename[self.type()], 'Dims: {}'.format(str(self.dims())) if dims else '')
1276+
1277+
def _as_str(self):
1278+
arr_str = c_char_ptr_t(0)
1279+
be = backend.get()
1280+
safe_call(be.af_array_to_string(c_pointer(arr_str), "", self.arr, 4, True))
1281+
py_str = to_str(arr_str)
1282+
safe_call(be.af_free_host(arr_str))
1283+
return py_str
12781284

12791285
def __array__(self):
12801286
"""

0 commit comments

Comments
 (0)