I am trying to modify the gradient of a tensor in torch for R:
library(torch)
x <- torch_randn(10,2)
x$grad <- torch_randn(10,2)
However, I get the following error:
Erreur dans f(value) : argument inutilisé (value)
2: `$<-.R7`(`*tmp*`, grad, value = <pointer: 0x55cd40aefae0>)
1: `$<-`(`*tmp*`, grad, value = <pointer: 0x55cd40aefae0>)
I thought I was doing something wrong (gradients are a little bit tricky sometimes), but when I try the same thing in python it works just fine:
import torch
x = torch.randn(10,2)
x.grad = torch.randn(10,2)
When I call x$grad in R, I get [ Tensor (undefined) ], but this should not be a problem since it works fine in python.
Thanks.