# 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/pruning/symmetry.py
# def count_permutations_mask_layer(
#     mask_layer,
#     next_mask_layer = None,
#     parameter_key = 'kernel'):
# def count_permutations_mask(mask):
# def get_mask_stats(mask):


import functools
import math
import operator
import flax
import jax
import jax.numpy as jnp
import numpy as np
from typing import Mapping, Optional, Sequence
from absl.testing import absltest
from absl.testing import parameterized
from rigl.experimental.jax.pruning import masked
from rigl.experimental.jax.pruning import symmetry
  def test_count_permutations_layer_mask_empty(self):
    """Tests count of weight permutations in an empty mask."""
    mask_layer = {
        'kernel':
            jnp.zeros(self._masked_model.params['MaskedModule_0']['unmasked']
                      ['kernel'].shape),
    }

    stats = symmetry.count_permutations_mask_layer(mask_layer)

    with self.subTest(name='count_permutations_mask_unique'):
      self.assertEqual(stats['unique_neurons'], 0)

    with self.subTest(name='count_permutations_permutations'):
      self.assertEqual(stats['permutations'], 0)

    with self.subTest(name='count_permutations_zeroed'):
      self.assertEqual(stats['zeroed_neurons'], MaskedDense.NUM_FEATURES)

    with self.subTest(name='count_permutations_total'):
      self.assertEqual(stats['total_neurons'], MaskedDense.NUM_FEATURES)

  def test_count_permutations_conv_layer_mask_full(self):
    """Tests count of weight permutations in a full mask for a conv. layer."""
    mask_layer = {
        'kernel':
            jnp.ones(self._masked_conv_model.params['MaskedModule_0']
                     ['unmasked']['kernel'].shape),
    }


# 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/pruning/symmetry.py
# def count_permutations_mask_layer(
#     mask_layer,
#     next_mask_layer = None,
#     parameter_key = 'kernel'):
# def count_permutations_mask(mask):
# def get_mask_stats(mask):


# Path: rigl/experimental/jax/pruning/symmetry_test.py
import functools
import math
import operator
import flax
import jax
import jax.numpy as jnp
import numpy as np
from typing import Mapping, Optional, Sequence
from absl.testing import absltest
from absl.testing import parameterized
from rigl.experimental.jax.pruning import masked
from rigl.experimental.jax.pruning import symmetry

  def test_count_permutations_layer_mask_empty(self):
    """Tests count of weight permutations in an empty mask."""
    mask_layer = {
        'kernel':
            jnp.zeros(self._masked_model.params['MaskedModule_0']['unmasked']
                      ['kernel'].shape),
    }

    stats = symmetry.count_permutations_mask_layer(mask_layer)

    with self.subTest(name='count_permutations_mask_unique'):
      self.assertEqual(stats['unique_neurons'], 0)

    with self.subTest(name='count_permutations_permutations'):
      self.assertEqual(stats['permutations'], 0)

    with self.subTest(name='count_permutations_zeroed'):
      self.assertEqual(stats['zeroed_neurons'], MaskedDense.NUM_FEATURES)

    with self.subTest(name='count_permutations_total'):
      self.assertEqual(stats['total_neurons'], MaskedDense.NUM_FEATURES)

  def test_count_permutations_conv_layer_mask_full(self):
    """Tests count of weight permutations in a full mask for a conv. layer."""
    mask_layer = {
        'kernel':
            jnp.ones(self._masked_conv_model.params['MaskedModule_0']
                     ['unmasked']['kernel'].shape),
    }


    stats = symmetry.count_permutations_mask_layer(mask_layer)