code: def test_error_on_multidim_tensors(metric_class=R2Score):
      """Test that error is raised if a larger than 2D tensor is given as input."""
      metric = metric_class()
      with pytest.raises(
          ValueError,
          match=r"Expected both prediction and target to be 1D or 2D tensors, but received tensors with dimension .",
      ):
          metric(torch.randn(10, 20, 5), torch.randn(10, 20, 5))
  
imports: from functools import partial
  import pytest
  import torch
  from sklearn.metrics import r2_score
  from torchmetrics.functional import r2_score
  from torchmetrics.regression import R2Score
  from unittests import BATCH_SIZE, NUM_BATCHES, _Input
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester
label_desc: Use image node_id 4 for calling a global function with example usage: test_error_on_multidim_tensors(metric_class) without return types