MCPcopy Create free account
hub / github.com/pytorch/pytorch / _tensor_str

Function _tensor_str

torch/_tensor_str.py:302–350  ·  view source on GitHub ↗
(self, indent)

Source from the content-addressed store, hash-verified

300
301
302def _tensor_str(self, indent):
303 if self.numel() == 0:
304 return "[]"
305
306 if self.has_names():
307 # There are two main codepaths (possibly more) that tensor printing goes through:
308 # - tensor data can fit comfortably on screen
309 # - tensor data needs to be summarized
310 # Some of the codepaths don't fully support named tensors, so we send in
311 # an unnamed tensor to the formatting code as a workaround.
312 self = self.rename(None)
313
314 summarize = self.numel() > PRINT_OPTS.threshold
315
316 if self._is_zerotensor():
317 self = self.clone()
318
319 # handle the negative bit
320 if self.is_neg():
321 self = self.resolve_neg()
322
323 if self.dtype in [
324 torch.float16,
325 torch.bfloat16,
326 torch.float8_e5m2,
327 torch.float8_e5m2fnuz,
328 torch.float8_e4m3fn,
329 torch.float8_e4m3fnuz,
330 ]:
331 self = self.float()
332
333 if self.dtype is torch.complex32:
334 self = self.cfloat()
335
336 if self.dtype.is_complex:
337 # handle the conjugate bit
338 self = self.resolve_conj()
339 real_formatter = _Formatter(
340 get_summarized_data(self.real) if summarize else self.real
341 )
342 imag_formatter = _Formatter(
343 get_summarized_data(self.imag) if summarize else self.imag
344 )
345 return _tensor_str_with_formatter(
346 self, indent, summarize, real_formatter, imag_formatter
347 )
348 else:
349 formatter = _Formatter(get_summarized_data(self) if summarize else self)
350 return _tensor_str_with_formatter(self, indent, summarize, formatter)
351
352
353def _add_suffixes(tensor_str, suffixes, indent, force_newline):

Callers 1

_str_internFunction · 0.85

Calls 7

_FormatterClass · 0.85
get_summarized_dataFunction · 0.85
numelMethod · 0.45
renameMethod · 0.45
cloneMethod · 0.45
floatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…