code: def test_lof_torch_backend_ts(tmp_path):
      """
      Test the lof torch backend can be initialized and torch scripted, as well as
      saved and loaded to and from disk.
      """
  
      lof_torch = LOFTorch(k=7)
      x = torch.randn((3, 10)) * torch.tensor([[1], [1], [100]])
      x_ref = torch.randn((1024, 10))
      lof_torch.fit(x_ref)
      lof_torch.infer_threshold(x_ref, 0.1)
      pred_1 = lof_torch(x)
      lof_torch = torch.jit.script(lof_torch)
      pred_2 = lof_torch(x)
      assert torch.all(pred_1 == pred_2)
  
      lof_torch.save(tmp_path / "lof_torch.pt")
      lof_torch = torch.load(tmp_path / "lof_torch.pt")
      pred_2 = lof_torch(x)
      assert torch.all(pred_1 == pred_2)
  
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 5 for calling a global function with example usage: test_lof_torch_backend_ts(tmp_path) without return types