Skip to content

Can't print tensors with inf or nan #27

@adamlerer

Description

@adamlerer
In [27]: print(torch.FloatTensor(1).fill_(1).div(0))
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-27-811177cb15a4> in <module>()
----> 1 print(torch.FloatTensor(1).fill_(1).div(0))

/home/alerer/anaconda/lib/python2.7/site-packages/torch/Tensor.pyc in __str__(self)
     85
     86     def __str__(self):
---> 87         return TensorPrinting.printTensor(self)
     88
     89     def __iter__(self):

/home/alerer/anaconda/lib/python2.7/site-packages/torch/TensorPrinting.pyc in printTensor(self)
    106         return '[{} with no dimension]\n'.format(torch.typename(self))
    107     elif self.nDimension() == 1:
--> 108         strt = _printVector(self)
    109     elif self.nDimension() == 2:
    110         strt = _printMatrix(self)

/home/alerer/anaconda/lib/python2.7/site-packages/torch/TensorPrinting.pyc in _printVector(tensor)
     96
     97 def _printVector(tensor):
---> 98     fmt, scale, _ = _printformat(tensor.storage())
     99     strt = ''
    100     if scale != 1:

/home/alerer/anaconda/lib/python2.7/site-packages/torch/TensorPrinting.pyc in _printformat(storage)
     25
     26     scale = 1
---> 27     exp_max = int(exp_max)
     28     if int_mode:
     29         if exp_max > 9:

OverflowError: cannot convert float infinity to integer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions