code: def test_to_categorical():
      """Test that casting to categorical works as expected."""
      test_tensor = torch.stack(
          [
              torch.cat(
                  [
                      torch.eye(5, dtype=int),
                      torch.zeros((5, 5), dtype=int),
                  ]
              ),
              torch.cat(
                  [
                      torch.zeros((5, 5), dtype=int),
                      torch.eye(5, dtype=int),
                  ]
              ),
          ]
      ).to(torch.float)
  
      expected = tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
      assert expected.shape == (2, 5)
      assert test_tensor.shape == (2, 10, 5)
  
      result = to_categorical(test_tensor)
  
      assert result.shape == expected.shape
      assert torch.allclose(result, expected.to(result.dtype))
  
imports: import sys
  import numpy
  import pytest
  import torch
  from torch import tensor
  from torchmetrics.regression import MeanSquaredError, PearsonCorrCoef
  from torchmetrics.utilities import check_forward_full_state_property, rank_zero_debug, rank_zero_info, rank_zero_warn
  from torchmetrics.utilities.checks import _allclose_recursive
  from torchmetrics.utilities.data import _bincount, _cumsum, _flatten, _flatten_dict, select_topk, to_categorical, to_onehot
  from torchmetrics.utilities.distributed import class_reduce, reduce
  from torchmetrics.utilities.exceptions import TorchMetricsUserWarning
  from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_13
label_desc: Use image node_id 5 for calling a global function with example usage: test_to_categorical() without return types