



'''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   a_   (		_UpperCAmelCase    :      Any				)    ->  Dict:  # picklable for multiprocessing
      return i + 1





@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def   a_   (		)    ->  Dict:
      with parallel_backend('spark'				):
            assert ParallelBackendConfig.backend_name == "spark"

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





import functools





def   a_   (		_UpperCAmelCase    :      list[int] ,_UpperCAmelCase    :      list[int]				)    ->  int:

      # Validation
      if not isinstance(_UpperCAmelCase ,_UpperCAmelCase				) or not all(isinstance(_UpperCAmelCase ,_UpperCAmelCase				) for day in days				):
            raise ValueError('The parameter days should be a list of integers'				)

      if len(_UpperCAmelCase				) != 3 or not all(isinstance(_UpperCAmelCase ,_UpperCAmelCase				) for cost in costs				):
            raise ValueError('The parameter costs should be a list of three integers'				)

      if len(_UpperCAmelCase				) == 0:
            return 0

      if min(_UpperCAmelCase				) <= 0:
            raise ValueError('All days elements should be greater than 0'				)

      if max(_UpperCAmelCase				) >= 3_66:
            raise ValueError('All days elements should be less than 366'				)

      __snake_case :   str													=    set(_UpperCAmelCase				)

      @functools.cache
      def dynamic_programming(_UpperCAmelCase    :      int				) -> int:
            if index > 3_65:
                  return 0

            if index not in days_set:
                  return dynamic_programming(index + 1				)

            return min(
                costs[0] + dynamic_programming(index + 1				) ,costs[1] + dynamic_programming(index + 7				) ,costs[2] + dynamic_programming(index + 30				) ,)

      return dynamic_programming(1				)


if __name__ == "__main__":
    import doctest

    doctest.testmod()



