



def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							_lowerCAmelCase     :							Tuple    =    abs(_lowerCamelCase  )
							_lowerCAmelCase     :							Optional[int]    =    0
							while n > 0:
														res += n % 10
														n //= 10
							return res






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							_lowerCAmelCase     :							Optional[Any]    =    abs(_lowerCamelCase  )
							return n if n < 10 else n % 10 + sum_of_digits(n // 10  )






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							return sum(int(_lowerCamelCase  ) for c in str(abs(_lowerCamelCase  )  )  )






def 				A				(					):





							'''simple docstring'''




							from collections.abc import Callable
							from timeit import timeit

							def benchmark_a_function(_lowerCamelCase				, _lowerCamelCase  ) -> None:
														_lowerCAmelCase     :							Optional[Any]    =    F"{func.__name__}({value})"
														_lowerCAmelCase     :							str    =    timeit(F"__main__.{call}"				, setup="import __main__"  )
														print(F"{call:56} = {func(_lowerCamelCase  )} -- {timing:.4f} seconds"  )

							for value in (262_144, 1_125_899_906_842_624, 1_267_650_600_228_229_401_496_703_205_376):
														for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
																					benchmark_a_function(_lowerCamelCase				, _lowerCamelCase  )
														print()


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						benchmark()





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(_lowerCamelCase				, 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 				A				(					_lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




							_lowerCAmelCase     :							List[Any]    =    _distribute_shards(**_lowerCamelCase  )
							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 				A				(					_lowerCamelCase				, _lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




							_lowerCAmelCase     :							Optional[int]    =    _split_gen_kwargs(_lowerCamelCase				, _lowerCamelCase  )
							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 				A				(					_lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




							if expected is RuntimeError:
														with pytest.raises(_lowerCamelCase  ):
																					_number_of_shards_in_gen_kwargs(_lowerCamelCase  )
							else:
														_lowerCAmelCase     :							Optional[int]    =    _number_of_shards_in_gen_kwargs(_lowerCamelCase  )
														assert out == expected
