code: def test_pearson_correlation_unmasked_computation(self, device: str):
      pearson_correlation = PearsonCorrelation()
      batch_size = 100
      num_labels = 10
      predictions_1 = torch.randn(batch_size, num_labels, device=device)
      labels_1 = 0.5 * predictions_1 + torch.randn(
          batch_size, num_labels, device=device
      )
  
      predictions_2 = torch.randn(1, device=device).expand(num_labels)
      predictions_2 = predictions_2.unsqueeze(0).expand(batch_size, -1)
      labels_2 = torch.randn(1, device=device).expand(num_labels)
      labels_2 = 0.5 * predictions_2 + labels_2.unsqueeze(0).expand(
          batch_size, -1
      )
  
      # in most cases, the data is constructed like predictions_1, the data of such a batch different.
      # but in a few cases, for example, predictions_2, the data of such a batch is exactly the same.
      predictions_labels = [
          (predictions_1, labels_1),
          (predictions_2, labels_2),
      ]
  
      stride = 10
  
      for predictions, labels in predictions_labels:
          pearson_correlation.reset()
          for i in range(batch_size // stride):
              timestep_predictions = predictions[
                  stride * i : stride * (i + 1), :
              ]
              timestep_labels = labels[stride * i : stride * (i + 1), :]
              expected_pearson_correlation = pearson_corrcoef(
                  predictions[: stride * (i + 1), :]
                  .view(-1)
                  .cpu()
                  .numpy(),
                  labels[: stride * (i + 1), :].view(-1).cpu().numpy(),
              )
              pearson_correlation(timestep_predictions, timestep_labels)
              assert_allclose(
                  expected_pearson_correlation,
                  pearson_correlation.get_metric(),
              )
          # Test reset
          pearson_correlation.reset()
          pearson_correlation(predictions, labels)
          assert_allclose(
              pearson_corrcoef(
                  predictions.view(-1).cpu().numpy(),
                  labels.view(-1).cpu().numpy(),
              ),
              pearson_correlation.get_metric(),
          )
  
file_path: allennlp/tests/training/metrics/pearson_correlation_test.py
imports: from typing import Optional
  import numpy
  import torch
  from torch.testing import assert_allclose
  from allennlp.common.testing import AllenNlpTestCase, multi_device
  from allennlp.training.metrics import PearsonCorrelation
label_desc: Use image node_id 1 for calling the PearsonCorrelationTest obj's underlying member method code with example usage: obj.test_pearson_correlation_unmasked_computation(device) without return types