






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 					snake_case_						(   lowerCAmelCase_				:  List[Any]					):  # picklable for multiprocessing
							return i + 1
@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 					snake_case_						(   ):
							with parallel_backend("""spark"""					):
														assert ParallelBackendConfig.backend_name == "spark"

							__lowercase					:							List[Any]			=   [1, 2, 3]
							with pytest.raises(lowerCAmelCase_					):
														with parallel_backend("""unsupported backend"""					):
																					map_nested(lowerCAmelCase_				,				lowerCAmelCase_				,				num_proc=2					)

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



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

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







import math

class 						lowerCAmelCase   :

					'''simple docstring'''

					def __init__(     self :		Tuple						,   __a :		int=0							)	->     Optional[Any]:  # a graph with Node 0,1,...,N-1


												"""simple docstring"""

												__lowercase					:							Any			=   n
												__lowercase					:							Optional[int]			=   [
												    [math.inf for j in range(0						,   __a							)] for i in range(0						,   __a							)
												]  # adjacency matrix for weight
												__lowercase					:							Dict			=   [
												    [math.inf for j in range(0						,   __a							)] for i in range(0						,   __a							)
												]  # dp[i][j] stores minimum distance from i to j



					def 					lowerCAmelCase (     self :		int						,   __a :		Optional[int]						,   __a :		Tuple						,   __a :		Dict							)	->     Dict:


												"""simple docstring"""

												__lowercase					:							Any			=   w



					def 					lowerCAmelCase (     self :		List[str]							)	->     Tuple:


												"""simple docstring"""

												for k in range(0						,   self.n							):
																			for i in range(0						,   self.n							):
																										for j in range(0						,   self.n							):
																																	__lowercase					:							List[str]			=   min(self.dp[i][j]						,   self.dp[i][k] + self.dp[k][j]							)



					def 					lowerCAmelCase (     self :		Any						,   __a :		Any						,   __a :		str							)	->     int:


												"""simple docstring"""

												return self.dp[u][v]


if __name__ == "__main__":
	lowerCamelCase       :       int        =				Graph(5)
	graph.add_edge(0, 2, 9)
	graph.add_edge(0, 4, 10)
	graph.add_edge(1, 3, 5)
	graph.add_edge(2, 3, 7)
	graph.add_edge(3, 0, 10)
	graph.add_edge(3, 1, 2)
	graph.add_edge(3, 2, 1)
	graph.add_edge(3, 4, 6)
	graph.add_edge(4, 1, 3)
	graph.add_edge(4, 2, 4)
	graph.add_edge(4, 3, 9)
	graph.floyd_warshall()
	graph.show_min(1, 4)
	graph.show_min(0, 3)