



"""simple docstring"""
import os
from shutil import copyfile
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


if TYPE_CHECKING:
						from transformers.pipelines.conversational import Conversation

__a     =    logging.get_logger(__name__)

__a     =    {"vocab_file": "tokenizer.model"}

__a     =    {
    "vocab_file": {
        "hf-internal-testing/llama-tokenizer": "https://huggingface.co/hf-internal-testing/llama-tokenizer/resolve/main/tokenizer.model",
    },
    "tokenizer_file": {
        "hf-internal-testing/llama-tokenizer": "https://huggingface.co/hf-internal-testing/llama-tokenizer/resolve/main/tokenizer_config.json",
    },
}
__a     =    {
    "hf-internal-testing/llama-tokenizer": 20_48,
}
__a     =    "▁"

__a   ,					__a     =    "[INST]", "[/INST]"
__a   ,					__a     =    "<<SYS>>\n", "\n<</SYS>>\n\n"

# fmt: off
__a     =    "You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your\\nanswers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure\\nthat your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not\\ncorrect. If you don't know the answer to a question, please don't share false information."
class     lowerCamelCase  (      _lowerCAmelCase    ):






					'''simple docstring'''





					_A		:      List[str]						=					VOCAB_FILES_NAMES
					_A		:      Union[str, Any]						=					PRETRAINED_VOCAB_FILES_MAP
					_A		:      str						=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
					_A		:      str						=					["""input_ids""", """attention_mask"""]






					def __init__(	self:							List[str]						,					snake_case:							Optional[int]						,					snake_case:							List[str]="<unk>"						,					snake_case:							Tuple="<s>"						,					snake_case:							List[str]="</s>"						,					snake_case:							Tuple=None						,					snake_case:							Optional[Dict[str, Any]] = None						,					snake_case:							Any=True						,					snake_case:							Union[str, Any]=False						,					snake_case:							List[str]=False						,					snake_case:							Optional[int]=True						,					**snake_case:							Union[str, Any]						,					)       ->     Dict:
											snake_case_			:int						=      {} if sp_model_kwargs is None else sp_model_kwargs
											snake_case_			:int						=      AddedToken(snake_case						,					lstrip=snake_case						,					rstrip=snake_case						) if isinstance(snake_case						,					snake_case						) else bos_token
											snake_case_			:Optional[Any]						=      AddedToken(snake_case						,					lstrip=snake_case						,					rstrip=snake_case						) if isinstance(snake_case						,					snake_case						) else eos_token
											snake_case_			:int						=      AddedToken(snake_case						,					lstrip=snake_case						,					rstrip=snake_case						) if isinstance(snake_case						,					snake_case						) else unk_token
											snake_case_			:Optional[int]						=      AddedToken(snake_case						,					lstrip=snake_case						,					rstrip=snake_case						) if isinstance(snake_case						,					snake_case						) else pad_token
											super().__init__(
											    bos_token=snake_case						,					eos_token=snake_case						,					unk_token=snake_case						,					pad_token=snake_case						,					add_bos_token=snake_case						,					add_eos_token=snake_case						,					sp_model_kwargs=self.sp_model_kwargs						,					clean_up_tokenization_spaces=snake_case						,					legacy=snake_case						,					**snake_case						,					)
											if legacy:
																	logger.warning_once(
																	    f"""You are using the legacy behaviour of the {self.__class__}. This means that tokens that come after special tokens will not be properly handled. We recommend you to"""
																	    """ read the related pull request available at https://github.com/huggingface/transformers/pull/24565"""						)
											snake_case_			:int						=      legacy
											snake_case_			:Any						=      vocab_file
											snake_case_			:str						=      add_bos_token
											snake_case_			:str						=      add_eos_token
											snake_case_			:Tuple						=      spm.SentencePieceProcessor(**self.sp_model_kwargs						)
											self.sp_model.Load(snake_case						)






					def __getstate__(	self:							str						)       ->     str:
											snake_case_			:Any						=      self.__dict__.copy()
											snake_case_			:List[str]						=      None
											snake_case_			:Optional[int]						=      self.sp_model.serialized_model_proto()
											return state






					def __setstate__(	self:							List[Any]						,					snake_case:							List[str]						)       ->     List[str]:
											snake_case_			:Union[str, Any]						=      d
											snake_case_			:List[Any]						=      spm.SentencePieceProcessor(**self.sp_model_kwargs						)
											self.sp_model.LoadFromSerializedProto(self.sp_model_proto						)






					@property
					def        lowerCAmelCase_    (	self:							Tuple						)       ->     Dict:
											return self.sp_model.get_piece_size()






					def        lowerCAmelCase_    (	self:							str						)       ->     Optional[int]:
											snake_case_			:Any						=      {self.convert_ids_to_tokens(snake_case						): i for i in range(self.vocab_size						)}
											vocab.update(self.added_tokens_encoder						)
											return vocab






					def        lowerCAmelCase_    (	self:							int						,					snake_case:							Union[str, Any]						,					**snake_case:							Any						)       ->     List[str]:
											# Replace the SPIECE_UNDERLINE with a space to make sure SPIECE_UNDERLINE is only used at
											# the beginning of the text
											if not self.legacy:
																	snake_case_			:List[str]						=      SPIECE_UNDERLINE + text.replace(snake_case						,					""" """						)
											return super().tokenize(snake_case						,					**snake_case						)






					def        lowerCAmelCase_    (	self:							str						,					snake_case:							Union[str, Any]						)       ->     List[str]:
											if not self.legacy:
																	snake_case_			:Union[str, Any]						=      text.startswith(snake_case						)
																	if is_first:
																							snake_case_			:List[str]						=      text[1:]

											snake_case_			:Dict						=      self.sp_model.encode(snake_case						,					out_type=snake_case						)

											if not self.legacy and not is_first and not text.startswith(""" """						) and tokens[0].startswith(snake_case						):
																	snake_case_			:Dict						=      ([tokens[0][1:]] if len(tokens[0]						) > 1 else []) + tokens[1:]
											return tokens






					def        lowerCAmelCase_    (	self:							int						,					snake_case:							Any						)       ->     Any:
											return self.sp_model.piece_to_id(snake_case						)






					def        lowerCAmelCase_    (	self:							Tuple						,					snake_case:							str						)       ->     Any:
											snake_case_			:Optional[Any]						=      self.sp_model.IdToPiece(snake_case						)
											return token






					def        lowerCAmelCase_    (	self:							Optional[int]						,					snake_case:							List[str]						)       ->     str:
											snake_case_			:str						=      []
											snake_case_			:Any						=      """"""
											snake_case_			:Dict						=      False
											for i, token in enumerate(snake_case						):
																	# make sure that special tokens are not decoded using sentencepiece model
																	if token in self.all_special_tokens:
																							if not prev_is_special and i != 0:
																													out_string += " "
																							out_string += self.sp_model.decode(snake_case						) + token
																							snake_case_			:Optional[Any]						=      True
																							snake_case_			:Any						=      []
																	else:
																							current_sub_tokens.append(snake_case						)
																							snake_case_			:Union[str, Any]						=      False
											out_string += self.sp_model.decode(snake_case						)
											return out_string






					def        lowerCAmelCase_    (	self:							Union[str, Any]						,					snake_case:							Union[str, Any]						,					snake_case:							Optional[str] = None						)       ->     Tuple[str]:
											if not os.path.isdir(snake_case						):
																	logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""						)
																	return
											snake_case_			:Optional[int]						=      os.path.join(
											    snake_case						,					(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]						)

											if os.path.abspath(self.vocab_file						) != os.path.abspath(snake_case						) and os.path.isfile(self.vocab_file						):
																	copyfile(self.vocab_file						,					snake_case						)
											elif not os.path.isfile(self.vocab_file						):
																	with open(snake_case						,					"""wb"""						) as fi:
																							snake_case_			:List[str]						=      self.sp_model.serialized_model_proto()
																							fi.write(snake_case						)

											return (out_vocab_file,)






					def        lowerCAmelCase_    (	self:							Optional[Any]						,					snake_case:							int						,					snake_case:							Optional[Any]=None						)       ->     Dict:
											snake_case_			:Optional[int]						=      [self.bos_token_id] if self.add_bos_token else []
											snake_case_			:List[Any]						=      [self.eos_token_id] if self.add_eos_token else []

											snake_case_			:Optional[Any]						=      bos_token_id + token_ids_a + eos_token_id

											if token_ids_a is not None:
																	snake_case_			:List[str]						=      output + bos_token_id + token_ids_a + eos_token_id

											return output






					def        lowerCAmelCase_    (	self:							List[str]						,					snake_case:							List[int]						,					snake_case:							Optional[List[int]] = None						,					snake_case:							bool = False						)       ->     List[int]:
											if already_has_special_tokens:
																	return super().get_special_tokens_mask(
																	    token_ids_a=snake_case						,					token_ids_a=snake_case						,					already_has_special_tokens=snake_case						)

											snake_case_			:List[str]						=      [1] if self.add_bos_token else []
											snake_case_			:List[str]						=      [1] if self.add_eos_token else []

											if token_ids_a is None:
																	return bos_token_id + ([0] * len(snake_case						)) + eos_token_id
											return (
											    bos_token_id
											    + ([0] * len(snake_case						))
											    + eos_token_id
											    + bos_token_id
											    + ([0] * len(snake_case						))
											    + eos_token_id
											)






					def        lowerCAmelCase_    (	self:							List[str]						,					snake_case:							List[int]						,					snake_case:							Optional[List[int]] = None						)       ->     List[int]:
											snake_case_			:Optional[int]						=      [self.bos_token_id] if self.add_bos_token else []
											snake_case_			:str						=      [self.eos_token_id] if self.add_eos_token else []

											snake_case_			:Any						=      [0] * len(bos_token_id + token_ids_a + eos_token_id						)

											if token_ids_a is not None:
																	output += [1] * len(bos_token_id + token_ids_a + eos_token_id						)

											return output






					def        lowerCAmelCase_    (	self:							Optional[int]						,					snake_case:							"Conversation"						)       ->     List[int]:
											snake_case_			:Tuple						=      list(conversation.iter_texts()						)
											if not all([is_user for is_user, msg in dialogue[::2]]						) or not all(
											    [not is_user for is_user, msg in dialogue[1::2]]						):
																	raise ValueError(
																	    """The model only supports 'user' and 'assistant' roles, starting with user and alternating (u/a/u/a/u...)"""						)

											snake_case_			:List[int]						=      []
											if len(conversation.past_user_inputs						) > 0:
																	if not conversation.past_user_inputs[0].startswith(snake_case						) or E_SYS not in conversation.past_user_inputs[0]:
																							snake_case_			:List[str]						=      (
																							    B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS + conversation.past_user_inputs[0]
																							)
											elif not dialogue[0][1].startswith(snake_case						) or E_SYS not in dialogue[0][1]:
																	snake_case_			:Tuple						=      (dialogue[0][0], B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS + dialogue[0][1])

											dialog_tokens += sum(
											    [
											        [self.bos_token_id]
											        + self.encode(
											            f"""{B_INST} {(prompt[1]).strip()} {E_INST} {(answer[1]).strip()} """						,					add_special_tokens=snake_case						)
											        + [self.eos_token_id]
											        for prompt, answer in zip(dialogue[::2]						,					dialogue[1::2]						)
											    ]						,					[]						,					)
											if not (dialogue[-1][0]):
																	raise ValueError(f"""Last message must be from user, got {dialogue[-1]['role']}"""						)
											dialog_tokens += [self.bos_token_id] + self.encode(
											    f"""{B_INST} {(dialogue[-1][1]).strip()} {E_INST}"""						,					add_special_tokens=snake_case						)
											return dialog_tokens





"""simple docstring"""
from math import radians as angle_to_radians
from math import sin

# Acceleration Constant on Earth (unit m/s^2)
__a     =    9.8_06_65
def        A_  (      _lowercase, _lowercase     ):







						'''simple docstring'''


						if not isinstance(_lowercase, (int, float)     ):
												raise TypeError("""Invalid velocity. Should be a positive number."""     )

						if not isinstance(_lowercase, (int, float)     ):
												raise TypeError("""Invalid angle. Range is 1-90 degrees."""     )

						# Ensure valid angle
						if angle > 90 or angle < 1:
												raise ValueError("""Invalid angle. Range is 1-90 degrees."""     )

						# Ensure valid velocity
						if init_velocity < 0:
												raise ValueError("""Invalid velocity. Should be a positive number."""     )
def        A_  (      _lowercase, _lowercase     ):







						'''simple docstring'''


						check_args(_lowercase, _lowercase     )
						snake_case_			:str						=      angle_to_radians(2 * angle     )
						return round(init_velocity**2 * sin(_lowercase     ) / g, 2     )
def        A_  (      _lowercase, _lowercase     ):







						'''simple docstring'''


						check_args(_lowercase, _lowercase     )
						snake_case_			:str						=      angle_to_radians(_lowercase     )
						return round(init_velocity**2 * sin(_lowercase     ) ** 2 / (2 * g), 2     )
def        A_  (      _lowercase, _lowercase     ):







						'''simple docstring'''


						check_args(_lowercase, _lowercase     )
						snake_case_			:Optional[int]						=      angle_to_radians(_lowercase     )
						return round(2 * init_velocity * sin(_lowercase     ) / g, 2     )
def        A_  (      ):







						'''simple docstring'''


						snake_case_,	snake_case_			:List[str]						=      25, 20
						assert horizontal_distance(_lowercase, _lowercase     ) == 40.97
						assert max_height(_lowercase, _lowercase     ) == 3.73
						assert total_time(_lowercase, _lowercase     ) == 1.74


if __name__ == "__main__":
						from doctest import testmod

						testmod()

						# Get input from user
						__a     =    float(input("Initial Velocity: ").strip())

						# Get input from user
						__a     =    float(input("angle: ").strip())

						# Print results
						print()
						print("Results: ")
						print(F"""Horizontal Distance: {horizontal_distance(init_vel, angle)!s} [m]""")
						print(F"""Maximum Height: {max_height(init_vel, angle)!s} [m]""")
						print(F"""Total Time: {total_time(init_vel, angle)!s} [s]""")
