Change:
It seems that the following link that can be reached from here (check the screenshot) is broken: Page: Broken link: Screenshot: ! cc
this should be transferred to , but I don't have permissions to do that. Fix is available at pytorch/hub.

Discussion:
from .serialization import save, load <ins> from ._tensor_str import set_printoptions </ins> ################################################################################ # Define Storage and Tensor classes

from functools import reduce from ._utils import _range <ins> class __PrinterOptions(object): precision = 4 threshold = 1000 edgeitems = 3 linewidth = 80 PRINT_OPTS = __PrinterOptions() </ins> SCALE_FORMAT = '{:.5e} *n' <del> def _number_format(tensor): min_sz = 2 </del> <ins> # We could use **kwargs, but this will give better docs def set_printoptions( precision=None, threshold=None, edgeitems=None, linewidth=None, profile=None, ): """Set options for printing. Items shamelessly taken from Numpy Args: precision: Number of digits of precision for floating point output (default 8). threshold: Total number of array elements which trigger summarization rather than full repr (default 1000). edgeitems: Number of array items in summary at beginning and end of each dimension (default 3). linewidth: The number of characters per line for the purpose of inserting line breaks (default 80). Thresholded matricies will ignore this parameter. profile: Sane defaults for pretty printing. Can override with any of the above options. (default, short, full) """ if profile is not None: if profile == "default": PRINT_OPTS.precision = 4 PRINT_OPTS.threshold = 1000 PRINT_OPTS.edgeitems = 3 PRINT_OPTS.linewidth = 80 elif profile == "short": PRINT_OPTS.precision = 2 PRINT_OPTS.threshold = 1000 PRINT_OPTS.edgeitems = 2 PRINT_OPTS.linewidth = 80 elif profile == "full": PRINT_OPTS.precision = 4 PRINT_OPTS.threshold = float('inf') PRINT_OPTS.edgeitems = 3 PRINT_OPTS.linewidth = 80 if precision is not None: PRINT_OPTS.precision = precision if threshold is not None: PRINT_OPTS.threshold = threshold if edgeitems is not None: PRINT_OPTS.edgeitems = edgeitems if linewidth is not None: PRINT_OPTS.linewidth = linewidth def _number_format(tensor, min_sz=-1): min_sz = max(min_sz, 2) </ins> tensor = torch.DoubleTensor(tensor.nelement()).copy_(tensor).abs_() pos_inf_mask = tensor.eq(float('inf'))

example_value = tensor[invalid_value_mask.eq(0)][0] tensor[invalid_value_mask] = example_value if invalid_value_mask.any(): <del> min_sz = 3 </del> <ins> min_sz = max(min_sz, 3) </ins> int_mode = True # TODO: use fmod?

scale = 1 exp_max = int(exp_max) <ins> prec = PRINT_OPTS.precision </ins> if int_mode: <del> if exp_max > 9: format = '{:11.4e}' sz = max(min_sz, 11) </del> <ins> if exp_max > prec + 1: format = '{{:11.{}e}}'.format(prec) sz = max(min_sz, 7 + prec) </ins> else: sz = max(min_sz, exp_max + 1) format = '{:' + str(sz) + '.0f}' else: <del> if exp_max - exp_min > 4: sz = 11 </del> <ins> if exp_max - exp_min > prec: sz = 7 + prec </ins> if abs(exp_max) > 99 or abs(exp_min) > 99: sz = sz + 1 sz = max(min_sz, sz) <del> format = '{:' + str(sz) + '.4e}' </del> <ins> format = '{{:{}.{}e}}'.format(sz, prec) </ins> else: <del> if exp_max > 5 or exp_max < 0: </del> <ins> if exp_max > prec + 1 or exp_max < 0: </ins> sz = max(min_sz, 7) scale = math.pow(10, exp_max-1) else:

else: sz = exp_max + 6 sz = max(min_sz, sz) <del> format = '{:' + str(sz) + '.4f}' </del> <ins> format = '{{:{}.{}f}}'.format(sz, prec) </ins> return format, scale, sz def _tensor_str(self): <ins> n = PRINT_OPTS.edgeitems has_hdots = self.size()[-1] > 2*n has_vdots = self.size()[-2] > 2*n print_full_mat = not has_hdots and not has_vdots formatter = _number_format(self, min_sz=3 if not print_full_mat else 0) print_dots = self.numel() >= PRINT_OPTS.threshold dim_sz = max(2, max(len(str(x)) for x in self.size())) dim_fmt = "{:^" + str(dim_sz) + "}" dot_fmt = u"{:^" + str(dim_sz+1) + "}" </ins> counter_dim = self.ndimension() - 2 counter = torch.LongStorage(counter_dim).fill_(0) <del> counter[0] = -1 </del> <ins> counter[counter.size()-1] = -1 </ins> finished = False strt = '' while True: <del> for i in _range(counter_dim): </del> <ins> nrestarted = [False for i in counter] nskipped = [False for i in counter] for i in _range(counter_dim - 1, -1, -1): </ins> counter[i] += 1 <ins> if print_dots and counter[i] == n and self.size(i) > 2*n: counter[i] = self.size(i) - n nskipped[i] = True </ins> if counter[i] == self.size(i): <del> if i == counter_dim-1: </del> <ins> if i == 0: </ins> finished = True counter[i] = 0 <ins> nrestarted[i] = True </ins> else: break if finished: break <ins> elif print_dots: if any(nskipped): for hdot in nskipped: strt += dot_fmt.format('...') if hdot  else dot_fmt.format('') strt += 'n' if any(nrestarted): strt += ' ' for vdot in nrestarted: strt += dot_fmt.format(u'u22EE' if vdot else '') strt += 'n' </ins> if strt != '': <del> strt += 'n' strt += '({},.,.) = n'.format(','.join(str(i) for i in counter)) submatrix = reduce(lambda t,i: t.select(0, i), counter, self) strt += _matrix_str(submatrix, ' ') </del> <ins> strt += 'n' strt += '({},.,.) = n'.format( ','.join(dim_fmt.format(i) for i in counter)) submatrix = reduce(lambda t, i: t.select(0, i), counter, self) strt += _matrix_str(submatrix, ' ', formatter, print_dots) </ins> return strt <del> def _matrix_str(self, indent=''): fmt, scale, sz = _number_format(self) nColumnPerLine = int(math.floor((80-len(indent))/(sz+1))) </del> <ins> def __repr_row(row, indent, fmt, scale, sz, truncate=None): if truncate is not None: dotfmt = " {:^5} " return (indent + ' '.join(fmt.format(val/scale) for val in row[:truncate]) + dotfmt.format('...') + ' '.join(fmt.format(val/scale) for val in row[-truncate:]) + 'n') else: return indent + ' '.join(fmt.format(val/scale) for val in row) + 'n' def _matrix_str(self, indent='', formatter=None, force_truncate=False): n = PRINT_OPTS.edgeitems has_hdots = self.size(1) > 2*n has_vdots = self.size(0) > 2*n print_full_mat = not has_hdots and not has_vdots if formatter is None: fmt, scale, sz = _number_format(self, min_sz=5 if not print_full_mat else 0) else: fmt, scale, sz = formatter nColumnPerLine = int(math.floor((PRINT_OPTS.linewidth-len(indent))/(sz+1))) </ins> strt = '' firstColumn = 0 <del> while firstColumn < self.size(1): lastColumn = min(firstColumn + nColumnPerLine - 1, self.size(1)-1) if nColumnPerLine < self.size(1): strt += 'n' if firstColumn != 1 else '' strt += 'Columns {} to {} n{}'.format(firstColumn, lastColumn, indent) </del> <ins> if not force_truncate and  (self.numel() < PRINT_OPTS.threshold or print_full_mat): while firstColumn < self.size(1): lastColumn = min(firstColumn + nColumnPerLine - 1, self.size(1)-1) if nColumnPerLine < self.size(1): strt += 'n' if firstColumn != 1 else '' strt += 'Columns {} to {} n{}'.format( firstColumn, lastColumn, indent) if scale != 1: strt += SCALE_FORMAT.format(scale) for l in _range(self.size(0)): strt += indent + (' ' if scale != 1 else '') row_slice = self[l, firstColumn:lastColumn+1] strt += ' '.join(fmt.format(val/scale) for val in row_slice) strt += 'n' firstColumn = lastColumn + 1 else: </ins> if scale != 1: strt += SCALE_FORMAT.format(scale) <del> for l in _range(self.size(0)): strt += indent + (' ' if scale != 1 else '') row_slice = self[l, firstColumn:lastColumn+1] strt += ' '.join(fmt.format(val/scale) for val in row_slice) + 'n' firstColumn = lastColumn + 1 </del> <ins> if has_vdots and has_hdots: vdotfmt = "{:^" + str((sz+1)*n-1) + "}" ddotfmt = u"{:^5}" for row in self[:n]: strt += __repr_row(row, indent, fmt, scale, sz, n) strt += indent + ' '.join([vdotfmt.format('...'), ddotfmt.format(u'u22F1'), vdotfmt.format('...')]) + "n" for row in self[-n:]: strt += __repr_row(row, indent, fmt, scale, sz, n) elif not has_vdots and has_hdots: for row in self: strt += __repr_row(row, indent, fmt, scale, sz, n) elif has_vdots and not has_hdots: vdotfmt = u"{:^" +  str(len(__repr_row(self[0], '', fmt, scale, sz))) +  "}n" for row in self[:n]: strt += __repr_row(row, indent, fmt, scale, sz) strt += vdotfmt.format(u'u22EE') for row in self[-n:]: strt += __repr_row(row, indent, fmt, scale, sz) else: for row in self: strt += __repr_row(row, indent, fmt, scale, sz) </ins> return strt def _vector_str(self): <del> fmt, scale, _ = _number_format(self) </del> <ins> fmt, scale, sz = _number_format(self) </ins> strt = '' ident = '' <ins> n = PRINT_OPTS.edgeitems dotfmt = u"{:^" + str(sz) + "}n" </ins> if scale != 1: strt += SCALE_FORMAT.format(scale) ident = ' ' <del> return strt + 'n'.join(ident + fmt.format(val/scale) for val in self) + 'n' </del> <ins> if self.numel() < PRINT_OPTS.threshold: return (strt + 'n'.join(ident + fmt.format(val/scale) for val in self) + 'n') else: return (strt + 'n'.join(ident + fmt.format(val/scale) for val in self[:n]) + 'n' + (ident + dotfmt.format(u"u22EE")) + 'n'.join(ident + fmt.format(val/scale) for val in self[-n:]) + 'n') </ins> def _str(self):

strt = _tensor_str(self) size_str = 'x'.join(str(size) for size in self.size()) <del> device_str = '' if not self.is_cuda else ' (GPU {})'.format(self.get_device()) </del> <ins> device_str = '' if not self.is_cuda else  ' (GPU {})'.format(self.get_device()) </ins> strt += '[{} of size {}{}]n'.format(torch.typename(self), <del> size_str, device_str) </del> <ins> size_str, device_str) </ins> return 'n' + strt

from ._utils import _type, _cuda, _range from functools import reduce from itertools import chain <ins> import sys </ins> import math

return type(self), (self.tolist(),) def __repr__(self): <del> return str(self) </del> <ins> return repr(str(self)) </ins> def __str__(self): <del> return _tensor_str._str(self) </del> <ins> # All strings are unicode in Python 3, while we have to encode unicode # strings in Python2. If we can't, let python decide the best # characters to replace unicode characters with. if sys.version_info > (3,): return _tensor_str._str(self) else: return _tensor_str._str(self).encode( sys.stdout.encoding or 'UTF-8', 'replace') </ins> def __iter__(self): return iter(map(lambda i: self.select(0, i), _range(self.size(0))))