




'''simple docstring'''







import contextlib
from multiprocessing import Pool, RLock

from tqdm.auto import tqdm

from ..utils import experimental, logging


lowerCAmelCase_     						=				logging.get_logger(__name__)

class 	_snake_case:
 __snake_case:							Optional[Any]						=					None







@experimental
def 						_A      ( UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







   if ParallelBackendConfig.backend_name is None:
      return _map_with_multiprocessing_pool(
          UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase						)

   return _map_with_joblib(UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase						)







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







   A__       =     num_proc if num_proc <= len(UpperCAmelCase						) else len(UpperCAmelCase						)
   A__       =     []  # We organize the splits ourselve (contiguous splits)
   for index in range(UpperCAmelCase						):
      A__       =     len(UpperCAmelCase						) // num_proc
      A__       =     len(UpperCAmelCase						) % num_proc
      A__       =     div * index + min(UpperCAmelCase      ,UpperCAmelCase						)
      A__       =     start + div + (1 if index < mod else 0)
      split_kwds.append((function, iterable[start:end], types, index, disable_tqdm, desc)						)

   if len(UpperCAmelCase						) != sum(len(i[1]						) for i in split_kwds						):
      raise ValueError(
          F"""Error dividing inputs iterable among processes. """
          F"""Total number of objects {len(UpperCAmelCase						)}, """
          F"""length: {sum(len(i[1]						) for i in split_kwds						)}"""						)

   logger.info(
       F"""Spawning {num_proc} processes for {len(UpperCAmelCase						)} objects in slices of {[len(i[1]						) for i in split_kwds]}"""						)
   A__  ,			A__       =     None, None
   if not disable_tqdm:
      A__  ,			A__       =     (RLock(),), tqdm.set_lock
   with Pool(UpperCAmelCase      ,initargs=UpperCAmelCase      ,initializer=UpperCAmelCase						) as pool:
      A__       =     pool.map(UpperCAmelCase      ,UpperCAmelCase						)
   logger.info(F"""Finished {num_proc} processes"""						)
   A__       =     [obj for proc_res in mapped for obj in proc_res]
   logger.info(F"""Unpacked {len(UpperCAmelCase						)} objects"""						)

   return mapped







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







   import joblib

   with joblib.parallel_backend(ParallelBackendConfig.backend_name      ,n_jobs=UpperCAmelCase						):
      return joblib.Parallel()(
          joblib.delayed(UpperCAmelCase						)((function, obj, types, None, True, None)						) for obj in iterable						)







@experimental
@contextlib.contextmanager
def 						_A      ( UpperCAmelCase						):






   '''simple docstring'''







   A__       =     backend_name

   if backend_name == "spark":
      from joblibspark import register_spark

      register_spark()

      # TODO: call create_cache_and_write_probe if "download" in steps
      # TODO: raise NotImplementedError when Dataset.map etc is called

   try:
      yield
   finally:
      A__       =     None








'''simple docstring'''







def 						_A      ( ):






   '''simple docstring'''







   A__       =     [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

   A__       =     6
   A__       =     1
   A__       =     1901

   A__       =     0

   while year < 2001:
      day += 7

      if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
         if day > days_per_month[month - 1] and month != 2:
            month += 1
            A__       =     day - days_per_month[month - 2]
         elif day > 29 and month == 2:
            month += 1
            A__       =     day - 29
      else:
         if day > days_per_month[month - 1]:
            month += 1
            A__       =     day - days_per_month[month - 2]

      if month > 12:
         year += 1
         A__       =     1

      if year < 2001 and day == 1:
         sundays += 1
   return sundays


if __name__ == "__main__":
    print(solution())


