code: def test_top_k_ignore_index_multiclass():
      """Test that top_k argument works together with ignore_index."""
      preds_without = torch.randn(10, 3).softmax(dim=-1)
      target_without = torch.randint(3, (10,))
      preds_with = torch.cat(
          [preds_without, torch.randn(10, 3).softmax(dim=-1)], 0
      )
      target_with = torch.cat(
          [target_without, -100 * torch.ones(10)], 0
      ).long()
  
      res_without = multiclass_stat_scores(
          preds_without,
          target_without,
          num_classes=3,
          average="micro",
          top_k=2,
      )
      res_with = multiclass_stat_scores(
          preds_with,
          target_with,
          num_classes=3,
          average="micro",
          top_k=2,
          ignore_index=-100,
      )
  
      assert torch.allclose(res_without, res_with)
  
imports: from functools import partial
  import numpy
  import pytest
  import torch
  from scipy.special import expit
  from sklearn.metrics import confusion_matrix
  from torchmetrics.classification.stat_scores import BinaryStatScores, MulticlassStatScores, MultilabelStatScores, StatScores
  from torchmetrics.functional.classification.stat_scores import binary_stat_scores, multiclass_stat_scores, multilabel_stat_scores
  from torchmetrics.metric import Metric
  from unittests import NUM_CLASSES, THRESHOLD
  from unittests.classification.inputs import _binary_cases, _multiclass_cases, _multilabel_cases
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester, inject_ignore_index, remove_ignore_index
label_desc: Use image node_id 6 for calling a global function with example usage: test_top_k_ignore_index_multiclass() without return types