

'''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 					__UpperCamelCase				(						lowercase__    :	Optional[Any]			):  # picklable for multiprocessing






     '''simple docstring'''





     return i + 1

@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 					__UpperCamelCase				(						):






     '''simple docstring'''





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

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

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







@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('num_proc',       [2, -1]			)
def 					__UpperCamelCase				(						lowercase__    :	Optional[Any]			):






     '''simple docstring'''





     __lowercase      		=[1, 2]
     __lowercase      		={'a': 1, 'b': 2}
     __lowercase      		={'a': [1, 2], 'b': [3, 4]}
     __lowercase      		={'a': {'1': 1}, 'b': 2}
     __lowercase      		={'a': 1, 'b': 2, 'c': 3, 'd': 4}
     __lowercase      		=[2, 3]
     __lowercase      		={'a': 2, 'b': 3}
     __lowercase      		={'a': [2, 3], 'b': [4, 5]}
     __lowercase      		={'a': {'1': 2}, 'b': 3}
     __lowercase      		={'a': 2, 'b': 3, 'c': 4, 'd': 5}

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





'''simple docstring'''

def 					__UpperCamelCase				(						lowercase__    :	int			):






     '''simple docstring'''





     if upper_limit < 0:
          raise ValueError('Limit for the Catalan sequence must be ≥ 0'			)

     __lowercase      		=[0] * (upper_limit + 1)

     # Base case: C(0) = C(1) = 1
     __lowercase      		=1
     if upper_limit > 0:
          __lowercase      		=1

     # Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i
     for i in range(2,       upper_limit + 1			):
          for j in range(lowercase__			):
               catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1]

     return catalan_list


if __name__ == "__main__":
       print('''\n********* Catalan Numbers Using Dynamic Programming ************\n''')
       print('''\n*** Enter -1 at any time to quit ***''')
       print('''\nEnter the upper limit (≥ 0) for the Catalan number sequence: ''', end='''''')
       try:
              while True:
                     UpperCAmelCase					 =	int(input().strip())
                     if N < 0:
                            print('''\n********* Goodbye!! ************''')
                            break
                     else:
                            print(F'''The Catalan numbers from 0 through {N} are:''')
                            print(catalan_numbers(N))
                            print('''Try another upper limit for the sequence: ''', end='''''')
       except (NameError, ValueError):
              print('''\n********* Invalid input, goodbye! ************\n''')

       import doctest

       doctest.testmod()


