# 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
    Returns:
      Stat identity value.
    """

  @abc.abstractmethod
  def evaluate_example(self, example: SingleExample,
                       prediction: SinglePrediction) -> Stat:
    """Evaluates a single example.

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

    Args:
      example: A single input example (e.g. one sentence for language).
      prediction: Output for ``example`` from
        :meth:`fedjax.core.models.Model.apply_for_eval`.

    Returns:
      Stat value.
    """


def apply_mask(mask: jnp.ndarray, a: jnp.ndarray,
               b: jnp.ndarray) -> jnp.ndarray:
  """Applies mask on the leading dimension."""
  rank = max(len(a.shape), len(b.shape))
  return jnp.where(jnp.expand_dims(mask, tuple(range(1, rank))), a, b)


@functools.partial(jax.jit, static_argnums=0)
def evaluate_batch(metric: Metric,

# 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

    Returns:
      Stat identity value.
    """

  @abc.abstractmethod
  def evaluate_example(self, example: SingleExample,
                       prediction: SinglePrediction) -> Stat:
    """Evaluates a single example.

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

    Args:
      example: A single input example (e.g. one sentence for language).
      prediction: Output for ``example`` from
        :meth:`fedjax.core.models.Model.apply_for_eval`.

    Returns:
      Stat value.
    """


def apply_mask(mask: jnp.ndarray, a: jnp.ndarray,
               b: jnp.ndarray) -> jnp.ndarray:
  """Applies mask on the leading dimension."""
  rank = max(len(a.shape), len(b.shape))
  return jnp.where(jnp.expand_dims(mask, tuple(range(1, rank))), a, b)


@functools.partial(jax.jit, static_argnums=0)
def evaluate_batch(metric: Metric,

                   batch_example: BatchExample,