


'''simple docstring'''






import pytest

from datasets.utils.sharding import _distribute_shards, _number_of_shards_in_gen_kwargs, _split_gen_kwargs







@pytest.mark.parametrize(
    """kwargs, expected"""							,    [
        ({"""num_shards""": 0, """max_num_jobs""": 1}, []),
        ({"""num_shards""": 10, """max_num_jobs""": 1}, [range(10					)]),
        ({"""num_shards""": 10, """max_num_jobs""": 10}, [range(A__							,    i + 1					) for i in range(10					)]),
        ({"""num_shards""": 1, """max_num_jobs""": 10}, [range(1					)]),
        ({"""num_shards""": 10, """max_num_jobs""": 3}, [range(0							,    4					), range(4							,    7					), range(7							,    10					)]),
        ({"""num_shards""": 3, """max_num_jobs""": 10}, [range(0							,    1					), range(1							,    2					), range(2							,    3					)]),
    ]							,    )
def 				UpperCamelCase_			(    A__					:   Any							,    A__					:   List[Any]					):
  '''simple docstring'''





  lowerCAmelCase_			:      Dict			=   _distribute_shards(**A__					)
  assert out == expected







@pytest.mark.parametrize(
    """gen_kwargs, max_num_jobs, expected"""							,    [
        ({"""foo""": 0}, 10, [{"""foo""": 0}]),
        ({"""shards""": [0, 1, 2, 3]}, 1, [{"""shards""": [0, 1, 2, 3]}]),
        ({"""shards""": [0, 1, 2, 3]}, 4, [{"""shards""": [0]}, {"""shards""": [1]}, {"""shards""": [2]}, {"""shards""": [3]}]),
        ({"""shards""": [0, 1]}, 4, [{"""shards""": [0]}, {"""shards""": [1]}]),
        ({"""shards""": [0, 1, 2, 3]}, 2, [{"""shards""": [0, 1]}, {"""shards""": [2, 3]}]),
    ]							,    )
def 				UpperCamelCase_			(    A__					:   Union[str, Any]							,    A__					:   Optional[Any]							,    A__					:   List[Any]					):
  '''simple docstring'''





  lowerCAmelCase_			:      Optional[int]			=   _split_gen_kwargs(A__							,    A__					)
  assert out == expected







@pytest.mark.parametrize(
    """gen_kwargs, expected"""							,    [
        ({"""foo""": 0}, 1),
        ({"""shards""": [0]}, 1),
        ({"""shards""": [0, 1, 2, 3]}, 4),
        ({"""shards""": [0, 1, 2, 3], """foo""": 0}, 4),
        ({"""shards""": [0, 1, 2, 3], """other""": (0, 1)}, 4),
        ({"""shards""": [0, 1, 2, 3], """shards2""": [0, 1]}, RuntimeError),
    ]							,    )
def 				UpperCamelCase_			(    A__					:   Tuple							,    A__					:   List[Any]					):
  '''simple docstring'''





  if expected is RuntimeError:
    with pytest.raises(A__					):
      _number_of_shards_in_gen_kwargs(A__					)
  else:
    lowerCAmelCase_			:      Optional[Any]			=   _number_of_shards_in_gen_kwargs(A__					)
    assert out == expected







'''simple docstring'''






from statistics import mean, stdev







def 				UpperCamelCase_			(    A__					:   list							,    A__					:   int = 3					):
  '''simple docstring'''





  lowerCAmelCase_			:      List[str]			=   min(A__					)
  lowerCAmelCase_			:      Optional[int]			=   max(A__					)
  # normalize data
  return [round((x - x_min) / (x_max - x_min)							,    A__					) for x in data]







def 				UpperCamelCase_			(    A__					:   list							,    A__					:   int = 3					):
  '''simple docstring'''





  lowerCAmelCase_			:      str			=   mean(A__					)
  lowerCAmelCase_			:      List[Any]			=   stdev(A__					)
  # standardize data
  return [round((x - mu) / (sigma)							,    A__					) for x in data]



