# 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
    return SumStat.new(jnp.sum(target_weight))


@dataclasses.dataclass
class SequenceCount(Metric):
  """Metric for count of non masked sequences.

  Example::

    example = {'y': jnp.array([1, 2, 2, 3, 4, 0, 0])}
    empty_example = {'y': jnp.array([0, 0, 0, 0, 0, 0, 0])}
    prediction = jnp.array([])  # Unused.
    metric = metrics.SequenceCount(masked_target_values=(0, 2))
    print(metric.evaluate_example(example, prediction))
    # SumStat(accum=1)
    print(metric.evaluate_example(empty_example, prediction))
    # SumStat(accum=0)

  Attributes:
    target_key: Key name in ``example`` for target.
    masked_target_values: Target values that should be ignored in computation.
      This is typically used to ignore padding values in computation.
  """
  target_key: str = 'y'
  masked_target_values: Tuple[int, ...] = (0,)

  def zero(self) -> SumStat:
    return SumStat.new(0.)

  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

    return SumStat.new(jnp.sum(target_weight))


@dataclasses.dataclass
class SequenceCount(Metric):
  """Metric for count of non masked sequences.

  Example::

    example = {'y': jnp.array([1, 2, 2, 3, 4, 0, 0])}
    empty_example = {'y': jnp.array([0, 0, 0, 0, 0, 0, 0])}
    prediction = jnp.array([])  # Unused.
    metric = metrics.SequenceCount(masked_target_values=(0, 2))
    print(metric.evaluate_example(example, prediction))
    # SumStat(accum=1)
    print(metric.evaluate_example(empty_example, prediction))
    # SumStat(accum=0)

  Attributes:
    target_key: Key name in ``example`` for target.
    masked_target_values: Target values that should be ignored in computation.
      This is typically used to ignore padding values in computation.
  """
  target_key: str = 'y'
  masked_target_values: Tuple[int, ...] = (0,)

  def zero(self) -> SumStat:
    return SumStat.new(0.)

  def evaluate_example(self, example: SingleExample,

                       prediction: SinglePrediction) -> SumStat: