dubeya
(Abhimanyu Dubey)
May 1, 2017, 4:01pm
#1
Hey guys,

I’ve been trying to play around with some gradients and came across an error while running this command:

```
return torch.inverse(torch.mm(x, x.t()))
```

This gave me the error:
TypeError: Type Variable doesn’t implement stateless method inverse

Is there an issue with my syntax, or is the inverse not implemented? Thanks!

Abhimanyu

`torch.inverse`

takes tensor as an argument not Variable. You can get tensor out of a Variable using `.data`

1 Like

dubeya
(Abhimanyu Dubey)
May 1, 2017, 7:18pm
#3
Thanks! I will try it out, however I need it to be differentiable. Will converting it to a tensor preserve the gradients?

dubeya
(Abhimanyu Dubey)
May 1, 2017, 7:31pm
#4
Hey, I tried your suggestion - doesn’t work. The .data call is:
`return torch.inverse(torch.mm(x, x.t()).data)`

And I get the error:
`AttributeError: 'FloatTensor' object has no attribute 'data'`

fmassa
(Francisco Massa)
May 1, 2017, 11:31pm
#5
The gradient of the inverse is not implemented, and apparently won’t be implemented in the nearby future, see https://github.com/pytorch/pytorch/issues/440

1 Like

That’s what the error was suggesting but apparently torch.mm returns a tensor and not a variable.
I don’t know why are you getting an error in the first place cuz I tried following code and it didn’t give any error:

`mat1 = torch.randn(3, 3)`

`torch.inverse(torch.mm(mat1, mat1.t()))`

smth
May 2, 2017, 3:03pm
#7
@Rinku_Jadhav2014 in his code snippet, x is a Variable

dubeya
(Abhimanyu Dubey)
May 2, 2017, 4:39pm
#8
Thanks for the link @fmassa ! In my case, all eigenvalues of the variable are going to be <1 without exception, so I’ll just approximate the inverse with a power series I think.