code: def test_topk_aggregator():
      """Test the TopKAggregator
  
      - Test the TopKAggregator correctly aggregates data passed to it
      - Test the TopKAggregator can be torch scripted
      """
      aggregator = ensemble.TopKAggregator(k=4)
      scores = torch.randn((3, 10))
  
      # test the aggregator correctly computes the top k scores
      aggregated_scores = aggregator(scores)
      assert aggregated_scores.shape == (3,)
      scores_sorted, _ = torch.sort(scores)
      torch.allclose(
          scores_sorted[:, -4:].mean(dim=1), aggregated_scores
      )
  
      # test the scriptability of the aggregator
      aggregator = torch.jit.script(aggregator)
      aggregated_scores_2 = aggregator(scores)
      assert torch.all(aggregated_scores_2 == aggregated_scores)
  
file_path: alibi-detect/alibi_detect/od/tests/test_ensemble.py
imports: import pytest
  import torch
  from alibi_detect.od.pytorch import ensemble
  from alibi_detect.exceptions import NotFittedError
label_desc: Use image node_id 5 for calling a global function with example usage: test_topk_aggregator() without return types