pytorch
38340f59 - randint accept generator=None (#29748)

Commit
5 years ago
randint accept generator=None (#29748) Summary: This PR fixes the inconsistent behavior of `randint`'s `generator=` kwarg. It does not accept `None`, which is inconsistent with how other random functions behave: ``` In [12]: torch.randint(0, 4, size=(2,3), generator=torch.Generator()) Out[12]: tensor([[2, 0, 1], [0, 1, 3]]) In [13]: torch.randint(0, 4, size=(2,3), generator=None) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-13-a6bc6525a1e1> in <module> ----> 1 torch.randint(0, 4, size=(2,3), generator=None) TypeError: randint() received an invalid combination of arguments - got (int, int, generator=NoneType, size=tuple), but expected one of: * (int high, tuple of ints size, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool requires_grad) * (int high, tuple of ints size, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool requires_grad) * (int low, int high, tuple of ints size, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool requires_grad) * (int low, int high, tuple of ints size, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool requires_grad) ``` Other random functions work fine: ``` In [9]: torch.bernoulli(torch.ones(3)) Out[9]: tensor([1., 1., 1.]) In [10]: torch.bernoulli(torch.ones(3), generator=None) Out[10]: tensor([1., 1., 1.]) ``` This PR also documents the `generator=` kwarg, and fixes https://github.com/pytorch/pytorch/issues/29683 since it's a related easy fix. Pull Request resolved: https://github.com/pytorch/pytorch/pull/29748 Differential Revision: D18529951 Pulled By: ezyang fbshipit-source-id: e956cc989decc94e9483fd4a30f9255240d7c07e
Author
Parents
Loading