# Path: rigl/experimental/jax/pruning/masked.py
# def masked(module, mask):
#   """Convenience function for masking a FLAX module with MaskedModule."""
#   return MaskedModule.partial(wrapped_module=module, mask=mask)
# 
# Path: rigl/experimental/jax/utils/utils.py
# def cross_entropy_loss(log_softmax_logits,
#                        labels):
# def compute_metrics(logits,
#                     labels):
# def _np_converter(obj):
# def dump_dict_json(data_dict, path):
# def count_param(model,
#                 param_names):
# def cosine_similarity(a, b):
# def param_as_array(params):
# def cosine_similarity_model(initial_model,
#                             current_model):
# def vector_difference_norm_model(initial_model,
#                                  current_model):
# def pairwise_longest(iterable):
# T = TypeVar('T')


import functools
import math
import operator
import jax.numpy as jnp
import numpy as np
from typing import Dict, Optional, Union
from rigl.experimental.jax.pruning import masked
from rigl.experimental.jax.utils import utils
  # there is a type conflict in passing iterators of different types to
  # itertools.chain.
  counts = [
      count_permutations_mask_layer(layer, next_layer)
      for layer, next_layer in utils.pairwise_longest(mask.values())
  ]

  sum_stats = {}
  for key in sum_keys:
    sum_stats[key] = functools.reduce(operator.add, (z[key] for z in counts))

  product_stats = {}
  for key in product_keys:
    product_stats[key] = functools.reduce(operator.mul,
                                          (z[key] for z in counts))

  return {**sum_stats, **product_stats}


def get_mask_stats(mask):
  """Calculates an array of mask statistics.

  Args:
    mask: A model mask to calculate the statistics of.

  Returns:
    A dictionary, containing a set of mask statistics.
  """
  mask_stats = count_permutations_mask(mask)
  mask_stats.update({

# Path: rigl/experimental/jax/pruning/masked.py
# def masked(module, mask):
#   """Convenience function for masking a FLAX module with MaskedModule."""
#   return MaskedModule.partial(wrapped_module=module, mask=mask)
# 
# Path: rigl/experimental/jax/utils/utils.py
# def cross_entropy_loss(log_softmax_logits,
#                        labels):
# def compute_metrics(logits,
#                     labels):
# def _np_converter(obj):
# def dump_dict_json(data_dict, path):
# def count_param(model,
#                 param_names):
# def cosine_similarity(a, b):
# def param_as_array(params):
# def cosine_similarity_model(initial_model,
#                             current_model):
# def vector_difference_norm_model(initial_model,
#                                  current_model):
# def pairwise_longest(iterable):
# T = TypeVar('T')


# Path: rigl/experimental/jax/pruning/symmetry.py
import functools
import math
import operator
import jax.numpy as jnp
import numpy as np
from typing import Dict, Optional, Union
from rigl.experimental.jax.pruning import masked
from rigl.experimental.jax.utils import utils

  # there is a type conflict in passing iterators of different types to
  # itertools.chain.
  counts = [
      count_permutations_mask_layer(layer, next_layer)
      for layer, next_layer in utils.pairwise_longest(mask.values())
  ]

  sum_stats = {}
  for key in sum_keys:
    sum_stats[key] = functools.reduce(operator.add, (z[key] for z in counts))

  product_stats = {}
  for key in product_keys:
    product_stats[key] = functools.reduce(operator.mul,
                                          (z[key] for z in counts))

  return {**sum_stats, **product_stats}


def get_mask_stats(mask):
  """Calculates an array of mask statistics.

  Args:
    mask: A model mask to calculate the statistics of.

  Returns:
    A dictionary, containing a set of mask statistics.
  """
  mask_stats = count_permutations_mask(mask)
  mask_stats.update({

      'sparsity': masked.mask_sparsity(mask),