




import unittest

from transformers import YosoConfig, 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 (
				    YosoForMaskedLM,
				    YosoForMultipleChoice,
				    YosoForQuestionAnswering,
				    YosoForSequenceClassification,
				    YosoForTokenClassification,
				    YosoModel,
				)
				from transformers.models.yoso.modeling_yoso import YOSO_PRETRAINED_MODEL_ARCHIVE_LIST





class 		A__				:






	def __init__(	self				,     lowerCamelCase				,     lowerCamelCase=13				,     lowerCamelCase=7				,     lowerCamelCase=True				,     lowerCamelCase=True				,     lowerCamelCase=True				,     lowerCamelCase=True				,     lowerCamelCase=99				,     lowerCamelCase=32				,     lowerCamelCase=5				,     lowerCamelCase=4				,     lowerCamelCase=37				,     lowerCamelCase="gelu"				,     lowerCamelCase=0.1				,     lowerCamelCase=0.1				,     lowerCamelCase=512				,     lowerCamelCase=16				,     lowerCamelCase=2				,     lowerCamelCase=0.0_2				,     lowerCamelCase=3				,     lowerCamelCase=4				,     lowerCamelCase=None				,     )      ->   str:




						"""simple docstring"""






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






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




						"""simple docstring"""






						__magic_name__					:							int		   =							ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size						)

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

						__magic_name__					:							Optional[int]		   =							None
						if self.use_token_type_ids:
											__magic_name__					:							Tuple		   =							ids_tensor([self.batch_size, self.seq_length]				,     self.type_vocab_size						)

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

						__magic_name__					:							Optional[Any]		   =							self.get_config()

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






	def  lowercase      (	self						)      ->   str:




						"""simple docstring"""






						return YosoConfig(
						    vocab_size=self.vocab_size				,     hidden_size=self.hidden_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=UpperCAmelCase_				,     initializer_range=self.initializer_range				,     )






	def  lowercase      (	self						)      ->   Optional[Any]:




						"""simple docstring"""






						__magic_name__					:							Dict		   =							self.get_config()
						__magic_name__					:							Any		   =							300
						return config






	def  lowercase      (	self						)      ->   int:




						"""simple docstring"""






						(
						    __magic_name__    
						)					:							List[str]		   =							self.prepare_config_and_inputs()

						__magic_name__					:							Union[str, Any]		   =							True
						__magic_name__					:							Union[str, Any]		   =							floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
						__magic_name__					:							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				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase						)      ->   List[str]:




						"""simple docstring"""






						__magic_name__					:							int		   =							YosoModel(config=UpperCAmelCase_						)
						model.to(UpperCAmelCase_						)
						model.eval()
						__magic_name__					:							Dict		   =							model(UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_						)
						__magic_name__					:							str		   =							model(UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_						)
						__magic_name__					:							List[str]		   =							model(UpperCAmelCase_						)
						self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.hidden_size)						)






	def  lowercase      (	self				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     )      ->   int:




						"""simple docstring"""






						__magic_name__					:							str		   =							True
						__magic_name__					:							List[Any]		   =							YosoModel(UpperCAmelCase_						)
						model.to(UpperCAmelCase_						)
						model.eval()
						__magic_name__					:							int		   =							model(
						    UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_				,     encoder_hidden_states=UpperCAmelCase_				,     encoder_attention_mask=UpperCAmelCase_				,     )
						__magic_name__					:							List[Any]		   =							model(
						    UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_				,     encoder_hidden_states=UpperCAmelCase_				,     )
						__magic_name__					:							int		   =							model(UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_						)
						self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.hidden_size)						)






	def  lowercase      (	self				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase						)      ->   Tuple:




						"""simple docstring"""






						__magic_name__					:							Tuple		   =							YosoForMaskedLM(config=UpperCAmelCase_						)
						model.to(UpperCAmelCase_						)
						model.eval()
						__magic_name__					:							Dict		   =							model(UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_				,     labels=UpperCAmelCase_						)
						self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.vocab_size)						)






	def  lowercase      (	self				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase						)      ->   Optional[Any]:




						"""simple docstring"""






						__magic_name__					:							Dict		   =							YosoForQuestionAnswering(config=UpperCAmelCase_						)
						model.to(UpperCAmelCase_						)
						model.eval()
						__magic_name__					:							str		   =							model(
						    UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_				,     start_positions=UpperCAmelCase_				,     end_positions=UpperCAmelCase_				,     )
						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				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase						)      ->   Dict:




						"""simple docstring"""






						__magic_name__					:							Dict		   =							self.num_labels
						__magic_name__					:							Optional[Any]		   =							YosoForSequenceClassification(UpperCAmelCase_						)
						model.to(UpperCAmelCase_						)
						model.eval()
						__magic_name__					:							Dict		   =							model(UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_				,     labels=UpperCAmelCase_						)
						self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_labels)						)






	def  lowercase      (	self				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase						)      ->   Any:




						"""simple docstring"""






						__magic_name__					:							List[Any]		   =							self.num_labels
						__magic_name__					:							Tuple		   =							YosoForTokenClassification(config=UpperCAmelCase_						)
						model.to(UpperCAmelCase_						)
						model.eval()
						__magic_name__					:							Dict		   =							model(UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_				,     labels=UpperCAmelCase_						)
						self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.num_labels)						)






	def  lowercase      (	self				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase				,     lowerCamelCase						)      ->   Tuple:




						"""simple docstring"""






						__magic_name__					:							Any		   =							self.num_choices
						__magic_name__					:							Dict		   =							YosoForMultipleChoice(config=UpperCAmelCase_						)
						model.to(UpperCAmelCase_						)
						model.eval()
						__magic_name__					:							int		   =							input_ids.unsqueeze(1						).expand(-1				,     self.num_choices				,     -1						).contiguous()
						__magic_name__					:							Tuple		   =							token_type_ids.unsqueeze(1						).expand(-1				,     self.num_choices				,     -1						).contiguous()
						__magic_name__					:							List[Any]		   =							input_mask.unsqueeze(1						).expand(-1				,     self.num_choices				,     -1						).contiguous()
						__magic_name__					:							Optional[Any]		   =							model(
						    UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_				,     labels=UpperCAmelCase_				,     )
						self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_choices)						)






	def  lowercase      (	self						)      ->   Dict:




						"""simple docstring"""






						__magic_name__					:							Tuple		   =							self.prepare_config_and_inputs()
						(
						    __magic_name__    
						)					:							List[Any]		   =							config_and_inputs
						__magic_name__					:							str		   =							{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
						return config, inputs_dict





@require_torch
class 		A__				(   __UpperCAmelCase		,     __UpperCAmelCase		,     unittest.TestCase ):
	lowerCamelCase__		: List[str]				    =(
	    (
	        YosoModel,
	        YosoForMaskedLM,
	        YosoForMultipleChoice,
	        YosoForQuestionAnswering,
	        YosoForSequenceClassification,
	        YosoForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	lowerCamelCase__		: Optional[Any]				    =False
	lowerCamelCase__		: Tuple				    =False
	lowerCamelCase__		: Any				    =False

	lowerCamelCase__		: Tuple				    =()
	lowerCamelCase__		: Optional[int]				    =(
	    {
	        "feature-extraction": YosoModel,
	        "fill-mask": YosoForMaskedLM,
	        "question-answering": YosoForQuestionAnswering,
	        "text-classification": YosoForSequenceClassification,
	        "token-classification": YosoForTokenClassification,
	        "zero-shot": YosoForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)






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




						"""simple docstring"""






						__magic_name__					:							Any		   =							YosoModelTester(self						)
						__magic_name__					:							Dict		   =							ConfigTester(self				,     config_class=UpperCAmelCase_				,     hidden_size=37						)






	def  lowercase      (	self						)      ->   str:




						"""simple docstring"""






						self.config_tester.run_common_tests()






	def  lowercase      (	self						)      ->   int:




						"""simple docstring"""






						__magic_name__					:							Any		   =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCAmelCase_						)






	def  lowercase      (	self						)      ->   Dict:




						"""simple docstring"""






						__magic_name__					:							List[str]		   =							self.model_tester.prepare_config_and_inputs()
						for type in ["absolute", "relative_key", "relative_key_query"]:
											__magic_name__					:							Tuple		   =							type
											self.model_tester.create_and_check_model(*UpperCAmelCase_						)






	def  lowercase      (	self						)      ->   str:




						"""simple docstring"""






						__magic_name__					:							Dict		   =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase_						)






	def  lowercase      (	self						)      ->   str:




						"""simple docstring"""






						__magic_name__					:							Any		   =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase_						)






	def  lowercase      (	self						)      ->   Tuple:




						"""simple docstring"""






						__magic_name__					:							str		   =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_						)






	def  lowercase      (	self						)      ->   Dict:




						"""simple docstring"""






						__magic_name__					:							Any		   =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase_						)






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




						"""simple docstring"""






						__magic_name__					:							List[str]		   =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_						)






	@slow
	def  lowercase      (	self						)      ->   List[Any]:




						"""simple docstring"""






						for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__magic_name__					:							List[str]		   =							YosoModel.from_pretrained(UpperCAmelCase_						)
											self.assertIsNotNone(UpperCAmelCase_						)






	def  lowercase      (	self						)      ->   Optional[Any]:




						"""simple docstring"""






						return





@require_torch
class 		A__				(   unittest.TestCase ):






	@slow
	def  lowercase      (	self						)      ->   Dict:




						"""simple docstring"""






						__magic_name__					:							Any		   =							YosoModel.from_pretrained('''uw-madison/yoso-4096'''						)
						__magic_name__					:							Optional[Any]		   =							torch.tensor([[0, 1, 2, 3, 4, 5]]						)

						with torch.no_grad():
											__magic_name__					:							List[str]		   =							model(UpperCAmelCase_						)[0]

						__magic_name__					:							str		   =							torch.Size((1, 6, 768)						)
						self.assertEqual(output.shape				,     UpperCAmelCase_						)

						__magic_name__					:							Tuple		   =							torch.tensor(
						    [[[-0.0_6_1_1, 0.1_2_4_2, 0.0_8_4_0], [0.0_2_8_0, -0.0_0_4_8, 0.1_1_2_5], [0.0_1_0_6, 0.0_2_2_6, 0.0_7_5_1]]]						)

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






	@slow
	def  lowercase      (	self						)      ->   Union[str, Any]:




						"""simple docstring"""






						__magic_name__					:							Any		   =							YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''						)
						__magic_name__					:							Optional[int]		   =							torch.tensor([[0, 1, 2, 3, 4, 5]]						)

						with torch.no_grad():
											__magic_name__					:							Tuple		   =							model(UpperCAmelCase_						)[0]

						__magic_name__					:							Optional[Any]		   =							50265

						__magic_name__					:							List[Any]		   =							torch.Size((1, 6, vocab_size)						)
						self.assertEqual(output.shape				,     UpperCAmelCase_						)

						__magic_name__					:							Optional[int]		   =							torch.tensor(
						    [[[-2.1_3_1_3, -3.7_2_8_5, -2.2_4_0_7], [-2.7_0_4_7, -3.3_3_1_4, -2.6_4_0_8], [0.0_6_2_9, -2.5_1_6_6, -0.3_3_5_6]]]						)

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






	@slow
	def  lowercase      (	self						)      ->   List[str]:




						"""simple docstring"""






						__magic_name__					:							Optional[int]		   =							YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''						)
						__magic_name__					:							str		   =							torch.arange(4096						).unsqueeze(0						)

						with torch.no_grad():
											__magic_name__					:							Union[str, Any]		   =							model(UpperCAmelCase_						)[0]

						__magic_name__					:							Any		   =							50265

						__magic_name__					:							Dict		   =							torch.Size((1, 4096, vocab_size)						)
						self.assertEqual(output.shape				,     UpperCAmelCase_						)

						__magic_name__					:							Tuple		   =							torch.tensor(
						    [[[-2.3_9_1_4, -4.3_7_4_2, -5.0_9_5_6], [-4.0_9_8_8, -4.2_3_8_4, -7.0_4_0_6], [-3.1_4_2_7, -3.7_1_9_2, -6.6_8_0_0]]]						)

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





"""simple docstring"""

import numpy as np
def 		UpperCAmelCase					(		a_,						a_="utf-8",						a_="surrogatepass"			):





		'''simple docstring'''


		lowerCamelCase     :			str		=    bin(int.from_bytes(text.encode(a_,						a_			),						'big'			)			)[2:]
		return bits.zfill(8 * ((len(a_			) + 7) // 8)			)
def 		UpperCAmelCase					(		a_,						a_="utf-8",						a_="surrogatepass"			):





		'''simple docstring'''


		lowerCamelCase     :			List[Any]		=    int(a_,						2			)
		return n.to_bytes((n.bit_length() + 7) // 8,						'big'			).decode(a_,						a_			) or "\0"
def 		UpperCAmelCase					(		a_,						a_			):





		'''simple docstring'''


		if size_par + len(a_			) <= 2**size_par - (len(a_			) - 1):
				raise ValueError('size of parity don\'t match with size of data'			)

		lowerCamelCase     :			List[str]		=    []
		lowerCamelCase     :			str		=    []
		lowerCamelCase     :			Any		=    [bin(a_			)[2:] for x in range(1,						size_par + len(a_			) + 1			)]

		# sorted information data for the size of the output data
		lowerCamelCase     :			int		=    []
		# data position template + parity
		lowerCamelCase     :			Union[str, Any]		=    []
		# parity bit counter
		lowerCamelCase     :			Optional[int]		=    0
		# counter position of data bits
		lowerCamelCase     :			Any		=    0

		for x in range(1,						size_par + len(a_			) + 1			):
				# Performs a template of bit positions - who should be given,
				# and who should be parity
				if qtd_bp < size_par:
						if (np.log(a_			) / np.log(2			)).is_integer():
								data_out_gab.append('P'			)
								lowerCamelCase     :			List[Any]		=    qtd_bp + 1
						else:
								data_out_gab.append('D'			)
				else:
						data_out_gab.append('D'			)

				# Sorts the data to the new output size
				if data_out_gab[-1] == "D":
						data_ord.append(data[cont_data]			)
						cont_data += 1
				else:
						data_ord.append(a_			)

    # Calculates parity
		lowerCamelCase     :			Optional[Any]		=    0  # parity bit counter
		for bp in range(1,						size_par + 1			):
				# Bit counter one for a given parity
				lowerCamelCase     :			Union[str, Any]		=    0
				# counter to control the loop reading
				lowerCamelCase     :			Optional[int]		=    0
				for x in data_ord:
						if x is not None:
								try:
										lowerCamelCase     :			Union[str, Any]		=    (bin_pos[cont_loop])[-1 * (bp)]
								except IndexError:
										lowerCamelCase     :			str		=    '0'
								if aux == "1" and x == "1":
										cont_bo += 1
						cont_loop += 1
				parity.append(cont_bo % 2			)

				qtd_bp += 1

		# Mount the message
		lowerCamelCase     :			Tuple		=    0  # parity bit counter
		for x in range(0,						size_par + len(a_			)			):
				if data_ord[x] is None:
						data_out.append(str(parity[cont_bp]			)			)
						cont_bp += 1
				else:
						data_out.append(data_ord[x]			)

		return data_out
def 		UpperCAmelCase					(		a_,						a_			):





		'''simple docstring'''


		lowerCamelCase     :			str		=    []
		# Parity bit counter
		lowerCamelCase     :			Dict		=    0
		# Counter p data bit reading
		lowerCamelCase     :			int		=    0
		# list of parity received
		lowerCamelCase     :			Optional[int]		=    []
		lowerCamelCase     :			Any		=    []

		for x in range(1,						len(a_			) + 1			):
				# Performs a template of bit positions - who should be given,
				#  and who should be parity
				if qtd_bp < size_par and (np.log(a_			) / np.log(2			)).is_integer():
						data_out_gab.append('P'			)
						lowerCamelCase     :			List[Any]		=    qtd_bp + 1
				else:
						data_out_gab.append('D'			)

				# Sorts the data to the new output size
				if data_out_gab[-1] == "D":
						data_output.append(data[cont_data]			)
				else:
						parity_received.append(data[cont_data]			)
				cont_data += 1

		# -----------calculates the parity with the data
		lowerCamelCase     :			Dict		=    []
		lowerCamelCase     :			Optional[Any]		=    []
		lowerCamelCase     :			Dict		=    [bin(a_			)[2:] for x in range(1,						size_par + len(a_			) + 1			)]

		#  sorted information data for the size of the output data
		lowerCamelCase     :			Any		=    []
		# Data position feedback + parity
		lowerCamelCase     :			List[str]		=    []
		# Parity bit counter
		lowerCamelCase     :			List[str]		=    0
		# Counter p data bit reading
		lowerCamelCase     :			int		=    0

		for x in range(1,						size_par + len(a_			) + 1			):
				# Performs a template position of bits - who should be given,
				# and who should be parity
				if qtd_bp < size_par and (np.log(a_			) / np.log(2			)).is_integer():
						data_out_gab.append('P'			)
						lowerCamelCase     :			Tuple		=    qtd_bp + 1
				else:
						data_out_gab.append('D'			)

				# Sorts the data to the new output size
				if data_out_gab[-1] == "D":
						data_ord.append(data_output[cont_data]			)
						cont_data += 1
				else:
						data_ord.append(a_			)

    # Calculates parity
		lowerCamelCase     :			List[str]		=    0  # parity bit counter
		for bp in range(1,						size_par + 1			):
				# Bit counter one for a certain parity
				lowerCamelCase     :			List[Any]		=    0
				# Counter to control loop reading
				lowerCamelCase     :			List[Any]		=    0
				for x in data_ord:
						if x is not None:
								try:
										lowerCamelCase     :			Dict		=    (bin_pos[cont_loop])[-1 * (bp)]
								except IndexError:
										lowerCamelCase     :			List[Any]		=    '0'
								if aux == "1" and x == "1":
										cont_bo += 1
						cont_loop += 1
				parity.append(str(cont_bo % 2			)			)

				qtd_bp += 1

		# Mount the message
		lowerCamelCase     :			Tuple		=    0  # Parity bit counter
		for x in range(0,						size_par + len(a_			)			):
				if data_ord[x] is None:
						data_out.append(str(parity[cont_bp]			)			)
						cont_bp += 1
				else:
						data_out.append(data_ord[x]			)

		lowerCamelCase     :			Union[str, Any]		=    parity_received == parity
		return data_output, ack






