# Path: fedjax/core/dataclasses.py
# def dataclass(clz: type):
#   def replace(self, **updates):
#   def iterate_clz(x):
#   def clz_from_iterable(meta, data):
# 
# Path: fedjax/core/util.py
# def safe_div(a, b):
#   def __getattr__(self, _):
# def import_tf():
# class FakeTensorFlowModule:
# 
# Path: fedjax/core/typing.py

# 
# Path: fedjax/core/typing.py

# 
# Path: fedjax/core/typing.py

# 
# Path: fedjax/core/typing.py



import abc
import functools
import jax
import jax.numpy as jnp
from typing import Optional, Tuple
from fedjax.core import dataclasses
from fedjax.core import util
from fedjax.core.typing import BatchExample
from fedjax.core.typing import BatchPrediction
from fedjax.core.typing import SingleExample
from fedjax.core.typing import SinglePrediction

  - :meth:`~Metric.evaluate_example` evaluates a single example, and returns a
    :class:`Stat` object.
  - :meth:`~Metric.zero` returns the identity value for what
    :meth:`~Metric.evaluate_example` returns.

  Given a :class:`Metric` object ``m``, let

  - ``u = m.zero()``
  - ``v = m.evaluate_example(...)``

  We require that

  - ``type(u) == type(v)``.
  - ``u.merge(v) == v.merge(u) == v``.
  - Components of ``u`` has the same shape as the counter parts in ``v``.
  """

  @abc.abstractmethod
  def zero(self) -> Stat:
    """Returns a Stat such that merging with it is an identity operation.

    e.g. for accuracy: ``MeanStat.new(0., 0.)``

    Returns:
      Stat identity value.
    """

  @abc.abstractmethod
  def evaluate_example(self, example: SingleExample,

# Path: fedjax/core/dataclasses.py
# def dataclass(clz: type):
#   def replace(self, **updates):
#   def iterate_clz(x):
#   def clz_from_iterable(meta, data):
# 
# Path: fedjax/core/util.py
# def safe_div(a, b):
#   def __getattr__(self, _):
# def import_tf():
# class FakeTensorFlowModule:
# 
# Path: fedjax/core/typing.py

# 
# Path: fedjax/core/typing.py

# 
# Path: fedjax/core/typing.py

# 
# Path: fedjax/core/typing.py



# Path: fedjax/core/metrics.py
import abc
import functools
import jax
import jax.numpy as jnp
from typing import Optional, Tuple
from fedjax.core import dataclasses
from fedjax.core import util
from fedjax.core.typing import BatchExample
from fedjax.core.typing import BatchPrediction
from fedjax.core.typing import SingleExample
from fedjax.core.typing import SinglePrediction


  - :meth:`~Metric.evaluate_example` evaluates a single example, and returns a
    :class:`Stat` object.
  - :meth:`~Metric.zero` returns the identity value for what
    :meth:`~Metric.evaluate_example` returns.

  Given a :class:`Metric` object ``m``, let

  - ``u = m.zero()``
  - ``v = m.evaluate_example(...)``

  We require that

  - ``type(u) == type(v)``.
  - ``u.merge(v) == v.merge(u) == v``.
  - Components of ``u`` has the same shape as the counter parts in ``v``.
  """

  @abc.abstractmethod
  def zero(self) -> Stat:
    """Returns a Stat such that merging with it is an identity operation.

    e.g. for accuracy: ``MeanStat.new(0., 0.)``

    Returns:
      Stat identity value.
    """

  @abc.abstractmethod
  def evaluate_example(self, example: SingleExample,

                       prediction: SinglePrediction) -> Stat: