

"""simple docstring"""


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    RemBertConfig,
			    RemBertForCausalLM,
			    RemBertForMaskedLM,
			    RemBertForMultipleChoice,
			    RemBertForQuestionAnswering,
			    RemBertForSequenceClassification,
			    RemBertForTokenClassification,
			    RemBertModel,
			)
			from transformers.models.rembert.modeling_rembert import REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST





class 					snake_case			:

				def __init__(			self							:       Optional[Any]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       List[str]=1_3  ,						UpperCamelCase__							:       List[str]=7  ,						UpperCamelCase__							:       Union[str, Any]=True  ,						UpperCamelCase__							:       Dict=True  ,						UpperCamelCase__							:       Dict=True  ,						UpperCamelCase__							:       str=True  ,						UpperCamelCase__							:       List[str]=9_9  ,						UpperCamelCase__							:       Dict=3_2  ,						UpperCamelCase__							:       List[Any]=1_8  ,						UpperCamelCase__							:       List[Any]=4_3  ,						UpperCamelCase__							:       List[Any]=5  ,						UpperCamelCase__							:       Optional[int]=4  ,						UpperCamelCase__							:       Optional[int]=3_7  ,						UpperCamelCase__							:       str="gelu"  ,						UpperCamelCase__							:       Any=0.1  ,						UpperCamelCase__							:       int=0.1  ,						UpperCamelCase__							:       str=5_1_2  ,						UpperCamelCase__							:       Any=1_6  ,						UpperCamelCase__							:       Tuple=2  ,						UpperCamelCase__							:       Optional[Any]=0.02  ,						UpperCamelCase__							:       List[str]=3  ,						UpperCamelCase__							:       Any=4  ,						UpperCamelCase__							:       str=None  ,						)->     str:



											'''simple docstring'''


											__lowerCAmelCase: Tuple					   =    parent
											__lowerCAmelCase: List[Any]					   =    batch_size
											__lowerCAmelCase: List[str]					   =    seq_length
											__lowerCAmelCase: List[Any]					   =    is_training
											__lowerCAmelCase: Optional[Any]					   =    use_input_mask
											__lowerCAmelCase: str					   =    use_token_type_ids
											__lowerCAmelCase: Any					   =    use_labels
											__lowerCAmelCase: Union[str, Any]					   =    vocab_size
											__lowerCAmelCase: Optional[int]					   =    hidden_size
											__lowerCAmelCase: int					   =    input_embedding_size
											__lowerCAmelCase: List[Any]					   =    output_embedding_size
											__lowerCAmelCase: str					   =    num_hidden_layers
											__lowerCAmelCase: int					   =    num_attention_heads
											__lowerCAmelCase: Dict					   =    intermediate_size
											__lowerCAmelCase: str					   =    hidden_act
											__lowerCAmelCase: str					   =    hidden_dropout_prob
											__lowerCAmelCase: Optional[Any]					   =    attention_probs_dropout_prob
											__lowerCAmelCase: Any					   =    max_position_embeddings
											__lowerCAmelCase: Dict					   =    type_vocab_size
											__lowerCAmelCase: str					   =    type_sequence_label_size
											__lowerCAmelCase: Dict					   =    initializer_range
											__lowerCAmelCase: int					   =    num_labels
											__lowerCAmelCase: int					   =    num_choices
											__lowerCAmelCase: Dict					   =    scope

				def 							lowercase_  (			self							:       Union[str, Any])->     List[Any]:



											'''simple docstring'''


											__lowerCAmelCase: List[Any]					   =    ids_tensor([self.batch_size, self.seq_length]  ,						self.vocab_size)

											__lowerCAmelCase: List[Any]					   =    None
											if self.use_input_mask:
																		__lowerCAmelCase: Optional[Any]					   =    random_attention_mask([self.batch_size, self.seq_length])

											__lowerCAmelCase: List[Any]					   =    None
											if self.use_token_type_ids:
																		__lowerCAmelCase: List[Any]					   =    ids_tensor([self.batch_size, self.seq_length]  ,						self.type_vocab_size)

											__lowerCAmelCase: Optional[Any]					   =    None
											__lowerCAmelCase: Optional[int]					   =    None
											__lowerCAmelCase: Dict					   =    None
											if self.use_labels:
																		__lowerCAmelCase: str					   =    ids_tensor([self.batch_size]  ,						self.type_sequence_label_size)
																		__lowerCAmelCase: Optional[int]					   =    ids_tensor([self.batch_size, self.seq_length]  ,						self.num_labels)
																		__lowerCAmelCase: Dict					   =    ids_tensor([self.batch_size]  ,						self.num_choices)

											__lowerCAmelCase: List[str]					   =    RemBertConfig(
											    vocab_size=self.vocab_size  ,						hidden_size=self.hidden_size  ,						input_embedding_size=self.input_embedding_size  ,						output_embedding_size=self.output_embedding_size  ,						num_hidden_layers=self.num_hidden_layers  ,						num_attention_heads=self.num_attention_heads  ,						intermediate_size=self.intermediate_size  ,						hidden_act=self.hidden_act  ,						hidden_dropout_prob=self.hidden_dropout_prob  ,						attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,						max_position_embeddings=self.max_position_embeddings  ,						type_vocab_size=self.type_vocab_size  ,						is_decoder=__A  ,						initializer_range=self.initializer_range  ,						)

											return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

				def 							lowercase_  (			self							:       List[Any])->     Tuple:



											'''simple docstring'''


											(
											    __lowerCAmelCase					
											): Optional[Any]					   =    self.prepare_config_and_inputs()

											__lowerCAmelCase: Optional[Any]					   =    True
											__lowerCAmelCase: Dict					   =    floats_tensor([self.batch_size, self.seq_length, self.hidden_size])
											__lowerCAmelCase: Optional[int]					   =    ids_tensor([self.batch_size, self.seq_length]  ,						vocab_size=2)

											return (
											    config,
											    input_ids,
											    token_type_ids,
											    input_mask,
											    sequence_labels,
											    token_labels,
											    choice_labels,
											    encoder_hidden_states,
											    encoder_attention_mask,
											)

				def 							lowercase_  (			self							:       List[str]  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       str)->     Dict:



											'''simple docstring'''


											__lowerCAmelCase: List[str]					   =    RemBertModel(config=__A)
											model.to(__A)
											model.eval()
											__lowerCAmelCase: Tuple					   =    model(__A  ,						attention_mask=__A  ,						token_type_ids=__A)
											__lowerCAmelCase: Dict					   =    model(__A  ,						token_type_ids=__A)
											__lowerCAmelCase: int					   =    model(__A)
											self.parent.assertEqual(result.last_hidden_state.shape  ,						(self.batch_size, self.seq_length, self.hidden_size))

				def 							lowercase_  (			self							:       Tuple  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       str  ,						)->     int:



											'''simple docstring'''


											__lowerCAmelCase: Union[str, Any]					   =    True
											__lowerCAmelCase: Union[str, Any]					   =    RemBertModel(__A)
											model.to(__A)
											model.eval()
											__lowerCAmelCase: List[str]					   =    model(
											    __A  ,						attention_mask=__A  ,						token_type_ids=__A  ,						encoder_hidden_states=__A  ,						encoder_attention_mask=__A  ,						)
											__lowerCAmelCase: str					   =    model(
											    __A  ,						attention_mask=__A  ,						token_type_ids=__A  ,						encoder_hidden_states=__A  ,						)
											__lowerCAmelCase: List[Any]					   =    model(__A  ,						attention_mask=__A  ,						token_type_ids=__A)
											self.parent.assertEqual(result.last_hidden_state.shape  ,						(self.batch_size, self.seq_length, self.hidden_size))

				def 							lowercase_  (			self							:       List[Any]  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       Dict  ,						)->     Tuple:



											'''simple docstring'''


											__lowerCAmelCase: Dict					   =    RemBertForCausalLM(config=__A)
											model.to(__A)
											model.eval()
											__lowerCAmelCase: int					   =    model(__A  ,						attention_mask=__A  ,						token_type_ids=__A  ,						labels=__A)
											self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.vocab_size))

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



											'''simple docstring'''


											__lowerCAmelCase: int					   =    RemBertForMaskedLM(config=__A)
											model.to(__A)
											model.eval()
											__lowerCAmelCase: Optional[int]					   =    model(__A  ,						attention_mask=__A  ,						token_type_ids=__A  ,						labels=__A)
											self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.vocab_size))

				def 							lowercase_  (			self							:       Optional[int]  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       int  ,						)->     str:



											'''simple docstring'''


											__lowerCAmelCase: Optional[Any]					   =    True
											__lowerCAmelCase: Tuple					   =    True
											__lowerCAmelCase: str					   =    RemBertForCausalLM(config=__A)
											model.to(__A)
											model.eval()

											# first forward pass
											__lowerCAmelCase: Optional[Any]					   =    model(
											    __A  ,						attention_mask=__A  ,						encoder_hidden_states=__A  ,						encoder_attention_mask=__A  ,						use_cache=__A  ,						)
											__lowerCAmelCase: List[str]					   =    outputs.past_key_values

											# create hypothetical multiple next token and extent to next_input_ids
											__lowerCAmelCase: Tuple					   =    ids_tensor((self.batch_size, 3)  ,						config.vocab_size)
											__lowerCAmelCase: Any					   =    ids_tensor((self.batch_size, 3)  ,						vocab_size=2)

											# append to next input_ids and
											__lowerCAmelCase: Tuple					   =    torch.cat([input_ids, next_tokens]  ,						dim=-1)
											__lowerCAmelCase: Any					   =    torch.cat([input_mask, next_mask]  ,						dim=-1)

											__lowerCAmelCase: Dict					   =    model(
											    __A  ,						attention_mask=__A  ,						encoder_hidden_states=__A  ,						encoder_attention_mask=__A  ,						output_hidden_states=__A  ,						)["hidden_states"][0]
											__lowerCAmelCase: Dict					   =    model(
											    __A  ,						attention_mask=__A  ,						encoder_hidden_states=__A  ,						encoder_attention_mask=__A  ,						past_key_values=__A  ,						output_hidden_states=__A  ,						)["hidden_states"][0]

											# select random slice
											__lowerCAmelCase: int					   =    ids_tensor((1,)  ,						output_from_past.shape[-1]).item()
											__lowerCAmelCase: str					   =    output_from_no_past[:, -3:, random_slice_idx].detach()
											__lowerCAmelCase: Tuple					   =    output_from_past[:, :, random_slice_idx].detach()

											self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1])

											# test that outputs are equal for slice
											self.parent.assertTrue(torch.allclose(__A  ,						__A  ,						atol=1e-3))

				def 							lowercase_  (			self							:       int  ,						UpperCamelCase__							:       Any  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       Any  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       Any  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       int)->     List[str]:



											'''simple docstring'''


											__lowerCAmelCase: int					   =    RemBertForQuestionAnswering(config=__A)
											model.to(__A)
											model.eval()
											__lowerCAmelCase: Optional[Any]					   =    model(
											    __A  ,						attention_mask=__A  ,						token_type_ids=__A  ,						start_positions=__A  ,						end_positions=__A  ,						)
											self.parent.assertEqual(result.start_logits.shape  ,						(self.batch_size, self.seq_length))
											self.parent.assertEqual(result.end_logits.shape  ,						(self.batch_size, self.seq_length))

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



											'''simple docstring'''


											__lowerCAmelCase: int					   =    self.num_labels
											__lowerCAmelCase: Dict					   =    RemBertForSequenceClassification(__A)
											model.to(__A)
											model.eval()
											__lowerCAmelCase: List[str]					   =    model(__A  ,						attention_mask=__A  ,						token_type_ids=__A  ,						labels=__A)
											self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_labels))

				def 							lowercase_  (			self							:       Tuple  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       Optional[int])->     List[Any]:



											'''simple docstring'''


											__lowerCAmelCase: Optional[int]					   =    self.num_labels
											__lowerCAmelCase: Optional[int]					   =    RemBertForTokenClassification(config=__A)
											model.to(__A)
											model.eval()
											__lowerCAmelCase: List[str]					   =    model(__A  ,						attention_mask=__A  ,						token_type_ids=__A  ,						labels=__A)
											self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.num_labels))

				def 							lowercase_  (			self							:       List[Any]  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Union[str, Any])->     Tuple:



											'''simple docstring'''


											__lowerCAmelCase: Optional[Any]					   =    self.num_choices
											__lowerCAmelCase: Optional[int]					   =    RemBertForMultipleChoice(config=__A)
											model.to(__A)
											model.eval()
											__lowerCAmelCase: Optional[Any]					   =    input_ids.unsqueeze(1).expand(-1  ,						self.num_choices  ,						-1).contiguous()
											__lowerCAmelCase: str					   =    token_type_ids.unsqueeze(1).expand(-1  ,						self.num_choices  ,						-1).contiguous()
											__lowerCAmelCase: Optional[Any]					   =    input_mask.unsqueeze(1).expand(-1  ,						self.num_choices  ,						-1).contiguous()
											__lowerCAmelCase: int					   =    model(
											    __A  ,						attention_mask=__A  ,						token_type_ids=__A  ,						labels=__A  ,						)
											self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_choices))




				def 							lowercase_  (			self							:       List[Any])->     Optional[int]:



											'''simple docstring'''


											__lowerCAmelCase: List[Any]					   =    self.prepare_config_and_inputs()
											(
											    __lowerCAmelCase					
											): Optional[int]					   =    config_and_inputs
											__lowerCAmelCase: str					   =    {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
											return config, inputs_dict





@require_torch
class 					snake_case			(       a__,							a__,							unittest.TestCase						):
				SCREAMING_SNAKE_CASE_     :   int        =						(
				    (
				        RemBertModel,
				        RemBertForMaskedLM,
				        RemBertForCausalLM,
				        RemBertForMultipleChoice,
				        RemBertForQuestionAnswering,
				        RemBertForSequenceClassification,
				        RemBertForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE_     :   List[Any]        =						(RemBertForCausalLM,) if is_torch_available() else ()
				SCREAMING_SNAKE_CASE_     :   Dict        =						(
				    {
				        """feature-extraction""": RemBertModel,
				        """fill-mask""": RemBertForMaskedLM,
				        """question-answering""": RemBertForQuestionAnswering,
				        """text-classification""": RemBertForSequenceClassification,
				        """text-generation""": RemBertForCausalLM,
				        """token-classification""": RemBertForTokenClassification,
				        """zero-shot""": RemBertForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)

				def 							lowercase_  (			self							:       Tuple)->     Tuple:



											'''simple docstring'''


											__lowerCAmelCase: Tuple					   =    RemBertModelTester(self)
											__lowerCAmelCase: Optional[Any]					   =    ConfigTester(self  ,						config_class=__A  ,						hidden_size=3_7)

				def 							lowercase_  (			self							:       List[Any])->     Dict:



											'''simple docstring'''


											self.config_tester.run_common_tests()

				def 							lowercase_  (			self							:       Optional[Any])->     Union[str, Any]:



											'''simple docstring'''


											__lowerCAmelCase: List[Any]					   =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__A)

				def 							lowercase_  (			self							:       List[Any])->     Any:



											'''simple docstring'''


											__lowerCAmelCase: Tuple					   =    self.model_tester.prepare_config_and_inputs()
											for type in ["absolute", "relative_key", "relative_key_query"]:
																		__lowerCAmelCase: int					   =    type
																		self.model_tester.create_and_check_model(*__A)

				def 							lowercase_  (			self							:       Optional[Any])->     Dict:



											'''simple docstring'''


											__lowerCAmelCase: Optional[int]					   =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*__A)

				def 							lowercase_  (			self							:       int)->     Optional[Any]:



											'''simple docstring'''


											__lowerCAmelCase: Tuple					   =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_multiple_choice(*__A)

				def 							lowercase_  (			self							:       Tuple)->     List[str]:



											'''simple docstring'''


											__lowerCAmelCase: Tuple					   =    self.model_tester.prepare_config_and_inputs_for_decoder()
											self.model_tester.create_and_check_decoder_model_past_large_inputs(*__A)

				def 							lowercase_  (			self							:       List[str])->     Any:



											'''simple docstring'''


											__lowerCAmelCase: Optional[int]					   =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*__A)

				def 							lowercase_  (			self							:       List[Any])->     Any:



											'''simple docstring'''


											__lowerCAmelCase: Dict					   =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*__A)

				def 							lowercase_  (			self							:       Any)->     Any:



											'''simple docstring'''


											__lowerCAmelCase: Tuple					   =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*__A)

				def 							lowercase_  (			self							:       List[str])->     List[str]:



											'''simple docstring'''


											__lowerCAmelCase: Any					   =    self.model_tester.prepare_config_and_inputs_for_decoder()
											self.model_tester.create_and_check_model_as_decoder(*__A)

				def 							lowercase_  (			self							:       Optional[int])->     int:



											'''simple docstring'''


											(
											    __lowerCAmelCase					
											): Any					   =    self.model_tester.prepare_config_and_inputs_for_decoder()

											__lowerCAmelCase: Union[str, Any]					   =    None

											self.model_tester.create_and_check_model_as_decoder(
											    __A  ,						__A  ,						__A  ,						__A  ,						__A  ,						__A  ,						__A  ,						__A  ,						__A  ,						)




				@slow
				def 							lowercase_  (			self							:       Optional[int])->     Union[str, Any]:



											'''simple docstring'''


											for model_name in REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		__lowerCAmelCase: Any					   =    RemBertModel.from_pretrained(__A)
																		self.assertIsNotNone(__A)





@require_torch
class 					snake_case			(       unittest.TestCase						):

				@slow
				def 							lowercase_  (			self							:       Optional[int])->     List[str]:



											'''simple docstring'''


											__lowerCAmelCase: List[Any]					   =    RemBertModel.from_pretrained("google/rembert")
											__lowerCAmelCase: Tuple					   =    torch.tensor([[3_1_2, 5_6_4_9_8, 3_1_3, 2_1_2_5, 3_1_3]])
											__lowerCAmelCase: str					   =    torch.tensor([[0, 0, 0, 1, 1]])
											with torch.no_grad():
																		__lowerCAmelCase: Optional[Any]					   =    model(__A  ,						token_type_ids=__A  ,						output_hidden_states=__A)

											__lowerCAmelCase: int					   =    1_1_5_2

											__lowerCAmelCase: Any					   =    torch.Size((1, 5, hidden_size))
											self.assertEqual(output["last_hidden_state"].shape  ,						__A)

											__lowerCAmelCase: Optional[Any]					   =    torch.tensor(
											    [
											        [
											            [0.0754, -0.2022, 0.1904],
											            [-0.3354, -0.3692, -0.4791],
											            [-0.2314, -0.6729, -0.0749],
											            [-0.0396, -0.3105, -0.4234],
											            [-0.1571, -0.0525, 0.5353],
											        ]
											    ])

											# Running on the original tf implementation gives slightly different results here.
											# Not clear why this variations is present
											# TODO: Find reason for discrepancy
											# expected_original_implementation = [[
											#     [0.07630594074726105, -0.20146065950393677, 0.19107051193714142],
											#     [-0.3405614495277405, -0.36971670389175415, -0.4808273911476135],
											#     [-0.22587086260318756, -0.6656315922737122, -0.07844287157058716],
											#     [-0.04145475849509239, -0.3077218234539032, -0.42316967248916626],
											#     [-0.15887849032878876, -0.054529931396245956, 0.5356100797653198]
											# ]]

											self.assertTrue(torch.allclose(output["last_hidden_state"][:, :, :3]  ,						__A  ,						atol=1e-4))





"""simple docstring"""


import math






def 					a__					(					__SCREAMING_SNAKE_CASE				)			->			list:
		if n <= 0:
				raise ValueError("Only positive integers have prime factors"				)
		__lowerCAmelCase: Tuple					   =    []
		while n % 2 == 0:
				pf.append(2				)
				__lowerCAmelCase: str					   =    int(n / 2				)
		for i in range(3      ,				int(math.sqrt(__SCREAMING_SNAKE_CASE				)				) + 1      ,				2				):
				while n % i == 0:
						pf.append(__SCREAMING_SNAKE_CASE				)
						__lowerCAmelCase: List[Any]					   =    int(n / i				)
		if n > 2:
				pf.append(__SCREAMING_SNAKE_CASE				)
		return pf






def 					a__					(					__SCREAMING_SNAKE_CASE				)			->			int:
		if n <= 0:
				raise ValueError("Only positive numbers are accepted"				)
		__lowerCAmelCase: int					   =    1
		__lowerCAmelCase: str					   =    1
		while n % 2 == 0:
				temp += 1
				__lowerCAmelCase: Dict					   =    int(n / 2				)
		div *= temp
		for i in range(3      ,				int(math.sqrt(__SCREAMING_SNAKE_CASE				)				) + 1      ,				2				):
				__lowerCAmelCase: int					   =    1
				while n % i == 0:
						temp += 1
						__lowerCAmelCase: Tuple					   =    int(n / i				)
				div *= temp
		if n > 1:
				div *= 2
		return div






def 					a__					(					__SCREAMING_SNAKE_CASE				)			->			int:
		if n <= 0:
				raise ValueError("Only positive numbers are accepted"				)
		__lowerCAmelCase: Dict					   =    1
		__lowerCAmelCase: int					   =    1
		while n % 2 == 0:
				temp += 1
				__lowerCAmelCase: Tuple					   =    int(n / 2				)
		if temp > 1:
				s *= (2**temp - 1) / (2 - 1)
		for i in range(3      ,				int(math.sqrt(__SCREAMING_SNAKE_CASE				)				) + 1      ,				2				):
				__lowerCAmelCase: List[Any]					   =    1
				while n % i == 0:
						temp += 1
						__lowerCAmelCase: List[str]					   =    int(n / i				)
				if temp > 1:
						s *= (i**temp - 1) / (i - 1)
		return int(__SCREAMING_SNAKE_CASE				)






def 					a__					(					__SCREAMING_SNAKE_CASE				)			->			int:
		__lowerCAmelCase: Optional[int]					   =    n
		for x in set(prime_factors(__SCREAMING_SNAKE_CASE				)				):
				s *= (x - 1) / x
		return int(__SCREAMING_SNAKE_CASE				)


if __name__ == "__main__":
			import doctest

			doctest.testmod()


