12
12
"""
13
13
14
14
import inspect
15
+ import os
15
16
from .library import *
16
17
from .util import *
17
18
from .util import _is_number
20
21
from .index import *
21
22
from .index import _Index4
22
23
24
+ _is_running_in_py_charm = "PYCHARM_HOSTED" in os .environ
25
+
26
+ _display_dims_limit = None
27
+
28
+ def set_display_dims_limit (* dims ):
29
+ """
30
+ Sets the dimension limit after which array's data won't get
31
+ presented to the result of str(arr).
32
+
33
+ Default is None, which means there is no limit.
34
+
35
+ Parameters
36
+ ----------
37
+ *dims : dimension limit args
38
+
39
+ Example
40
+ -------
41
+ set_display_dims_limit(10, 10, 10, 10)
42
+
43
+ """
44
+ global _display_dims_limit
45
+ _display_dims_limit = dims
46
+
47
+ def get_display_dims_limit ():
48
+ """
49
+ Gets the dimension limit after which array's data won't get
50
+ presented to the result of str(arr).
51
+
52
+ Default is None, which means there is no limit.
53
+
54
+ Returns
55
+ -----------
56
+ - tuple of the current limit
57
+ - None is there is no limit
58
+
59
+ Example
60
+ -------
61
+ get_display_dims_limit()
62
+ # None
63
+ set_display_dims_limit(10, 10, 10, 10)
64
+ get_display_dims_limit()
65
+ # (10, 10, 10, 10)
66
+
67
+ """
68
+ return _display_dims_limit
69
+
70
+ def _in_display_dims_limit (dims ):
71
+ if _is_running_in_py_charm :
72
+ return False
73
+ print (_display_dims_limit )
74
+ 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 ):
77
+ if dims [i ] > _display_dims_limit [i ]:
78
+ return False
79
+ return True
80
+
23
81
def _create_array (buf , numdims , idims , dtype , is_device ):
24
82
out_arr = c_void_ptr_t (0 )
25
83
c_dims = dim4 (idims [0 ], idims [1 ], idims [2 ], idims [3 ])
@@ -1185,7 +1243,7 @@ def to_list(self, row_major=False):
1185
1243
ct_array , shape = self .to_ctype (row_major , True )
1186
1244
return _ctype_to_lists (ct_array , len (shape ) - 1 , shape )
1187
1245
1188
- def to_string (self ):
1246
+ def __str__ (self ):
1189
1247
"""
1190
1248
Converts the arrayfire array to string showing its meta data and contents.
1191
1249
@@ -1194,6 +1252,9 @@ def to_string(self):
1194
1252
You can also use af.display(a, pres) to display the contents of the array with better precision.
1195
1253
"""
1196
1254
1255
+ if not _in_display_dims_limit (self .dims ()):
1256
+ return self .__repr__ ();
1257
+
1197
1258
arr_str = c_char_ptr_t (0 )
1198
1259
be = backend .get ()
1199
1260
safe_call (be .af_array_to_string (c_pointer (arr_str ), "" , self .arr , 4 , True ))
0 commit comments