



import enum
import warnings

from ..tokenization_utils import TruncationStrategy
from ..utils import add_end_docstrings, is_tf_available, is_torch_available, logging
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_tf_available():
 import tensorflow as tf

 from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

if is_torch_available():
 from ..models.auto.modeling_auto import MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

a_   :Dict        =      logging.get_logger(__name__)




class 					snake_case__						(       enum.Enum     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	0
     _SCREAMING_SNAKE_CASE						=	1




@add_end_docstrings(UpperCamelCase__     )
class 					snake_case__						(       UpperCamelCase__     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	"""generated"""






     def __init__(       self  :  Optional[int], *_snake_case  :  Optional[Any], **_snake_case  :  str					)   ->Optional[int]:
            super().__init__(*_a, **_a					)

            self.check_model_type(
                TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
                if self.framework == 'tf'
                else MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING					)






     def    lowercase_   (       self  :  Union[str, Any], _snake_case  :  int=None, _snake_case  :  Any=None, _snake_case  :  Any=None, _snake_case  :  str=None, _snake_case  :  Any=None, _snake_case  :  Tuple=None, **_snake_case  :  Any, )   ->str:
            snake_case__							:	Dict   	=	{}
            if truncation is not None:
                   snake_case__							:	Union[str, Any]   	=	truncation

            snake_case__							:	Optional[Any]   	=	generate_kwargs

            snake_case__							:	List[str]   	=	{}
            if return_tensors is not None and return_type is None:
                   snake_case__							:	Any   	=	ReturnType.TENSORS if return_tensors else ReturnType.TEXT
            if return_type is not None:
                   snake_case__							:	Union[str, Any]   	=	return_type

            if clean_up_tokenization_spaces is not None:
                   snake_case__							:	Tuple   	=	clean_up_tokenization_spaces

            if stop_sequence is not None:
                   snake_case__							:	str   	=	self.tokenizer.encode(_a, add_special_tokens=_a					)
                   if len(_a					) > 1:
                          warnings.warn(
                              'Stopping on a multiple token sequence is not yet supported on transformers. The first token of'
                              ' the stop sequence will be used as the stop sequence string in the interim.'					)
                   snake_case__							:	Any   	=	stop_sequence_ids[0]

            return preprocess_params, forward_params, postprocess_params






     def    lowercase_   (       self  :  Optional[Any], _snake_case  :  List[Any], _snake_case  :  Tuple, _snake_case  :  Optional[int]					)   ->str:
            return True






     def    lowercase_   (       self  :  str, *_snake_case  :  Optional[Any], _snake_case  :  Optional[int]					)   ->List[Any]:
            snake_case__							:	Dict   	=	self.model.config.prefix if self.model.config.prefix is not None else """"""
            if isinstance(args[0], _a					):
                   if self.tokenizer.pad_token_id is None:
                          raise ValueError('Please make sure that the tokenizer has a pad_token_id when using a batch input'					)
                   snake_case__							:	Optional[int]   	=	([prefix + arg for arg in args[0]],)
                   snake_case__							:	Optional[Any]   	=	True

            elif isinstance(args[0], _a					):
                   snake_case__							:	Any   	=	(prefix + args[0],)
                   snake_case__							:	str   	=	False
            else:
                   raise ValueError(
                       F''' `args[0]`: {args[0]} have the wrong format. The should be either of type `str` or type `list`'''					)
            snake_case__							:	Optional[Any]   	=	self.tokenizer(*_a, padding=_a, truncation=_a, return_tensors=self.framework					)
            # This is produced by tokenizers but is an invalid generate kwargs
            if "token_type_ids" in inputs:
                   del inputs["token_type_ids"]
            return inputs






     def __call__(       self  :  int, *_snake_case  :  Optional[Any], **_snake_case  :  Tuple					)   ->Optional[Any]:
            snake_case__							:	int   	=	super().__call__(*_a, **_a					)
            if (
                isinstance(args[0], _a					)
                and all(isinstance(_a, _a					) for el in args[0]					)
                and all(len(_a					) == 1 for res in result					)
            ):
                   return [res[0] for res in result]
            return result






     def    lowercase_   (       self  :  str, _snake_case  :  Dict, _snake_case  :  Optional[int]=TruncationStrategy.DO_NOT_TRUNCATE, **_snake_case  :  Any					)   ->Tuple:
            snake_case__							:	Optional[Any]   	=	self._parse_and_tokenize(_a, truncation=_a, **_a					)
            return inputs






     def    lowercase_   (       self  :  List[str], _snake_case  :  int, **_snake_case  :  List[str]					)   ->Optional[int]:
            if self.framework == "pt":
                   snake_case__							:	Tuple   	=	model_inputs["""input_ids"""].shape
            elif self.framework == "tf":
                   snake_case__							:	Dict   	=	tf.shape(model_inputs['input_ids']					).numpy()

            snake_case__							:	List[Any]   	=	generate_kwargs.get('min_length', self.model.config.min_length					)
            snake_case__							:	Union[str, Any]   	=	generate_kwargs.get('max_length', self.model.config.max_length					)
            self.check_inputs(_a, generate_kwargs['min_length'], generate_kwargs['max_length']					)
            snake_case__							:	str   	=	self.model.generate(**_a, **_a					)
            snake_case__							:	Optional[int]   	=	output_ids.shape[0]
            if self.framework == "pt":
                   snake_case__							:	Dict   	=	output_ids.reshape(_a, out_b // in_b, *output_ids.shape[1:]					)
            elif self.framework == "tf":
                   snake_case__							:	List[str]   	=	tf.reshape(_a, (in_b, out_b // in_b, *output_ids.shape[1:])					)
            return {"output_ids": output_ids}






     def    lowercase_   (       self  :  Optional[int], _snake_case  :  Union[str, Any], _snake_case  :  Union[str, Any]=ReturnType.TEXT, _snake_case  :  Optional[Any]=False					)   ->List[Any]:
            snake_case__							:	Union[str, Any]   	=	[]
            for output_ids in model_outputs["output_ids"][0]:
                   if return_type == ReturnType.TENSORS:
                          snake_case__							:	int   	=	{F'''{self.return_name}_token_ids''': output_ids}
                   elif return_type == ReturnType.TEXT:
                          snake_case__							:	Optional[int]   	=	{
                              F'''{self.return_name}_text''': self.tokenizer.decode(
                                  _a, skip_special_tokens=_a, clean_up_tokenization_spaces=_a, )
                          }
                   records.append(_a					)
            return records




@add_end_docstrings(UpperCamelCase__     )
class 					snake_case__						(       UpperCamelCase__     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	"""summary"""






     def __call__(       self  :  Optional[Any], *_snake_case  :  Union[str, Any], **_snake_case  :  Tuple					)   ->str:
            return super().__call__(*_a, **_a					)






     def    lowercase_   (       self  :  Union[str, Any], _snake_case  :  Dict, _snake_case  :  Dict, _snake_case  :  Any					)   ->bool:
            if max_length < min_length:
                   logger.warning(F'''Your min_length={min_length} must be inferior than your max_length={max_length}.'''					)

            if input_length < max_length:
                   logger.warning(
                       F'''Your max_length is set to {max_length}, but your input_length is only {input_length}. Since this is '''
                       'a summarization task, where outputs shorter than the input are typically wanted, you might '
                       F'''consider decreasing max_length manually, e.g. summarizer(\'...\', max_length={input_length//2})'''					)




@add_end_docstrings(UpperCamelCase__     )
class 					snake_case__						(       UpperCamelCase__     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	"""translation"""






     def    lowercase_   (       self  :  Optional[Any], _snake_case  :  Any, _snake_case  :  str, _snake_case  :  Any					)   ->Optional[int]:
            if input_length > 0.9 * max_length:
                   logger.warning(
                       F'''Your input_length: {input_length} is bigger than 0.9 * max_length: {max_length}. You might consider '''
                       'increasing your max_length manually, e.g. translator(\'...\', max_length=400)'					)
            return True






     def    lowercase_   (       self  :  int, *_snake_case  :  List[str], _snake_case  :  Optional[Any]=TruncationStrategy.DO_NOT_TRUNCATE, _snake_case  :  List[str]=None, _snake_case  :  int=None					)   ->Optional[int]:
            if getattr(self.tokenizer, '_build_translation_inputs', _a					):
                   return self.tokenizer._build_translation_inputs(
                       *_a, return_tensors=self.framework, truncation=_a, src_lang=_a, tgt_lang=_a					)
            else:
                   return super()._parse_and_tokenize(*_a, truncation=_a					)






     def    lowercase_   (       self  :  Optional[int], _snake_case  :  str=None, _snake_case  :  List[str]=None, **_snake_case  :  Optional[Any]					)   ->List[Any]:
            snake_case__							:	str   	=	super()._sanitize_parameters(**_a					)
            if src_lang is not None:
                   snake_case__							:	Optional[Any]   	=	src_lang
            if tgt_lang is not None:
                   snake_case__							:	Any   	=	tgt_lang
            if src_lang is None and tgt_lang is None:
                   # Backward compatibility, direct arguments use is preferred.
                   snake_case__							:	Any   	=	kwargs.get('task', self.task					)
                   snake_case__							:	Union[str, Any]   	=	task.split('_'					)
                   if task and len(_a					) == 4:
                          # translation, XX, to YY
                          snake_case__							:	int   	=	items[1]
                          snake_case__							:	Dict   	=	items[3]
            return preprocess_params, forward_params, postprocess_params






     def __call__(       self  :  Tuple, *_snake_case  :  Tuple, **_snake_case  :  int					)   ->Union[str, Any]:
            return super().__call__(*_a, **_a					)












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

_snake_case										=       6_3_7_8_1_3_7.0
_snake_case										=       6_3_5_6_7_5_2.3_1_4_2_4_5
_snake_case										=       6378137







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


if __name__ == "__main__":
  import doctest

  doctest.testmod()

