






'''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(UpperCamelCase    ,      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 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase				)				->	str:
							lowerCamelCase__ :     Tuple	  =	_distribute_shards(**UpperCamelCase				)
							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 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase				)				->	str:
							lowerCamelCase__ :     Tuple	  =	_split_gen_kwargs(UpperCamelCase    ,      UpperCamelCase				)
							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 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase				)				->	Optional[int]:
							if expected is RuntimeError:
														with pytest.raises(UpperCamelCase				):
																					_number_of_shards_in_gen_kwargs(UpperCamelCase				)
							else:
														lowerCamelCase__ :     Optional[Any]	  =	_number_of_shards_in_gen_kwargs(UpperCamelCase				)
														assert out == expected









'''simple docstring'''







from __future__ import annotations

import typing
from collections.abc import Iterable

import numpy as np

_A     :      Optional[Any]   					=typing.Union[Iterable[float], Iterable[int], np.ndarray]  # noqa: UP007
_A     :      Optional[int]   					=typing.Union[np.floataa, int, float]  # noqa: UP007





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase				)				->	VectorOut:
							return np.sqrt(np.sum((np.asarray(UpperCamelCase				) - np.asarray(UpperCamelCase				)) ** 2				)				)





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase				)				->	VectorOut:
							return sum((va - va) ** 2 for va, va in zip(UpperCamelCase    ,      UpperCamelCase				)				) ** (1 / 2)


if __name__ == "__main__":





			def 			SCREAMING_SNAKE_CASE_	()				->	None:
										from timeit import timeit

										print("""Without Numpy"""				)
										print(
										    timeit(
										        """euclidean_distance_no_np([1, 2, 3], [4, 5, 6])"""    ,      number=10000    ,      globals=globals()    ,      )				)
										print("""With Numpy"""				)
										print(
										    timeit(
										        """euclidean_distance([1, 2, 3], [4, 5, 6])"""    ,      number=10000    ,      globals=globals()    ,      )				)



			benchmark()

