# Path: fedjax/aggregators/compression.py
# class CompressionState:
# def binary_stochastic_quantize(v: jnp.ndarray,
#                                rng: PRNGKey,
#                                v_min: Optional[float] = None,
#                                v_max: Optional[float] = None) -> jnp.ndarray:
# def uniform_stochastic_quantize(v: jnp.ndarray,
#                                 num_levels: int,
#                                 rng: PRNGKey,
#                                 v_min: Optional[float] = None,
#                                 v_max: Optional[float] = None) -> jnp.ndarray:
# def uniform_stochastic_quantize_pytree(params: Params, num_levels: int,
#                                        rng: PRNGKey) -> Params:
# def num_leaves(pytree):
# def _entropy(v, uniq):
# def _hist_bits(v, uniq):
# def arithmetic_encoding_num_bits(v: jnp.ndarray) -> int:
# def uniform_stochastic_quantizer(
#     num_levels: int,
#     rng: PRNGKey,
#     encode_algorithm: Optional[str] = None) -> aggregator.Aggregator:
#   def init():
#   def apply(
#       clients_params_and_weights: Iterable[Tuple[ClientId, Params, float]],
#       aggregator_state: CompressionState) -> Tuple[Params, CompressionState]:
#     def quantize_params_and_weight(client_params_and_weight, rng):
#       def arithmetic_encoding_num_bits_pytree(params, weights):
# def rotated_uniform_stochastic_quantizer(num_levels: int,
#                                          rng: PRNGKey) -> aggregator.Aggregator:
#   def init():
#   def apply(
#       clients_params_and_weights: Iterable[Tuple[ClientId, Params, float]],
#       aggregator_state: CompressionState) -> Tuple[Params, CompressionState]:
#     def quantize_params_and_weight(client_params_and_weight, rng):
# def drive_pytree(params: Params) -> Params:
# def structured_drive_quantizer(rng: PRNGKey) -> aggregator.Aggregator:
#   def init():
#   def apply(
#       clients_params_and_weights: Iterable[Tuple[ClientId, Params, float]],
#       aggregator_state: CompressionState) -> Tuple[Params, CompressionState]:
#     def quantize_params_and_weight(client_id, params, weight):
# def terngrad_quantize(v: jnp.ndarray, rng: PRNGKey) -> jnp.ndarray:
# def terngrad_quantize_pytree(params: Params, rng: PRNGKey) -> Params:
# def terngrad_quantizer(rng: PRNGKey) -> aggregator.Aggregator:
#   def init():
#   def apply(
#       clients_params_and_weights: Iterable[Tuple[ClientId, Params, float]],
#       aggregator_state: CompressionState) -> Tuple[Params, CompressionState]:
#     def quantize_params_and_weight(client_params_and_weight, rng):


from absl.testing import absltest
from fedjax.aggregators import compression
import jax
import jax.numpy as jnp
import numpy.testing as npt
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for fedjax.aggregators.compression."""



class CompressionTest(absltest.TestCase):

  def test_num_leaves(self):
    params = {'w': jnp.array([1., 2., 3.]), 'b': jnp.array([1.])}

# Path: fedjax/aggregators/compression.py
# class CompressionState:
# def binary_stochastic_quantize(v: jnp.ndarray,
#                                rng: PRNGKey,
#                                v_min: Optional[float] = None,
#                                v_max: Optional[float] = None) -> jnp.ndarray:
# def uniform_stochastic_quantize(v: jnp.ndarray,
#                                 num_levels: int,
#                                 rng: PRNGKey,
#                                 v_min: Optional[float] = None,
#                                 v_max: Optional[float] = None) -> jnp.ndarray:
# def uniform_stochastic_quantize_pytree(params: Params, num_levels: int,
#                                        rng: PRNGKey) -> Params:
# def num_leaves(pytree):
# def _entropy(v, uniq):
# def _hist_bits(v, uniq):
# def arithmetic_encoding_num_bits(v: jnp.ndarray) -> int:
# def uniform_stochastic_quantizer(
#     num_levels: int,
#     rng: PRNGKey,
#     encode_algorithm: Optional[str] = None) -> aggregator.Aggregator:
#   def init():
#   def apply(
#       clients_params_and_weights: Iterable[Tuple[ClientId, Params, float]],
#       aggregator_state: CompressionState) -> Tuple[Params, CompressionState]:
#     def quantize_params_and_weight(client_params_and_weight, rng):
#       def arithmetic_encoding_num_bits_pytree(params, weights):
# def rotated_uniform_stochastic_quantizer(num_levels: int,
#                                          rng: PRNGKey) -> aggregator.Aggregator:
#   def init():
#   def apply(
#       clients_params_and_weights: Iterable[Tuple[ClientId, Params, float]],
#       aggregator_state: CompressionState) -> Tuple[Params, CompressionState]:
#     def quantize_params_and_weight(client_params_and_weight, rng):
# def drive_pytree(params: Params) -> Params:
# def structured_drive_quantizer(rng: PRNGKey) -> aggregator.Aggregator:
#   def init():
#   def apply(
#       clients_params_and_weights: Iterable[Tuple[ClientId, Params, float]],
#       aggregator_state: CompressionState) -> Tuple[Params, CompressionState]:
#     def quantize_params_and_weight(client_id, params, weight):
# def terngrad_quantize(v: jnp.ndarray, rng: PRNGKey) -> jnp.ndarray:
# def terngrad_quantize_pytree(params: Params, rng: PRNGKey) -> Params:
# def terngrad_quantizer(rng: PRNGKey) -> aggregator.Aggregator:
#   def init():
#   def apply(
#       clients_params_and_weights: Iterable[Tuple[ClientId, Params, float]],
#       aggregator_state: CompressionState) -> Tuple[Params, CompressionState]:
#     def quantize_params_and_weight(client_params_and_weight, rng):


# Path: fedjax/aggregators/compression_test.py
from absl.testing import absltest
from fedjax.aggregators import compression
import jax
import jax.numpy as jnp
import numpy.testing as npt

# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for fedjax.aggregators.compression."""



class CompressionTest(absltest.TestCase):

  def test_num_leaves(self):
    params = {'w': jnp.array([1., 2., 3.]), 'b': jnp.array([1.])}

    self.assertEqual(compression.num_leaves(params), 2)