# 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
    weight: The sum of weights.
  """
  accum: jnp.ndarray
  weight: jnp.ndarray

  @classmethod
  def new(cls, accum, weight) -> 'MeanStat':
    """Creates a sanitized MeanStat.

    The domain of a weighted mean statistic is:

    .. math::

      \{(0, 0)\} ∪ \{(a, b) | a >= 0, b > 0\}


    new() sanitizes values outside the domain into the identity (zeros).

    Args:
      accum: A value convertible to ``jnp.ndarray``.
      weight: A value convertible to ``jnp.ndarray``.

    Returns:
      The sanitized MeanStat.
    """
    weight = jnp.maximum(0, jnp.array(weight, copy=False))
    accum = jnp.where(weight == 0, 0, jnp.array(accum, copy=False))
    return cls(accum, weight)

  def result(self) -> jnp.ndarray:

# 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

    weight: The sum of weights.
  """
  accum: jnp.ndarray
  weight: jnp.ndarray

  @classmethod
  def new(cls, accum, weight) -> 'MeanStat':
    """Creates a sanitized MeanStat.

    The domain of a weighted mean statistic is:

    .. math::

      \{(0, 0)\} ∪ \{(a, b) | a >= 0, b > 0\}


    new() sanitizes values outside the domain into the identity (zeros).

    Args:
      accum: A value convertible to ``jnp.ndarray``.
      weight: A value convertible to ``jnp.ndarray``.

    Returns:
      The sanitized MeanStat.
    """
    weight = jnp.maximum(0, jnp.array(weight, copy=False))
    accum = jnp.where(weight == 0, 0, jnp.array(accum, copy=False))
    return cls(accum, weight)

  def result(self) -> jnp.ndarray:

    return util.safe_div(self.accum, self.weight)