For example in the randint
signature there is a \*
as 4th argument. What does it mean ?
torch.randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
I am aware of position only args and keyword only args introduced in Python 3.8 which use \
and *
. But here I see \*
.
CodePudding user response:
I was pretty sure user2357112 supports Monica is right. To confirm it, I've tried looking for the source of the documentation, which is autogenerated. I've looked at the implementation, which is in C where functions signatures work differently. I found the type annotation generation code:
'randint': ['def randint(low: _int, high: _int, size: _size, *,'
' generator: Optional[Generator]=None, {}) -> Tensor: ...'
.format(FACTORY_PARAMS),
'def randint(high: _int, size: _size, *,'
' generator: Optional[Generator]=None, {}) -> Tensor: ...'
.format(FACTORY_PARAMS)],
This suggests that the commenter was indeed right, and it should have been *
rather than \*
.
Positional arguments in Python are denoted by /
, not by \
. In Python's syntax \
is only used in two places: as an escape character in string literals, and at the end of a line as an explicit line continuation marker.
It looks like this has been an issue since at least May 2020, with no activity since.