def create_anomalib_metric(metric_cls: type) -> type:
    """Create an Anomalib version of a torchmetrics metric.

    Factory function that creates a new class inheriting from both
    ``AnomalibMetric`` and the input metric class. The resulting class has
    batch processing capabilities while maintaining the original metric's
    functionality.

    Args:
        metric_cls (type): torchmetrics metric class to wrap.

    Returns:
        type: New class inheriting from ``AnomalibMetric`` and input class.

    Raises:
        AssertionError: If input class is not a torchmetrics.Metric subclass.

    Example:
        Create F1 score metric::

            >>> from torchmetrics.classification import BinaryF1Score
            >>> F1Score = create_anomalib_metric(BinaryF1Score)
            >>> f1_score = F1Score(fields=["pred_label", "gt_label"])
            >>> f1_score.update(batch)  # Can update with batch directly
            >>> f1_score.compute()
            tensor(0.6667)
    """
    assert issubclass(metric_cls, Metric), "The wrapped metric must be a subclass of torchmetrics.Metric."
    return type(metric_cls.__name__, (AnomalibMetric, metric_cls), {})
Create an Anomalib version of a torchmetrics metric.

    Factory function that creates a new class inheriting from both
    ``AnomalibMetric`` and the input metric class. The resulting class has
    batch processing capabilities while maintaining the original metric's
    functionality.

    Args:
        metric_cls (type): torchmetrics metric class to wrap.

    Returns:
        type: New class inheriting from ``AnomalibMetric`` and input class.

    Raises:
        AssertionError: If input class is not a torchmetrics.Metric subclass.

    Example:
        Create F1 score metric::

            >>> from torchmetrics.classification import BinaryF1Score
            >>> F1Score = create_anomalib_metric(BinaryF1Score)
            >>> f1_score = F1Score(fields=["pred_label", "gt_label"])
            >>> f1_score.update(batch)  # Can update with batch directly
            >>> f1_score.compute()
            tensor(0.6667)
    
src/anomalib/metrics/base.py