Skip to content

Commit 99a54c3

Browse files
committed
init
1 parent 9bc779c commit 99a54c3

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

bae/autograd/function.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ def _convert_to_index_tensor(self, index):
147147
return torch.tensor(index)
148148
elif isinstance(index, np.ndarray):
149149
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)
150158

151159
def tensor(self) -> torch.Tensor:
152160
return torch.Tensor.as_subclass(self, torch.Tensor)

0 commit comments

Comments
 (0)