code: def test_svm_pytorch_backend_fit_errors(backend_cls):
      """Test SVM detector pytorch backend fit errors.
  
      Tests the correct errors are raised when using the SVMTorch pytorch backend detector.
      """
      svm_torch = backend_cls(
          n_components=100, kernel=GaussianRBF(), nu=0.1
      )
      assert not svm_torch.fitted
  
      # Test that the backend raises an error if it is not fitted before
      # calling forward method.
      x = torch.tensor(np.random.randn(1, 10))
      with pytest.raises(NotFittedError) as err:
          svm_torch(x)
      assert (
          str(err.value) == f"{backend_cls.__name__} has not been fit!"
      )
  
      # Test that the backend raises an error if it is not fitted before
      # predicting.
      with pytest.raises(NotFittedError) as err:
          svm_torch.predict(x)
      assert (
          str(err.value) == f"{backend_cls.__name__} has not been fit!"
      )
  
      # Test the backend updates _fitted flag on fit.
      x_ref = torch.tensor(np.random.randn(1024, 10))
      svm_torch.fit(x_ref)
      assert svm_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:
          svm_torch(x)
      assert (
          str(err.value)
          == f"{backend_cls.__name__} has no threshold set, call `infer_threshold` to fit one!"
      )
  
      # Test that the backend can call predict without the threshold being inferred.
      assert svm_torch.predict(x)
  
file_path: alibi-detect/alibi_detect/od/tests/test__svm/test__svm_pytorch_backend.py
imports: import pytest
  import numpy
  import torch
  from alibi_detect.utils.pytorch.kernels import GaussianRBF
  from alibi_detect.od.pytorch.svm import BgdSVMTorch, SgdSVMTorch
  from alibi_detect.exceptions import NotFittedError, ThresholdNotInferredError
label_desc: Use image node_id 3 for calling a global function with example usage: test_svm_pytorch_backend_fit_errors(backend_cls) without return types