-
-
Save mbergal/ebf3f29f702c676b68ace9714537e564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import abstractmethod | |
from typing import Generic, Protocol, TypeVar | |
T_cov = TypeVar("T", contravariant=True) | |
U_cov = TypeVar("U", contravariant=True) | |
class Metric(Protocol[T]): | |
@abstractmethod | |
def __call__(self, gt: T, pred: T) -> float: | |
... | |
class SomeMetric(Metric[int]): | |
def __call__(self, gt: int, pred: int) -> float: | |
return 0 | |
class MetricsStructure(Generic[T_cov]): | |
m1: T_cov | |
m2: T_cov | |
class MetricCollection(Protocol[U_cov]): | |
def __init__(self, metrics: MetricsStructure[Metric[U]]): | |
self.__metrics = metrics | |
def __call__(self, gt: U_cov, pred: U_cov) -> MetricsStructure[float]: | |
return {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment