Skip to content

Applying torch.log after torch.expand gives incorrect results on CPU #10241

@kharvd

Description

@kharvd

Issue description

torch.expand seems to be not working correctly with torch.log, torch.exp etc on CPU. The exact same code works on CUDA.

Code example

>>> import torch
>>> x = torch.rand(1, 2)
>>> x
tensor([[0.1591, 0.0630]])
>>> y = x.expand(3, -1, -1)
>>> y
tensor([[[0.1591, 0.0630]],

        [[0.1591, 0.0630]],

        [[0.1591, 0.0630]]])
>>> torch.log(x)
tensor([[-1.8385, -2.7643]])
>>> torch.log(y)
tensor([[[  -1.8385,   -2.7643]],

        [[      nan,   67.2355]],

        [[-103.2789,      -inf]]])
>>> torch.exp(y)
tensor([[[1.1724, 1.0650]],

        [[0.0000,    inf]],

        [[1.0000, 1.0000]]])

System Info

PyTorch version: 0.4.1
Is debug build: No
CUDA used to build PyTorch: None

OS: Mac OSX 10.13.3
GCC version: Could not collect
CMake version: version 3.10.0

Python version: 3.6
Is CUDA available: No
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA

Versions of relevant libraries:
[pip] numpy (1.14.3)
[pip] torch (0.4.1)
[pip] torchvision (0.2.1)
[conda] pytorch                   0.4.1           py36_cuda0.0_cudnn0.0_1    pytorch
[conda] torchvision               0.2.1                    py36_1    pytorch

Metadata

Metadata

Assignees

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