MCPcopy Create free account
hub / github.com/numpy/numpy / fillFormat

Method fillFormat

numpy/core/arrayprint.py:934–1016  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

932 self.fillFormat(data)
933
934 def fillFormat(self, data):
935 # only the finite values are used to compute the number of digits
936 finite_vals = data[isfinite(data)]
937
938 # choose exponential mode based on the non-zero finite values:
939 abs_non_zero = absolute(finite_vals[finite_vals != 0])
940 if len(abs_non_zero) != 0:
941 max_val = np.max(abs_non_zero)
942 min_val = np.min(abs_non_zero)
943 with errstate(over='ignore'): # division can overflow
944 if max_val >= 1.e8 or (not self.suppress_small and
945 (min_val < 0.0001 or max_val/min_val > 1000.)):
946 self.exp_format = True
947
948 # do a first pass of printing all the numbers, to determine sizes
949 if len(finite_vals) == 0:
950 self.pad_left = 0
951 self.pad_right = 0
952 self.trim = '.'
953 self.exp_size = -1
954 self.unique = True
955 self.min_digits = None
956 elif self.exp_format:
957 trim, unique = '.', True
958 if self.floatmode == 'fixed' or self._legacy <= 113:
959 trim, unique = 'k', False
960 strs = (dragon4_scientific(x, precision=self.precision,
961 unique=unique, trim=trim, sign=self.sign == '+')
962 for x in finite_vals)
963 frac_strs, _, exp_strs = zip(*(s.partition('e') for s in strs))
964 int_part, frac_part = zip(*(s.split('.') for s in frac_strs))
965 self.exp_size = max(len(s) for s in exp_strs) - 1
966
967 self.trim = 'k'
968 self.precision = max(len(s) for s in frac_part)
969 self.min_digits = self.precision
970 self.unique = unique
971
972 # for back-compat with np 1.13, use 2 spaces & sign and full prec
973 if self._legacy <= 113:
974 self.pad_left = 3
975 else:
976 # this should be only 1 or 2. Can be calculated from sign.
977 self.pad_left = max(len(s) for s in int_part)
978 # pad_right is only needed for nan length calculation
979 self.pad_right = self.exp_size + 2 + self.precision
980 else:
981 trim, unique = '.', True
982 if self.floatmode == 'fixed':
983 trim, unique = 'k', False
984 strs = (dragon4_positional(x, precision=self.precision,
985 fractional=True,
986 unique=unique, trim=trim,
987 sign=self.sign == '+')
988 for x in finite_vals)
989 int_part, frac_part = zip(*(s.split('.') for s in strs))
990 if self._legacy <= 113:
991 self.pad_left = 1 + max(len(s.lstrip('-+')) for s in int_part)

Callers 1

__init__Method · 0.95

Calls 12

dragon4_scientificFunction · 0.90
dragon4_positionalFunction · 0.90
isfiniteFunction · 0.85
errstateClass · 0.85
isinfFunction · 0.85
lstripMethod · 0.80
maxFunction · 0.70
anyFunction · 0.70
maxMethod · 0.45
minMethod · 0.45
partitionMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected