title: Construct a rotation matrix in Pytorch
body: <p>I want to construct a rotation matrix, which have unknown Eular angles. I want to build some regression solution to find the value of Eular angles. My code is here.</p>
  
  <pre><code>roll = yaw = pitch = torch.randn(1,requires_grad=True)
  RX = torch.tensor([
                  [1, 0, 0],
                  [0, cos(roll), -sin(roll)],
                  [0, sin(roll), cos(roll)]
              ],requires_grad=True)
  RY = torch.tensor([
                  [cos(pitch), 0, sin(pitch)],
                  [0, 1, 0],
                  [-sin(pitch), 0, cos(pitch)]
              ],requires_grad=True)
  RZ = torch.tensor([
                  [cos(yaw), -sin(yaw), 0],
                  [sin(yaw), cos(yaw), 0],
                  [0, 0, 1]
              ],requires_grad=True)
  R = torch.mm(RZ, RY).requires_grad_()
  R = torch.mm(R, RX).requires_grad_()
  R = R.mean().requires_grad_()
  R.backward()
  </code></pre>
  
  <p>Matrix cannot differentiate the Euler angles.
  There isn't any gradient value of matrix. Can anyone fix my problems? Thanks!
  <a href="https://i.stack.imgur.com/wrhFN.png" rel="nofollow noreferrer">debug result</a></p>