Skip to content

Update clu.Metrics.compute_value() return type, to avoid signature-mismatch error. #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions clu/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def evaluate(model, p_variables, test_ds):
return ms.unreplicate().compute()
"""

from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Tuple, Type
from collections.abc import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Type, Union

from absl import logging

Expand Down Expand Up @@ -141,7 +141,16 @@ def empty(cls) -> "Metric":
"""Returns an empty instance (i.e. `.merge(Metric.empty())` is a no-op)."""
raise NotImplementedError("Must override empty()")

def compute_value(self) -> clu.values.Value:
def compute_value(
self,
) -> Union[
clu.values.Value,
List[clu.values.Value],
Tuple[clu.values.Value],
Dict[str, clu.values.Value],
Dict[str, List[clu.values.Value]],
Dict[str, Tuple[clu.values.Value]],
]:
"""Wraps compute() and returns a values.Value."""
return clu.values.Scalar(self.compute())

Expand Down