code: def test_aggregation_metric(decoder_lengths, y):
      y_pred = torch.tensor([[0.0, 2.0], [4.0, 3.0]])
      if (decoder_lengths != y_pred.size(-1)).any():
          y_packed = rnn.pack_padded_sequence(
              y,
              lengths=decoder_lengths,
              batch_first=True,
              enforce_sorted=False,
          )
      else:
          y_packed = y
  
      # metric
      metric = AggregationMetric(MAE())
      res = metric(y_pred, y_packed)
      if (decoder_lengths == y_pred.size(-1)).all() and y.ndim == 2:
          assert torch.isclose(
              res, (y.mean(0) - y_pred.mean(0)).abs().mean()
          )
  
file_path: pytorch-forecasting/tests/test_metrics.py
imports: import itertools
  import numpy
  import pytest
  import torch
  from torch.nn.utils import rnn
  from pytorch_forecasting.data.encoders import TorchNormalizer
  from pytorch_forecasting.metrics import MAE, SMAPE, BetaDistributionLoss, ImplicitQuantileNetworkDistributionLoss, LogNormalDistributionLoss, MultivariateNormalDistributionLoss, NegativeBinomialDistributionLoss, NormalDistributionLoss
  from pytorch_forecasting.metrics.base_metrics import AggregationMetric, CompositeMetric
label_desc: Use image node_id 2 for calling a global function with example usage: test_aggregation_metric(decoder_lengths, y) without return types