Skip to content

Arrays must share the same dtype in meshgrid() #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2021

Conversation

honno
Copy link
Member

@honno honno commented Nov 2, 2021

This PR clarifies that input arrays must share the same dtype.

Allowing mixed dtypes complicates both user expectations and developer implementations for the returned arrays, which is currently outlined as all having the same promoted dtype (differing from both NumPy and PyTorch behaviour). It also does not seem like anyone would use or desire input arrays of mixed dtypes.

>>> x1 = np.arange(5, dtype=np.int32)
>>> x2 = np.arange(5, dtype=np.int64)
>>> out1, out2 = np.meshgrid(x1, x2)
>>> out1.dtype
int32  # same as x1.dtype
>>> out2.dtype
int64  # same as x2.dtype
...
>>> t1 = torch.arange(5, dtype=torch.int32)
>>> t2 = torch.arange(5, dtype=torch.int64)
>>> torch.meshgrid(t1, t2)
RuntimeError: meshgrid expects all tensors to have the same dtype

Copy link
Contributor

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@kgryte kgryte added this to the v2021 milestone Nov 4, 2021
@kgryte kgryte added Maintenance Bug fix, typo fix, or general maintenance. topic: Creation Array creation. labels Nov 4, 2021
@kgryte kgryte merged commit 7c98b00 into data-apis:main Nov 4, 2021
@kgryte
Copy link
Contributor

kgryte commented Nov 4, 2021

Thanks, @honno!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Bug fix, typo fix, or general maintenance. topic: Creation Array creation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants