



"""simple docstring"""
import contextlib
from multiprocessing import Pool, RLock

from tqdm.auto import tqdm

from ..utils import experimental, logging


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



class    SCREAMING_SNAKE_CASE__						:
   __lowerCAmelCase						:     Union[str, Any]		=		None

@experimental
def    _snake_case		(		UpperCamelCase		:	Union[str, Any]    ,	UpperCamelCase		:	Union[str, Any]    ,	UpperCamelCase		:	str    ,	UpperCamelCase		:	Any    ,	UpperCamelCase		:	List[Any]    ,	UpperCamelCase		:	str    ,	UpperCamelCase		:	Dict		):






 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		(		UpperCamelCase		:	Optional[Any]    ,	UpperCamelCase		:	int    ,	UpperCamelCase		:	int    ,	UpperCamelCase		:	List[Any]    ,	UpperCamelCase		:	List[str]    ,	UpperCamelCase		:	Any    ,	UpperCamelCase		:	List[Any]		):
 UpperCAmelCase			:      str			=			num_proc if num_proc <= len(__SCREAMING_SNAKE_CASE		) else len(__SCREAMING_SNAKE_CASE		)
 UpperCAmelCase			:      Optional[int]			=			[]  # We organize the splits ourselve (contiguous splits)
 for index in range(__SCREAMING_SNAKE_CASE		):
  UpperCAmelCase			:      List[str]			=			len(__SCREAMING_SNAKE_CASE		) // num_proc
  UpperCAmelCase			:      Optional[Any]			=			len(__SCREAMING_SNAKE_CASE		) % num_proc
  UpperCAmelCase			:      Optional[Any]			=			div * index + min(__SCREAMING_SNAKE_CASE    ,	__SCREAMING_SNAKE_CASE		)
  UpperCAmelCase			:      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(__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]}"		)
 UpperCAmelCase			:      Tuple			=			None, None
 if not disable_tqdm:
  UpperCAmelCase			:      int			=			(RLock(),), tqdm.set_lock
 with Pool(__SCREAMING_SNAKE_CASE    ,	initargs=__SCREAMING_SNAKE_CASE    ,	initializer=__SCREAMING_SNAKE_CASE		) as pool:
  UpperCAmelCase			:      Union[str, Any]			=			pool.map(__SCREAMING_SNAKE_CASE    ,	__SCREAMING_SNAKE_CASE		)
 logger.info(F"Finished {num_proc} processes"		)
 UpperCAmelCase			:      str			=			[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		(		UpperCamelCase		:	Any    ,	UpperCamelCase		:	int    ,	UpperCamelCase		:	List[str]    ,	UpperCamelCase		:	str    ,	UpperCamelCase		:	List[str]    ,	UpperCamelCase		:	Union[str, Any]    ,	UpperCamelCase		:	List[Any]		):
 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		(		UpperCamelCase		:	Tuple		):
 UpperCAmelCase			:      Union[str, 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:
  UpperCAmelCase			:      Any			=			None





"""simple docstring"""
def    _snake_case		(		UpperCamelCase		:	int    ,	UpperCamelCase		:	int		):
 return 1 if input_a == input_a else 0

def    _snake_case		(		):
 assert xnor_gate(0    ,	0		) == 1
 assert xnor_gate(0    ,	1		) == 0
 assert xnor_gate(1    ,	0		) == 0
 assert xnor_gate(1    ,	1		) == 1


if __name__ == "__main__":
      print(xnor_gate(0, 0))
      print(xnor_gate(0, 1))
      print(xnor_gate(1, 0))
      print(xnor_gate(1, 1))
