Skip to content

Possible bug when combining numpy function with Variable()  #1294

@manuelhaussmann

Description

@manuelhaussmann

Pytorch shows the following inconsistent behaviour.

import numpy as np
import torch
from torch.autograd import Variable

1.0 + Variable(torch.ones(1)) 
# returns as expected
# Variable containing:
#  2
# [torch.FloatTensor of size 1]

np.sum(1.0) + Variable(torch.ones(1)) 
# returns an unexpected (depth of array is 32)
# array([[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Variable containing:
#  2
# [torch.FloatTensor of size 1]
# ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], dtype=object)

# Switching their order 
Variable(torch.ones(1)) + np.sum(1.0)
# returns the expected
# Variable containing:
#  2
# [torch.FloatTensor of size 1]

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