If I do affine_params[:, 0] = -1.0 * affine_params[:, 0].clone() instead of affine_params[:, 0] = -1.0 * affine_params[:, 0], the line works. But why? And why is the division working without .clone()?
The other code snippet works when I do
trans_params = trans_params.clone()
trans_matrix = torch.stack([
    trans_params[:, 1] * torch.cos(trans_params[:, 0]), trans_params[:, 1] * -1 * torch.sin(trans_params[:, 0]), trans_params[:, 2],
    trans_params[:, 1] * torch.sin(trans_params[:, 0]), trans_params[:, 1] *      torch.cos(trans_params[:, 0]), trans_params[:, 3]
        ]).view(-1, 2, 3)

instead of
trans_matrix = torch.stack([
    trans_params[:, 1] * torch.cos(trans_params[:, 0]), trans_params[:, 1] * -1 * torch.sin(trans_params[:, 0]), trans_params[:, 2],
    trans_params[:, 1] * torch.sin(trans_params[:, 0]), trans_params[:, 1] *      torch.cos(trans_params[:, 0]), trans_params[:, 3]
        ]).view(-1, 2, 3)

So it seems that cloning fixes the error message. But it also seems that the gradients don’t flow properly anymore because my loss is not going down.