
"""simple docstring"""

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        _lowercase   :




	def __init__( self		, UpperCAmelCase_		, UpperCAmelCase_=13		, UpperCAmelCase_=7		, UpperCAmelCase_=True		, UpperCAmelCase_=True		, UpperCAmelCase_=True		, UpperCAmelCase_=True		, UpperCAmelCase_=99		, UpperCAmelCase_=32		, UpperCAmelCase_=5		, UpperCAmelCase_=4		, UpperCAmelCase_=37		, UpperCAmelCase_="gelu"		, UpperCAmelCase_=0.1		, UpperCAmelCase_=0.1		, UpperCAmelCase_=512		, UpperCAmelCase_=16		, UpperCAmelCase_=2		, UpperCAmelCase_=0.02		, UpperCAmelCase_=3		, UpperCAmelCase_=4		, UpperCAmelCase_=None		, )		->							str:
			lowerCamelCase     :			Union[str, Any]		=    parent
			lowerCamelCase     :			Tuple		=    batch_size
			lowerCamelCase     :			int		=    seq_length
			lowerCamelCase     :			Union[str, Any]		=    is_training
			lowerCamelCase     :			Dict		=    use_input_mask
			lowerCamelCase     :			List[Any]		=    use_token_type_ids
			lowerCamelCase     :			int		=    use_labels
			lowerCamelCase     :			int		=    vocab_size
			lowerCamelCase     :			int		=    hidden_size
			lowerCamelCase     :			List[Any]		=    num_hidden_layers
			lowerCamelCase     :			List[Any]		=    num_attention_heads
			lowerCamelCase     :			str		=    intermediate_size
			lowerCamelCase     :			Optional[Any]		=    hidden_act
			lowerCamelCase     :			List[str]		=    hidden_dropout_prob
			lowerCamelCase     :			Optional[Any]		=    attention_probs_dropout_prob
			lowerCamelCase     :			Union[str, Any]		=    max_position_embeddings
			lowerCamelCase     :			int		=    type_vocab_size
			lowerCamelCase     :			Any		=    type_sequence_label_size
			lowerCamelCase     :			List[Any]		=    initializer_range
			lowerCamelCase     :			List[str]		=    num_labels
			lowerCamelCase     :			Optional[Any]		=    num_choices
			lowerCamelCase     :			List[Any]		=    scope




	def 			_UpperCamelCase    ( self					)		->							Optional[int]:
			lowerCamelCase     :			int		=    ids_tensor([self.batch_size, self.seq_length]		, self.vocab_size					)

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

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

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

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

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




	def 			_UpperCamelCase    ( self					)		->							str:
			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 			_UpperCamelCase    ( self					)		->							Optional[Any]:
			lowerCamelCase     :			Dict		=    self.get_config()
			lowerCamelCase     :			Any		=    300
			return config




	def 			_UpperCamelCase    ( self					)		->							int:
			(
			    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    
			)     :			List[str]		=    self.prepare_config_and_inputs()

			lowerCamelCase     :			Union[str, Any]		=    True
			lowerCamelCase     :			Union[str, Any]		=    floats_tensor([self.batch_size, self.seq_length, self.hidden_size]					)
			lowerCamelCase     :			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 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_					)		->							List[str]:
			lowerCamelCase     :			int		=    YosoModel(config=UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			Dict		=    model(UpperCAmelCase_		, attention_mask=UpperCAmelCase_		, token_type_ids=UpperCAmelCase_					)
			lowerCamelCase     :			str		=    model(UpperCAmelCase_		, token_type_ids=UpperCAmelCase_					)
			lowerCamelCase     :			List[str]		=    model(UpperCAmelCase_					)
			self.parent.assertEqual(result.last_hidden_state.shape		, (self.batch_size, self.seq_length, self.hidden_size)					)




	def 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, )		->							int:
			lowerCamelCase     :			str		=    True
			lowerCamelCase     :			List[Any]		=    YosoModel(UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			int		=    model(
			    UpperCAmelCase_		, attention_mask=UpperCAmelCase_		, token_type_ids=UpperCAmelCase_		, encoder_hidden_states=UpperCAmelCase_		, encoder_attention_mask=UpperCAmelCase_		, )
			lowerCamelCase     :			List[Any]		=    model(
			    UpperCAmelCase_		, attention_mask=UpperCAmelCase_		, token_type_ids=UpperCAmelCase_		, encoder_hidden_states=UpperCAmelCase_		, )
			lowerCamelCase     :			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 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_					)		->							Tuple:
			lowerCamelCase     :			Tuple		=    YosoForMaskedLM(config=UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			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 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_					)		->							Optional[Any]:
			lowerCamelCase     :			Dict		=    YosoForQuestionAnswering(config=UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			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 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_					)		->							Dict:
			lowerCamelCase     :			Dict		=    self.num_labels
			lowerCamelCase     :			Optional[Any]		=    YosoForSequenceClassification(UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			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 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_					)		->							Any:
			lowerCamelCase     :			List[Any]		=    self.num_labels
			lowerCamelCase     :			Tuple		=    YosoForTokenClassification(config=UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			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 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_					)		->							Tuple:
			lowerCamelCase     :			Any		=    self.num_choices
			lowerCamelCase     :			Dict		=    YosoForMultipleChoice(config=UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			int		=    input_ids.unsqueeze(1					).expand(-1		, self.num_choices		, -1					).contiguous()
			lowerCamelCase     :			Tuple		=    token_type_ids.unsqueeze(1					).expand(-1		, self.num_choices		, -1					).contiguous()
			lowerCamelCase     :			List[Any]		=    input_mask.unsqueeze(1					).expand(-1		, self.num_choices		, -1					).contiguous()
			lowerCamelCase     :			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 			_UpperCamelCase    ( self					)		->							Dict:
			lowerCamelCase     :			Tuple		=    self.prepare_config_and_inputs()
			(
			    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    (
			    lowerCamelCase
			)	,    
			)     :			List[Any]		=    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        _lowercase   (				__UpperCAmelCase				,       __UpperCAmelCase				,       unittest.TestCase		):
	lowercase_        =	(
	    (
	        YosoModel,
	        YosoForMaskedLM,
	        YosoForMultipleChoice,
	        YosoForQuestionAnswering,
	        YosoForSequenceClassification,
	        YosoForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	lowercase_        =	False
	lowercase_        =	False
	lowercase_        =	False

	lowercase_        =	()
	lowercase_        =	(
	    {
	        'feature-extraction': YosoModel,
	        'fill-mask': YosoForMaskedLM,
	        'question-answering': YosoForQuestionAnswering,
	        'text-classification': YosoForSequenceClassification,
	        'token-classification': YosoForTokenClassification,
	        'zero-shot': YosoForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)




	def 			_UpperCamelCase    ( self					)		->							Optional[int]:
			lowerCamelCase     :			Any		=    YosoModelTester(self					)
			lowerCamelCase     :			Dict		=    ConfigTester(self		, config_class=UpperCAmelCase_		, hidden_size=37					)




	def 			_UpperCamelCase    ( self					)		->							str:
			self.config_tester.run_common_tests()




	def 			_UpperCamelCase    ( self					)		->							int:
			lowerCamelCase     :			Any		=    self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							Dict:
			lowerCamelCase     :			List[str]		=    self.model_tester.prepare_config_and_inputs()
			for type in ["absolute", "relative_key", "relative_key_query"]:
					lowerCamelCase     :			Tuple		=    type
					self.model_tester.create_and_check_model(*UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							str:
			lowerCamelCase     :			Dict		=    self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							str:
			lowerCamelCase     :			Any		=    self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							Tuple:
			lowerCamelCase     :			str		=    self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							Dict:
			lowerCamelCase     :			Any		=    self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							List[Any]:
			lowerCamelCase     :			List[str]		=    self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_					)




	@slow
	def 			_UpperCamelCase    ( self					)		->							List[Any]:
			for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					lowerCamelCase     :			List[str]		=    YosoModel.from_pretrained(UpperCAmelCase_					)
					self.assertIsNotNone(UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							Optional[Any]:
			return






@require_torch
class        _lowercase   (				unittest.TestCase		):




	@slow
	def 			_UpperCamelCase    ( self					)		->							Dict:
			lowerCamelCase     :			Any		=    YosoModel.from_pretrained('uw-madison/yoso-4096'					)
			lowerCamelCase     :			Optional[Any]		=    torch.tensor([[0, 1, 2, 3, 4, 5]]					)

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

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

			lowerCamelCase     :			Tuple		=    torch.tensor(
			    [[[-0.0611, 0.1242, 0.0840], [0.0280, -0.0048, 0.1125], [0.0106, 0.0226, 0.0751]]]					)

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




	@slow
	def 			_UpperCamelCase    ( self					)		->							Union[str, Any]:
			lowerCamelCase     :			Any		=    YosoForMaskedLM.from_pretrained('uw-madison/yoso-4096'					)
			lowerCamelCase     :			Optional[int]		=    torch.tensor([[0, 1, 2, 3, 4, 5]]					)

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

			lowerCamelCase     :			Optional[Any]		=    50265

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

			lowerCamelCase     :			Optional[int]		=    torch.tensor(
			    [[[-2.1313, -3.7285, -2.2407], [-2.7047, -3.3314, -2.6408], [0.0629, -2.5166, -0.3356]]]					)

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




	@slow
	def 			_UpperCamelCase    ( self					)		->							List[str]:
			lowerCamelCase     :			Optional[int]		=    YosoForMaskedLM.from_pretrained('uw-madison/yoso-4096'					)
			lowerCamelCase     :			str		=    torch.arange(4096					).unsqueeze(0					)

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

			lowerCamelCase     :			Any		=    50265

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

			lowerCamelCase     :			Tuple		=    torch.tensor(
			    [[[-2.3914, -4.3742, -5.0956], [-4.0988, -4.2384, -7.0406], [-3.1427, -3.7192, -6.6800]]]					)

			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






