






'''simple docstring'''







import pytest

from datasets.parallel import ParallelBackendConfig, parallel_backend
from datasets.utils.py_utils import map_nested

from .utils import require_dill_gt_0_3_2, require_joblibspark, require_not_windows





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	List[Any]:  # picklable for multiprocessing
							return i + 1





@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 			SCREAMING_SNAKE_CASE_	()				->	int:
							with parallel_backend("""spark"""				):
														assert ParallelBackendConfig.backend_name == "spark"

							lowerCamelCase__ :     Optional[Any]	  =	[1, 2, 3]
							with pytest.raises(UpperCamelCase				):
														with parallel_backend("""unsupported backend"""				):
																					map_nested(UpperCamelCase    ,      UpperCamelCase    ,      num_proc=2				)

							with pytest.raises(UpperCamelCase				):
														with parallel_backend("""unsupported backend"""				):
																					map_nested(UpperCamelCase    ,      UpperCamelCase    ,      num_proc=-1				)





@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize("""num_proc"""    ,      [2, -1]				)
def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	Optional[Any]:
							lowerCamelCase__ :     Any	  =	[1, 2]
							lowerCamelCase__ :     List[Any]	  =	{"""a""": 1, """b""": 2}
							lowerCamelCase__ :     List[Any]	  =	{"""a""": [1, 2], """b""": [3, 4]}
							lowerCamelCase__ :     Any	  =	{"""a""": {"""1""": 1}, """b""": 2}
							lowerCamelCase__ :     List[Any]	  =	{"""a""": 1, """b""": 2, """c""": 3, """d""": 4}
							lowerCamelCase__ :     Union[str, Any]	  =	[2, 3]
							lowerCamelCase__ :     Tuple	  =	{"""a""": 2, """b""": 3}
							lowerCamelCase__ :     str	  =	{"""a""": [2, 3], """b""": [4, 5]}
							lowerCamelCase__ :     int	  =	{"""a""": {"""1""": 2}, """b""": 3}
							lowerCamelCase__ :     Dict	  =	{"""a""": 2, """b""": 3, """c""": 4, """d""": 5}

							with parallel_backend("""spark"""				):
														assert map_nested(UpperCamelCase    ,      UpperCamelCase    ,      num_proc=UpperCamelCase				) == expected_map_nested_sa
														assert map_nested(UpperCamelCase    ,      UpperCamelCase    ,      num_proc=UpperCamelCase				) == expected_map_nested_sa
														assert map_nested(UpperCamelCase    ,      UpperCamelCase    ,      num_proc=UpperCamelCase				) == expected_map_nested_sa
														assert map_nested(UpperCamelCase    ,      UpperCamelCase    ,      num_proc=UpperCamelCase				) == expected_map_nested_sa
														assert map_nested(UpperCamelCase    ,      UpperCamelCase    ,      num_proc=UpperCamelCase				) == expected_map_nested_sa









'''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()

