name: Test TensorLy

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        BACKEND: ['numpy', 'pytorch', 'paddle']
        python-version: ['3.12']
        include:
          - BACKEND: 'numpy'
            python-version: '3.9'
          - BACKEND: 'numpy'
            python-version: '3.11'
            TENSORLY_TENALG_BACKEND: ['einsum']
          - BACKEND: 'jax'
            python-version: '3.13'
            TENSORLY_TENALG_BACKEND: ['einsum']
          - BACKEND: 'tensorflow'
            python-version: '3.12'
            TENSORLY_TENALG_BACKEND: ['einsum']

    steps:
    - uses: actions/checkout@v4
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
        cache: "pip"
        cache-dependency-path: |
          requirements.txt

    - name: Install dependencies and backend ${{matrix.BACKEND}}
      run: |
        python -m pip install --upgrade pip
        python -m pip install -r requirements.txt
        python -m pip install -r doc/requirements_doc.txt
        echo "Installing dependencies for BACKEND=${{matrix.BACKEND}}"
        if [[ "${{matrix.BACKEND}}" == "numpy" ]]; then
          echo "Installing sparse";
          pip install sparse;
        elif [[ "${{matrix.BACKEND}}" == "pytorch" ]]; then
          echo "Installing PyTorch";
          pip install torch torchvision;
        elif [[ "${{matrix.BACKEND}}" == "tensorflow" ]]; then
          echo "Installing TensorFlow";
          pip install tensorflow;
        elif [[ "${{matrix.BACKEND}}" == "jax" ]]; then
          echo "Installing JAX";
          pip install jax jaxlib;
        elif [[ "${{matrix.BACKEND}}" == "paddle" ]]; then
          echo "Installing PaddlePaddle";
          pip install 'setuptools>=65.0';
          pip install paddlepaddle==3.0.0b1 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/;
        fi

    - name: Install package
      run: |
        python -m pip install -e .

    - name: Test with backend ${{matrix.BACKEND}} pytest and coverage
      run: |
        TENSORLY_BACKEND=${{matrix.BACKEND}} pytest -vv --cov tensorly --cov-report xml --durations=10 tensorly

    - name: Check coverage with CodeCov
      uses: codecov/codecov-action@v4
      with:
        file: ./coverage.xml
        verbose: true
