code: def compute_weighted_metric(
      y, y_pred, metric, weights, weight_evaluation=None, **kwargs
  ):
      """Report weighted metric if: weights is not None, weight_evaluation=True, and the given metric supports sample weights.
      If weight_evaluation=None, it will be set to False if weights=None, True otherwise.
      """
      if not metric.needs_quantile:
          kwargs.pop("quantile_levels", None)
      if weight_evaluation is None:
          weight_evaluation = not (weights is None)
      if weight_evaluation and weights is None:
          raise ValueError(
              "Sample weights cannot be None when weight_evaluation=True."
          )
      if not weight_evaluation:
          return metric(y, y_pred, **kwargs)
      try:
          weighted_metric = metric(
              y, y_pred, sample_weight=weights, **kwargs
          )
      except (ValueError, TypeError, KeyError):
          if hasattr(metric, "name"):
              metric_name = metric.name
          else:
              metric_name = metric
          logger.log(
              30,
              f"WARNING: eval_metric='{metric_name}' does not support sample weights so they will be ignored in reported metric.",
          )
          weighted_metric = metric(y, y_pred, **kwargs)
      return weighted_metric
  
imports: import logging
  import math
  import pickle
  import random
  import sys
  import time
  from typing import Callable, List, Tuple, Union
  import numpy
  import pandas
  import scipy.stats
  from numpy.typing import ArrayLike
  from pandas import DataFrame, Series
  from sklearn.model_selection import LeaveOneGroupOut, RepeatedKFold, RepeatedStratifiedKFold, train_test_split
  from autogluon.common.utils.resource_utils import ResourceManager
  from ..constants import BINARY, LARGE_DATA_THRESHOLD, MULTICLASS, MULTICLASS_UPPER_LIMIT, QUANTILE, REGRESS_THRESHOLD_LARGE_DATA, REGRESS_THRESHOLD_SMALL_DATA, REGRESSION, SOFTCLASS
  from ..metrics import Scorer, accuracy, pinball_loss, root_mean_squared_error
  from .miscs import warning_filter
label_desc: Use image node_id 19 for calling a global function with example usage: compute_weighted_metric(y, y_pred, metric, weights, weight_evaluation) and returns: weighted_metric, metric