code: def test_lof_torch_backend_ensemble_fit_errors(ensembler):
      """Tests the correct errors are raised when using the LOFTorch backend as an ensemble."""
      lof_torch = LOFTorch(k=[4, 5], ensembler=ensembler)
  
      # Test that the backend raises an error if it is not fitted before
      # calling forward method.
      x = torch.randn((1, 10))
      with pytest.raises(NotFittedError) as err:
          lof_torch(x)
      assert str(err.value) == "LOFTorch has not been fit!"
  
      # Test that the backend raises an error if it is not fitted before
      # predicting.
      with pytest.raises(NotFittedError) as err:
          lof_torch.predict(x)
      assert str(err.value) == "LOFTorch has not been fit!"
  
      # Test the backend updates fitted flag on fit.
      x_ref = torch.randn((1024, 10))
      lof_torch.fit(x_ref)
      assert lof_torch.fitted
  
      # Test that the backend raises an if the forward method is called without the
      # threshold being inferred.
      with pytest.raises(ThresholdNotInferredError) as err:
          lof_torch(x)
      assert (
          str(err.value)
          == "LOFTorch has no threshold set, call `infer_threshold` to fit one!"
      )
  
      # Test that the backend can call predict without the threshold being inferred.
      with pytest.raises(ThresholdNotInferredError) as err:
          lof_torch.predict(x)
      assert (
          str(err.value)
          == "LOFTorch has no threshold set, call `infer_threshold` to fit one!"
      )
  
file_path: alibi-detect/alibi_detect/od/tests/test__lof/test__lof_backend.py
imports: import pytest
  import torch
  from alibi_detect.od.pytorch.lof import LOFTorch
  from alibi_detect.utils.pytorch.kernels import GaussianRBF
  from alibi_detect.od.pytorch.ensemble import Ensembler, PValNormalizer, AverageAggregator
  from alibi_detect.exceptions import NotFittedError, ThresholdNotInferredError
label_desc: Use image node_id 8 for calling a global function with example usage: test_lof_torch_backend_ensemble_fit_errors(ensembler) without return types