obj = t(100, 100).fill_(1)
obj.__repr__()
str(obj)
+ # test half tensor
+ obj = torch.rand(100, 100, device='cpu').half()
+ obj.__repr__()
+ str(obj)
for t in torch._storage_classes:
if t.is_cuda and not torch.cuda.is_available():
continue
self.assertEqual(x.__repr__(), str(x))
self.assertExpectedInline(str(x), '''tensor([0., 0., 0., ..., 0., 0., 0.])''')
+ # test internal summary function
+ x = torch.rand(1, 20, 5, 30)
+ summary = torch._tensor_str.get_summarized_data(x)
+ self.assertEqual(summary.shape, (1, 6, 5, 6))
+ first_and_last = [0, 1, 2, -3, -2, -1]
+ self.assertEqual(summary, x[:, first_and_last][..., first_and_last])
+
# test device
if torch.cuda.is_available():
x = torch.tensor([123], device='cuda:0')
return '[]'
summarize = self.numel() > PRINT_OPTS.threshold
+ if self.dtype is torch.float16:
+ self = self.float()
formatter = _Formatter(get_summarized_data(self) if summarize else self)
return _tensor_str_with_formatter(self, indent, formatter, summarize)
else:
return self
if self.size(0) > 2 * PRINT_OPTS.edgeitems:
- start = [get_summarized_data(self[i]).reshape(-1) for i in range(0, PRINT_OPTS.edgeitems)]
- end = ([get_summarized_data(self[i]).reshape(-1)
+ start = [self[i] for i in range(0, PRINT_OPTS.edgeitems)]
+ end = ([self[i]
for i in range(len(self) - PRINT_OPTS.edgeitems, len(self))])
- return torch.cat((start + end))
+ return torch.stack([get_summarized_data(x) for x in (start + end)])
else:
- return self
+ return torch.stack([get_summarized_data(x) for x in self])
def _str(self):