-
I have never seen an argument is written like this for a function.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @Reetos, Good question! I answered a similar question here: #360 (comment) But I'll paste it here too (because the question is similar): Those are called "type annotations" or "type hints" in Python. def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.weights * x + self.bias The And the Type hints/annotations are helpful for when you'd like to know the inputs/outputs of your code/functions. They don't necessarily return errors but when looking up documentation for what code does, the type annotation/hint shows you what the code is expecting as input/output. You can see more here: https://realpython.com/python-type-checking/ |
Beta Was this translation helpful? Give feedback.
Hi @Reetos,
Good question!
I answered a similar question here: #360 (comment)
But I'll paste it here too (because the question is similar):
Those are called "type annotations" or "type hints" in Python.
The
x: torch.Tensor
means that theforward()
method is expectingx
to be of typetorch.Tensor
.And the
-> torch.Tensor
means that theforward()
method returns atorch.Tensor
too.Type hints/annotations are helpful for when you'd like to know the inputs/outputs of your code/functions.
They don't necessarily return errors but when looking up documentation for what code does, the type annotation/hint s…