We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9bc779c commit 99a54c3Copy full SHA for 99a54c3
1 file changed
bae/autograd/function.py
@@ -147,6 +147,14 @@ def _convert_to_index_tensor(self, index):
147
return torch.tensor(index)
148
elif isinstance(index, np.ndarray):
149
return torch.from_numpy(index)
150
+
151
+ def __format__(self, format_spec):
152
+ tensor = self.tensor()
153
+ if tensor.numel() == 1:
154
+ return format(tensor.detach().item(), format_spec)
155
+ if format_spec:
156
+ return format(str(tensor), format_spec)
157
+ return str(tensor)
158
159
def tensor(self) -> torch.Tensor:
160
return torch.Tensor.as_subclass(self, torch.Tensor)
0 commit comments