Skip to content

torch.meshgrid is divergent from np.meshgrid #50276

@mruberry

Description

@mruberry

PyTorch's torch.meshgrid is divergent from NumPy's np.meshgrid. The documentation for these functions is very hard to parse, so I am not sure if this is a bug or not.

Snippet demonstrating the divergence:

nx, ny = (3, 2)
x = np.linspace(0, 1, nx)
y = np.linspace(0, 1, ny)
xv, yv = np.meshgrid(x, y)
xv
: array(
  [[0. , 0.5, 1. ], 
   [0. , 0.5, 1. ]])

xv, yv = torch.meshgrid(torch.from_numpy(x), torch.from_numpy(y))
xv
: tensor(
  [[0.0000, 0.0000],
   [0.5000, 0.5000],
   [1.0000, 1.0000]], dtype=torch.float64)

NumPy's np.meshgrid is a top 100 NumPy function. PyTorch's meshgrid is used hundreds of times within Facebook.

cc @mruberry @rgommers @heitorschueroff

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: deprecationmodule: numpyRelated to numpy support, and also numpy compatibility of our operatorstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions