Repository: kornia/kornia

Issue:
Deprecation warning for torch.qr
### Describe the bug

When the command `pytest -sv test/geometry/epipolar/test_projection.py --device all --dtype float32` or `pytest -sv test/geometry/epipolar/test_projection.py --device all --dtype float64` was run for PR #1241, the following deprecation error was obtained:

```
=================================================================== warnings summary ====================================================================
test/geometry/epipolar/test_projection.py::TestProjectionFromKRt::test_krt_from_projection[cpu-float64]
  /kornia/kornia/geometry/epipolar/projection.py:134: UserWarning: torch.qr is deprecated in favor of torch.linalg.qr and will be removed in a future PyTorch release.
  The boolean parameter 'some' has been replaced with a string parameter 'mode'.
  Q, R = torch.qr(A, some)
  should be replaced with
  Q, R = torch.linalg.qr(A, 'reduced' if some else 'complete') (Triggered internally at  /opt/conda/conda-bld/pytorch_1623448224956/work/aten/src/ATen/native/BatchLinearAlgebra.cpp:1940.)
    ortho_mat, upper_mat = torch.qr(submat_3x3)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
```

In the discussion in #1241, @edgarriba mentioned that:
> Regarding the QR thing - we need something similar to solve to cast and keep backward compatibility. See: https://github.com/kornia/kornia/blob/master/kornia/utils/_compat.py#L14

Possible solutions to this issue can be discussed here.

### Reproduction steps

This issue was obtained while testing for PR #1241. I did not re-test it on the latest `master` at the time of writing this issue. But the issue should still be there since it was not fixed.

Change directory to the top level kornia directory (you should be able to see the `test` directory if you run `ls` at the top level directory).

Then, run `pytest -sv test/geometry/epipolar/test_projection.py --device all --dtype float32` or `pytest -sv test/geometry/epipolar/test_projection.py --device all --dtype float64`.

### Expected behavior

Ideally the issue should be handled to ensure compatibility across versions.

### Environment

```shell
NOTE: I use an ubuntu 16.04 docker image. Kornia was installed within a docker container. The docker container was created from the aforementioned docker image.

PyTorch version: 1.9.0
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 16.04.7 LTS (x86_64)
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.17

Python version: 3.7.11 (default, Jul 27 2021, 14:32:16)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.0-81-generic-x86_64-with-debian-stretch-sid
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce GTX 950M
Nvidia driver version: 460.91.03
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy==0.910
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.2
[pip3] pytest-mypy==0.8.1
[pip3] torch==1.9.0
[pip3] torchvision==0.10.0
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               10.2.89              hfd86e86_1  
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.3.0           h06a4308_520  
[conda] mypy                      0.910                    pypi_0    pypi
[conda] mypy-extensions           0.4.3                    pypi_0    pypi
[conda] numpy                     1.21.2                   pypi_0    pypi
[conda] pytest-mypy               0.8.1                    pypi_0    pypi
[conda] pytorch                   1.9.0           py3.7_cuda10.2_cudnn7.6.5_0    pytorch
[conda] torchvision               0.10.0               py37_cu102    pytorch
```


### Additional context

For more context you can refer to PR #1241.


Discussion:
Can I work on this?

Resolving patch:
diff --git a/kornia/geometry/epipolar/projection.py b/kornia/geometry/epipolar/projection.py
--- a/kornia/geometry/epipolar/projection.py
+++ b/kornia/geometry/epipolar/projection.py
@@ -4,6 +4,7 @@
 import torch
 
 from kornia.geometry.epipolar import numeric
+from kornia.utils._compat import linalg_qr
 
 
 def intrinsics_like(focal: float, input: torch.Tensor) -> torch.Tensor:
@@ -131,7 +132,7 @@ def KRt_from_projection(P: torch.Tensor, eps: float = 1e-6) -> Tuple[torch.Tenso
     # Trick to turn QR-decomposition into RQ-decomposition
     reverse = torch.tensor([[0, 0, 1], [0, 1, 0], [1, 0, 0]], device=P.device, dtype=P.dtype).unsqueeze(0)
     submat_3x3 = torch.matmul(reverse, submat_3x3).permute(0, 2, 1)
-    ortho_mat, upper_mat = torch.qr(submat_3x3)
+    ortho_mat, upper_mat = linalg_qr(submat_3x3)
     ortho_mat = torch.matmul(reverse, ortho_mat.permute(0, 2, 1))
     upper_mat = torch.matmul(reverse, torch.matmul(upper_mat.permute(0, 2, 1), reverse))
 
diff --git a/kornia/utils/_compat.py b/kornia/utils/_compat.py
--- a/kornia/utils/_compat.py
+++ b/kornia/utils/_compat.py
@@ -19,3 +19,12 @@ def torch_version() -> str:
     # NOTE: in previous versions `torch.solve` accepted arguments in another order.
     def solve(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor:
         return _solve(B, A).solution
+
+
+if version.parse(torch_version()) > version.parse("1.7.1"):
+    # TODO: remove the type: ignore once Python 3.6 is deprecated.
+    # It turns out that Pytorch has no attribute `torch.linalg` for
+    # Python 3.6 / PyTorch 1.7.0, 1.7.1
+    from torch.linalg import qr as linalg_qr  # type: ignore
+else:
+    from torch import qr as linalg_qr  # type: ignore


Test patch: