What is the purpose of Python – torch.positive?
From documentation :
torch.positive(input)
→Tensor
Returns
input
. Throws a runtime error if input is a bool tensor.
If it is a tensor, it simply returns input and throws an error, but this is not an effective way to check if the tensor is , nor is bool
it bool
a readable method.
Solution
As if pytorch addedpytorch.positive
in parity with numpy
it has a function of the same name .
Back to your question,positive
is a unary operator that basically multiplies everything by +1
. This is not a particularly useful operation, but it is not the same as negative
symmetry, which multiplies everything by -1
.
>>> import numpy as np
>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.positive(a)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.negative(a)
array([ 0, -1, -2, -3, -4, -5, -6, -7, -8, -9])
So why make a function that effectively returns (a copy) positive
of the array you passed? It can be used to write generic code such asnumpy.positive
numpy.negative
and can be used dynamically based on certain conditions.