code: def test_mahalanobis_torch_backend_fit_errors():
      """Test Mahalanobis detector backend fit errors.
  
      Test that an unfit detector backend raises an error when calling predict or score. Test that the
      detector backend raises an error when calling the forward method while the threshold has not been
      inferred.
      """
      mahalanobis_torch = MahalanobisTorch()
      assert not mahalanobis_torch.fitted
  
      x = torch.randn((1, 10))
      with pytest.raises(NotFittedError) as err:
          mahalanobis_torch(x)
      assert str(err.value) == "MahalanobisTorch has not been fit!"
  
      with pytest.raises(NotFittedError) as err:
          mahalanobis_torch.predict(x)
      assert str(err.value) == "MahalanobisTorch has not been fit!"
  
      x_ref = torch.randn((1024, 10))
      mahalanobis_torch.fit(x_ref)
  
      assert mahalanobis_torch.fitted
  
      with pytest.raises(ThresholdNotInferredError) as err:
          mahalanobis_torch(x)
      assert (
          str(err.value)
          == "MahalanobisTorch has no threshold set, call `infer_threshold` to fit one!"
      )
  
      assert mahalanobis_torch.predict(x)
  
imports: import pytest
  import torch
  import numpy
  from alibi_detect.od.pytorch.mahalanobis import MahalanobisTorch
  from alibi_detect.exceptions import NotFittedError, ThresholdNotInferredError
label_desc: Use image node_id 3 for calling a global function with example usage: test_mahalanobis_torch_backend_fit_errors() without return types