


'''simple docstring'''


import contextlib
from multiprocessing import Pool, RLock

from tqdm.auto import tqdm

from ..utils import experimental, logging


UpperCAmelCase_						:  Optional[int]				  =						logging.get_logger(__name__)





class        lowercase__    :





							'''simple docstring'''


							A_				: Union[str, Any]       =    None







@experimental
def      snake_case_  (    SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__	):







				"""simple docstring"""





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

				return _map_with_joblib(SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__	)







def      snake_case_  (    SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__	):







				"""simple docstring"""





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

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

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

				return mapped







def      snake_case_  (    SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__	):







				"""simple docstring"""





				import joblib

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







@experimental
@contextlib.contextmanager
def      snake_case_  (    SCREAMING_SNAKE_CASE__	):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE					:			List[Any]							= 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:
								_SCREAMING_SNAKE_CASE					:			str							= None








'''simple docstring'''


import math







def      snake_case_  (    SCREAMING_SNAKE_CASE__	):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE					:			Tuple							= math.loga(math.sqrt(4 * positive_integer + 1	) / 2 + 1 / 2	)

				return exponent == int(SCREAMING_SNAKE_CASE__	)







def      snake_case_  (    SCREAMING_SNAKE_CASE__ = 1 / 1_2345	):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE					:			str							= 0
				_SCREAMING_SNAKE_CASE					:			str							= 0

				_SCREAMING_SNAKE_CASE					:			int							= 3
				while True:
								_SCREAMING_SNAKE_CASE					:			Optional[int]							= (integer**2 - 1) / 4
								# if candidate is an integer, then there is a partition for k
								if partition_candidate == int(SCREAMING_SNAKE_CASE__	):
												_SCREAMING_SNAKE_CASE					:			int							= int(SCREAMING_SNAKE_CASE__	)
												total_partitions += 1
												if check_partition_perfect(SCREAMING_SNAKE_CASE__	):
																perfect_partitions += 1
								if perfect_partitions > 0:
												if perfect_partitions / total_partitions < max_proportion:
																return int(SCREAMING_SNAKE_CASE__	)
								integer += 1


if __name__ == "__main__":
				print(F"{solution() = }")




