





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 			_a		(       UpperCAmelCase	)							->							Tuple:  # picklable for multiprocessing







   """simple docstring"""
   return i + 1



@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 			_a		(       )							->							Dict:







   """simple docstring"""

   with parallel_backend('''spark'''	):
      assert ParallelBackendConfig.backend_name == "spark"

   lowerCamelCase__  :		Dict     =				[1, 2, 3]
   with pytest.raises(__a	):
      with parallel_backend('''unsupported backend'''	):
         map_nested(__a     ,    __a     ,    num_proc=2	)

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




@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('''num_proc'''     ,    [2, -1]	)
def 			_a		(       UpperCAmelCase	)							->							Union[str, Any]:







   """simple docstring"""
   lowerCamelCase__  :		Optional[Any]     =				[1, 2]
   lowerCamelCase__  :		Dict     =				{'''a''': 1, '''b''': 2}
   lowerCamelCase__  :		Any     =				{'''a''': [1, 2], '''b''': [3, 4]}
   lowerCamelCase__  :		Optional[Any]     =				{'''a''': {'''1''': 1}, '''b''': 2}
   lowerCamelCase__  :		Optional[Any]     =				{'''a''': 1, '''b''': 2, '''c''': 3, '''d''': 4}
   lowerCamelCase__  :		Optional[int]     =				[2, 3]
   lowerCamelCase__  :		Optional[Any]     =				{'''a''': 2, '''b''': 3}
   lowerCamelCase__  :		int     =				{'''a''': [2, 3], '''b''': [4, 5]}
   lowerCamelCase__  :		Any     =				{'''a''': {'''1''': 2}, '''b''': 3}
   lowerCamelCase__  :		Optional[Any]     =				{'''a''': 2, '''b''': 3, '''c''': 4, '''d''': 5}

   with parallel_backend('''spark'''	):
      assert map_nested(__a     ,    __a     ,    num_proc=__a	) == expected_map_nested_sa
      assert map_nested(__a     ,    __a     ,    num_proc=__a	) == expected_map_nested_sa
      assert map_nested(__a     ,    __a     ,    num_proc=__a	) == expected_map_nested_sa
      assert map_nested(__a     ,    __a     ,    num_proc=__a	) == expected_map_nested_sa
      assert map_nested(__a     ,    __a     ,    num_proc=__a	) == expected_map_nested_sa










class     A     :
			'''simple docstring'''




			def __init__(     self  :       Optional[int]  )      ->      Dict:







					"""simple docstring"""






					A__     =  {}






			def   a_			(     self  :       Any  )      ->      None:







					"""simple docstring"""






					print(self.vertex  )
					for i in self.vertex:
							print(__lowerCAmelCase				,      """ -> """				,      """ -> """.join([str(__lowerCAmelCase  ) for j in self.vertex[i]]  )  )






			def   a_			(     self  :       Optional[int]				,      __lowerCAmelCase  :       int				,      __lowerCAmelCase  :       int  )      ->      None:







					"""simple docstring"""






					if from_vertex in self.vertex:
							self.vertex[from_vertex].append(__lowerCAmelCase  )
					else:
							# else make a new vertex
							A__     =  [to_vertex]






			def   a_			(     self  :       List[str]  )      ->      None:







					"""simple docstring"""






					A__     =  [False] * len(self.vertex  )

					# call the recursive helper function
					for i in range(len(self.vertex  )  ):
							if not visited[i]:
									self.dfs_recursive(__lowerCAmelCase				,      __lowerCAmelCase  )







			def   a_			(     self  :       List[str]				,      __lowerCAmelCase  :       int				,      __lowerCAmelCase  :       list  )      ->      None:







					"""simple docstring"""






					A__     =  True

					print(__lowerCAmelCase				,      end=""" """  )

					# Recur for all the vertices that are adjacent to this node
					for i in self.vertex:
							if not visited[i]:
									self.dfs_recursive(__lowerCAmelCase				,      __lowerCAmelCase  )


if __name__ == "__main__":
					A       :   Tuple					= Graph()
					g.add_edge(0, 1)
					g.add_edge(0, 2)
					g.add_edge(1, 2)
					g.add_edge(2, 0)
					g.add_edge(2, 3)
					g.add_edge(3, 3)

					g.print_graph()
					print('''DFS:''')
					g.dfs()

					# OUTPUT:
					# 0  ->  1 -> 2
					# 1  ->  2
					# 2  ->  0 -> 3
					# 3  ->  3
					# DFS:
					#  0 1 2 3



