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
sign
tensor operator for copying sign of one tensor onto another
#522
Comments
abs
and sign
tensor operators for copying sign of one tensor onto another
We are crucially missing two tensor operations for this: # Get the sign of tensor_a
sign_a = tensor_a.sign()
# Make a new tensor that is the absolute value of tensor_b, multiplied by the sign of tensor_a
output_tensor = tensor_b.abs() * sign_a For missing ops there are workarounds with the existing ops, which I can provide tomorrow after verifying they work on my computer. Stay tuned. I'll leave this issue open and convert to a feature request for |
For now I have done the (very silly): let sign = t.clone() / (t.clone() * t.clone()).sqrt(); although this is not guaranteed to yield elements in Also, I only care about the |
There is no example on how to add code specialized for a backend, but it is possible. The best way to do it is to create another trait The sign function can simply be the following: let sign = t.ones_like().mask_fill(t.lower_elem(0.0), -1.0); |
I guess with the missing ops you could do this: let sign = tensor.ones_like().mask_fill(tensor.lower_elem(0.0), -1.0);
let output_tensor = tensor.powf(2.0).sqrt().mul(sign); Note: I haven't tried it yet myself. |
abs
and sign
tensor operators for copying sign of one tensor onto anothersign
tensor operators for copying sign of one tensor onto another
Linking a related issue here: #506 |
sign
tensor operators for copying sign of one tensor onto anothersign
tensor operator for copying sign of one tensor onto another
This does not account for 0.0 case which should be 0.0 according to PyTorch's implementation |
I need to take tensor
a
, and apply its sign of all of its elements to the elements of tensorb
.There seems to be no autodiff compatible way to do this, although all backends support it AFAIK.
Thank you
The text was updated successfully, but these errors were encountered: