


'''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 				lowerCAmelCase__	(    lowerCamelCase					:      List[str]       ):  # picklable for multiprocessing
       return i + 1






@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 				lowerCAmelCase__	(    ):
       with parallel_backend('spark'       ):
              assert ParallelBackendConfig.backend_name == "spark"

       _A					:     Optional[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 				lowerCAmelCase__	(    lowerCamelCase					:      int       ):
       _A					:     Dict     = [1, 2]
       _A					:     int     = {'a': 1, 'b': 2}
       _A					:     Tuple     = {'a': [1, 2], 'b': [3, 4]}
       _A					:     Optional[Any]     = {'a': {'1': 1}, 'b': 2}
       _A					:     Tuple     = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
       _A					:     List[Any]     = [2, 3]
       _A					:     str     = {'a': 2, 'b': 3}
       _A					:     Optional[int]     = {'a': [2, 3], 'b': [4, 5]}
       _A					:     Union[str, Any]     = {'a': {'1': 2}, 'b': 3}
       _A					:     Dict     = {'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










'''simple docstring'''







class 			__lowerCamelCase			:  # Public class to implement a graph
    """simple docstring"""


    def __init__(  self      :							Optional[Any]				,							SCREAMING_SNAKE_CASE      :							int				,							SCREAMING_SNAKE_CASE      :							int				,							SCREAMING_SNAKE_CASE      :							list[list[bool]]):
           _A					:     List[Any]     = row
           _A					:     Union[str, Any]     = col
           _A					:     List[str]     = graph


    def        A   (  self      :							Any				,							SCREAMING_SNAKE_CASE      :							int				,							SCREAMING_SNAKE_CASE      :							int				,							SCREAMING_SNAKE_CASE      :							list[list[bool]]):
           return (
               0 <= i < self.ROW
               and 0 <= j < self.COL
               and not visited[i][j]
               and self.graph[i][j]
           )


    def        A   (  self      :							Tuple				,							SCREAMING_SNAKE_CASE      :							int				,							SCREAMING_SNAKE_CASE      :							int				,							SCREAMING_SNAKE_CASE      :							list[list[bool]]):
           # Checking all 8 elements surrounding nth element
           _A					:     Tuple     = [-1, -1, -1, 0, 0, 1, 1, 1]  # Coordinate order
           _A					:     Dict     = [-1, 0, 1, -1, 1, -1, 0, 1]
           _A					:     List[Any]     = True  # Make those cells visited
           for k in range(8):
                  if self.is_safe(i + row_nbr[k]				,							j + col_nbr[k]				,							SCREAMING_SNAKE_CASE):
                         self.diffs(i + row_nbr[k]				,							j + col_nbr[k]				,							SCREAMING_SNAKE_CASE)


    def        A   (  self      :							int):  # And finally, count all islands.
           _A					:     Dict     = [[False for j in range(self.COL)] for i in range(self.ROW)]
           _A					:     Union[str, Any]     = 0
           for i in range(self.ROW):
                  for j in range(self.COL):
                         if visited[i][j] is False and self.graph[i][j] == 1:
                                self.diffs(SCREAMING_SNAKE_CASE				,							SCREAMING_SNAKE_CASE				,							SCREAMING_SNAKE_CASE)
                                count += 1
           return count






