MCPcopy
hub / github.com/numpy/numpy / fillFormat

Method fillFormat

numpy/_core/arrayprint.py:1013–1102  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

1011 self.fillFormat(data)
1012
1013 def fillFormat(self, data):
1014 # only the finite values are used to compute the number of digits
1015 finite_vals = data[isfinite(data)]
1016
1017 # choose exponential mode based on the non-zero finite values:
1018 abs_non_zero = absolute(finite_vals[finite_vals != 0])
1019 if len(abs_non_zero) != 0:
1020 max_val = np.max(abs_non_zero)
1021 min_val = np.min(abs_non_zero)
1022 if self._legacy <= 202:
1023 exp_cutoff_max = 1.e8
1024 else:
1025 # consider data type while deciding the max cutoff for exp format
1026 exp_cutoff_max = 10.**min(8, np.finfo(data.dtype).precision)
1027 with errstate(over='ignore'): # division can overflow
1028 if max_val >= exp_cutoff_max or (not self.suppress_small and
1029 (min_val < 0.0001 or max_val / min_val > 1000.)):
1030 self.exp_format = True
1031
1032 # do a first pass of printing all the numbers, to determine sizes
1033 if len(finite_vals) == 0:
1034 self.pad_left = 0
1035 self.pad_right = 0
1036 self.trim = '.'
1037 self.exp_size = -1
1038 self.unique = True
1039 self.min_digits = None
1040 elif self.exp_format:
1041 trim, unique = '.', True
1042 if self.floatmode == 'fixed' or self._legacy <= 113:
1043 trim, unique = 'k', False
1044 strs = (dragon4_scientific(x, precision=self.precision,
1045 unique=unique, trim=trim, sign=self.sign == '+')
1046 for x in finite_vals)
1047 frac_strs, _, exp_strs = zip(*(s.partition('e') for s in strs))
1048 int_part, frac_part = zip(*(s.split('.') for s in frac_strs))
1049 self.exp_size = max(len(s) for s in exp_strs) - 1
1050
1051 self.trim = 'k'
1052 self.precision = max(len(s) for s in frac_part)
1053 self.min_digits = self.precision
1054 self.unique = unique
1055
1056 # for back-compat with np 1.13, use 2 spaces & sign and full prec
1057 if self._legacy <= 113:
1058 self.pad_left = 3
1059 else:
1060 # this should be only 1 or 2. Can be calculated from sign.
1061 self.pad_left = max(len(s) for s in int_part)
1062 # pad_right is only needed for nan length calculation
1063 self.pad_right = self.exp_size + 2 + self.precision
1064 else:
1065 trim, unique = '.', True
1066 if self.floatmode == 'fixed':
1067 trim, unique = 'k', False
1068 strs = (dragon4_positional(x, precision=self.precision,
1069 fractional=True,
1070 unique=unique, trim=trim,

Callers 1

__init__Method · 0.95

Calls 10

errstateClass · 0.85
anyFunction · 0.85
splitMethod · 0.80
lstripMethod · 0.80
minFunction · 0.70
maxFunction · 0.70
maxMethod · 0.45
minMethod · 0.45
partitionMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected