






'''simple docstring'''







import contextlib
from multiprocessing import Pool, RLock

from tqdm.auto import tqdm

from ..utils import experimental, logging


_A     :      str   					=logging.get_logger(__name__)

class _lowercase     :
							a    				=	None





@experimental
def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase				)				->	Dict:
							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 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase				)				->	int:
							lowerCamelCase__ :     Any	  =	num_proc if num_proc <= len(UpperCamelCase				) else len(UpperCamelCase				)
							lowerCamelCase__ :     int	  =	[]  # We organize the splits ourselve (contiguous splits)
							for index in range(UpperCamelCase				):
														lowerCamelCase__ :     List[str]	  =	len(UpperCamelCase				) // num_proc
														lowerCamelCase__ :     Optional[Any]	  =	len(UpperCamelCase				) % num_proc
														lowerCamelCase__ :     List[Any]	  =	div * index + min(UpperCamelCase    ,      UpperCamelCase				)
														lowerCamelCase__ :     Union[str, Any]	  =	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]}'''				)
							lowerCamelCase__ :     Dict	  =	None, None
							if not disable_tqdm:
														lowerCamelCase__ :     Tuple	  =	(RLock(),), tqdm.set_lock
							with Pool(UpperCamelCase    ,      initargs=UpperCamelCase    ,      initializer=UpperCamelCase				) as pool:
														lowerCamelCase__ :     int	  =	pool.map(UpperCamelCase    ,      UpperCamelCase				)
							logger.info(f'''Finished {num_proc} processes'''				)
							lowerCamelCase__ :     Optional[Any]	  =	[obj for proc_res in mapped for obj in proc_res]
							logger.info(f'''Unpacked {len(UpperCamelCase				)} objects'''				)

							return mapped





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase				)				->	Union[str, Any]:
							# progress bar is not yet supported for _map_with_joblib, because tqdm couldn't accurately be applied to joblib,
							# and it requires monkey-patching joblib internal classes which is subject to change
							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 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	List[str]:
							lowerCamelCase__ :     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:
														lowerCamelCase__ :     int	  =	None









'''simple docstring'''







from math import asin, atan, cos, radians, sin, sqrt, tan

_A     :      List[str]   					=637_8137.0
_A     :      Dict   					=635_6752.31_4245
_A     :      int   					=6_378_137





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase				)				->	float:
							lowerCamelCase__ :     str	  =	(AXIS_A - AXIS_B) / AXIS_A
							lowerCamelCase__ :     Dict	  =	atan((1 - flattening) * tan(radians(UpperCamelCase				)				)				)
							lowerCamelCase__ :     Dict	  =	atan((1 - flattening) * tan(radians(UpperCamelCase				)				)				)
							lowerCamelCase__ :     Optional[Any]	  =	radians(UpperCamelCase				)
							lowerCamelCase__ :     List[Any]	  =	radians(UpperCamelCase				)
							# Equation
							lowerCamelCase__ :     Tuple	  =	sin((phi_a - phi_a) / 2				)
							lowerCamelCase__ :     List[Any]	  =	sin((lambda_a - lambda_a) / 2				)
							# Square both values
							sin_sq_phi *= sin_sq_phi
							sin_sq_lambda *= sin_sq_lambda
							lowerCamelCase__ :     Tuple	  =	sqrt(sin_sq_phi + (cos(UpperCamelCase				) * cos(UpperCamelCase				) * sin_sq_lambda)				)
							return 2 * RADIUS * asin(UpperCamelCase				)


if __name__ == "__main__":
			import doctest

			doctest.testmod()

