Repository: fakufaku/fast_bss_eval (language: python)

Issue:
Compatibility problem with torch >= 1.8.0 when torch_complex package is not installed
Hello, 
I noticed that when trying to use the package (version `0.1.3`), I get some compatibility issues when using torch.Tensor inputs for the method `bss_eval_sources` because I did not have the `torch_complex` package installed. However, the `torch_complex package` shouldn't be required in this case since I use torch ` 1.10.2`.

This happens because in the `__init__.py` file, the variable `has_torch` is not set to `True` 

```
try:
    import torch as pt
    has_torch = True

    from . import torch as torch     # --> this line fails
    from .torch import sdr_pit_loss, si_sdr_pit_loss   
except ImportError:
    has_torch = False

    # dummy pytorch module
    class pt:
        class Tensor:
            def __init__(self):
                pass

    # dummy torch submodule
    class torch:
        bss_eval_sources = None
        sdr = None
        sdr_loss = None

from . import numpy as numpy
```

Apparently this happens because the line that fails tries to import the file `torch/compatibility.py` :

```
try:
    from packaging.version import Version
except [ImportError, ModuleNotFoundError]:
    from distutils.version import LooseVersion as Version

from torch_complex import ComplexTensor # --> this line causes the problem when torch_complex is not installed 

import torch

is_torch_1_8_plus = Version(torch.__version__) >= Version("1.8.0")

if not is_torch_1_8_plus:
    try:
        import torch_complex
    except ImportError:
        raise ImportError(
            "When using torch<=1.7, the package torch_complex is required."
            " Install it as `pip install torch_complex`"
        )
```

If I understand correctly, the fix would simply be to do the following :

```
try:
    from packaging.version import Version
except [ImportError, ModuleNotFoundError]:
    from distutils.version import LooseVersion as Version

import torch

is_torch_1_8_plus = Version(torch.__version__) >= Version("1.8.0")

if not is_torch_1_8_plus:
    try:
        from torch_complex import ComplexTensor 
    except ImportError:
        raise ImportError(
            "When using torch<=1.7, the package torch_complex is required."
            " Install it as `pip install torch_complex`"
        )
```


Discussion / hints:
Thank you very much for the detailed bug report! I also had some issues with torch_complex import failing, but had not looked into it! The bugfix is simple enough: I'll try it right now!

Fix patch:
diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml
index d80f722..7f3de3c 100644
--- a/.github/workflows/pythonpackage.yml
+++ b/.github/workflows/pythonpackage.yml
@@ -13,28 +13,36 @@ jobs:
         os: [ubuntu-latest, macos-latest, windows-latest]
         python-version: [3.7, 3.8, 3.9, "3.10"]
         torch-version: [1.11]
+        torch-complex-req: [""]
         include:
             - os: ubuntu-latest
               python-version: 3.8
               torch-version: 1.4
+              torch-complex-req: "_torch_le_1_8"
             - os: ubuntu-latest
               python-version: 3.8
               torch-version: 1.5
+              torch-complex-req: "_torch_le_1_8"
             - os: ubuntu-latest
               python-version: 3.8
               torch-version: 1.6
+              torch-complex-req: "_torch_le_1_8"
             - os: ubuntu-latest
               python-version: 3.8
               torch-version: 1.7
+              torch-complex-req: "_torch_le_1_8"
             - os: ubuntu-latest
               python-version: 3.8
               torch-version: 1.8
+              torch-complex-req: "_torch_le_1_8"
             - os: ubuntu-latest
               python-version: 3.8
               torch-version: 1.9
+              torch-complex-req: ""
             - os: ubuntu-latest
               python-version: 3.9
               torch-version: "1.10"
+              torch-complex-req: ""
 
     steps:
     - uses: actions/checkout@v2
@@ -51,7 +59,7 @@ jobs:
     - name: Install dependencies
       run: |
         python -m pip install --upgrade pip
-        python -m pip install -r tests/requirements.txt
+        python -m pip install -r tests/requirements${{ matrix.torch-complex-req }}.txt
         python -m pip install -U torch==${{ matrix.torch-version }}
         pip install -e .
     - name: Test and coverage with pytest
diff --git a/fast_bss_eval/torch/compatibility.py b/fast_bss_eval/torch/compatibility.py
index 90ad69c..b3f2764 100644
--- a/fast_bss_eval/torch/compatibility.py
+++ b/fast_bss_eval/torch/compatibility.py
@@ -32,8 +32,6 @@
 except [ImportError, ModuleNotFoundError]:
     from distutils.version import LooseVersion as Version
 
-from torch_complex import ComplexTensor
-
 import torch
 
 is_torch_1_8_plus = Version(torch.__version__) >= Version("1.8.0")


Test patch:
diff --git a/tests/requirements.txt b/tests/requirements.txt
index 4c4dfda..e683031 100644
--- a/tests/requirements.txt
+++ b/tests/requirements.txt
@@ -1,7 +1,6 @@
 numpy
 scipy
 torch>=1.4
-torch_complex
 mir_eval
 pytest
 pytest-cov
diff --git a/tests/requirements_torch_le_1_8.txt b/tests/requirements_torch_le_1_8.txt
new file mode 100644
index 0000000..4c4dfda
--- /dev/null
+++ b/tests/requirements_torch_le_1_8.txt
@@ -0,0 +1,9 @@
+numpy
+scipy
+torch>=1.4
+torch_complex
+mir_eval
+pytest
+pytest-cov
+pytest-timeout
+-e .