code: def test_pca_torch_backend_fit_errors(backend_detector):
      """Test Linear and Kernel PCA 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.
      """
      pca_torch = backend_detector()
      assert not pca_torch.fitted
  
      x = torch.randn((1, 10))
      with pytest.raises(NotFittedError) as err:
          pca_torch(x)
      assert (
          str(err.value)
          == f"{pca_torch.__class__.__name__} has not been fit!"
      )
  
      with pytest.raises(NotFittedError) as err:
          pca_torch.predict(x)
      assert (
          str(err.value)
          == f"{pca_torch.__class__.__name__} has not been fit!"
      )
  
      x_ref = torch.randn((1024, 10))
      pca_torch.fit(x_ref)
  
      assert pca_torch.fitted
  
      with pytest.raises(ThresholdNotInferredError) as err:
          pca_torch(x)
  
      assert str(err.value) == (
          f"{pca_torch.__class__.__name__} has no threshold set, "
          "call `infer_threshold` to fit one!"
      )
  
      assert pca_torch.predict(x)
  
file_path: alibi-detect/alibi_detect/od/tests/test__pca/test__pca_backend.py
imports: import pytest
  import torch
  import numpy
  from alibi_detect.utils.pytorch.kernels import GaussianRBF
  from alibi_detect.od.pytorch.pca import LinearPCATorch, KernelPCATorch
  from alibi_detect.exceptions import NotFittedError, ThresholdNotInferredError
label_desc: Use image node_id 1 for calling a global function with example usage: test_pca_torch_backend_fit_errors(backend_detector) without return types