code: def test_gmm_pytorch_backend_fit_errors():
      """Test gmm detector pytorch backend fit errors.
  
      Tests the correct errors are raised when using the GMMTorch pytorch backend detector.
      """
      gmm_torch = GMMTorch(n_components=2)
      assert not gmm_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:
          gmm_torch(x)
      assert str(err.value) == "GMMTorch has not been fit!"
  
      # Test that the backend raises an error if it is not fitted before
      # predicting.
      with pytest.raises(NotFittedError) as err:
          gmm_torch.predict(x)
      assert str(err.value) == "GMMTorch has not been fit!"
  
      # Test the backend updates _fitted flag on fit.
      x_ref = torch.tensor(np.random.randn(1024, 10))
      gmm_torch.fit(x_ref)
      assert gmm_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:
          gmm_torch(x)
      assert (
          str(err.value)
          == "GMMTorch has no threshold set, call `infer_threshold` to fit one!"
      )
  
      # Test that the backend can call predict without the threshold being inferred.
      assert gmm_torch.predict(x)
  
file_path: alibi-detect/alibi_detect/od/tests/test__gmm/test__gmm_pytorch_backend.py
imports: import pytest
  import numpy
  import torch
  from alibi_detect.od.pytorch.gmm import GMMTorch
  from alibi_detect.exceptions import NotFittedError, ThresholdNotInferredError
label_desc: Use image node_id 3 for calling a global function with example usage: test_gmm_pytorch_backend_fit_errors() without return types