






'''simple docstring'''







import unittest

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

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    FalconForCausalLM,
			    FalconForQuestionAnswering,
			    FalconForSequenceClassification,
			    FalconForTokenClassification,
			    FalconModel,
			)

class _lowercase			:




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




							def 	lowerCamelCase_       (							self:       Dict  ):
														lowerCamelCase__      :			Dict 						= ids_tensor([self.batch_size, self.seq_length]    ,							self.vocab_size  )

														lowerCamelCase__      :			Tuple 						= None
														if self.use_input_mask:
																					lowerCamelCase__      :			Tuple 						= random_attention_mask([self.batch_size, self.seq_length]  )

														lowerCamelCase__      :			Union[str, Any] 						= None

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

														lowerCamelCase__      :			Optional[int] 						= self.get_config()

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




							def 	lowerCamelCase_       (							self:       Tuple  ):
														return FalconConfig(
														    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    ,							pad_token_id=1    ,							new_decoder_architecture=UpperCamelCase__    ,							)




							def 	lowerCamelCase_       (							self:       List[Any]    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       Optional[Any]    ,							UpperCamelCase__:       str    ,							UpperCamelCase__:       Optional[Any]    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       Optional[int]    ,							UpperCamelCase__:       Union[str, Any]  ):
														lowerCamelCase__      :			Any 						= FalconModel(config=UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()
														lowerCamelCase__      :			Tuple 						= model(UpperCamelCase__    ,							attention_mask=UpperCamelCase__  )
														lowerCamelCase__      :			int 						= model(UpperCamelCase__  )
														self.parent.assertEqual(result.last_hidden_state.shape    ,							(self.batch_size, self.seq_length, self.hidden_size)  )




							def 	lowerCamelCase_       (							self:       str    ,							UpperCamelCase__:       int    ,							UpperCamelCase__:       int    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       Tuple    ,							UpperCamelCase__:       Tuple    ,							UpperCamelCase__:       Dict    ,							UpperCamelCase__:       int    ,							UpperCamelCase__:       Tuple    ,							):
														lowerCamelCase__      :			Dict 						= True
														lowerCamelCase__      :			Dict 						= FalconModel(UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()
														lowerCamelCase__      :			Union[str, Any] 						= model(
														    UpperCamelCase__    ,							attention_mask=UpperCamelCase__    ,							encoder_hidden_states=UpperCamelCase__    ,							encoder_attention_mask=UpperCamelCase__    ,							)
														lowerCamelCase__      :			List[Any] 						= model(
														    UpperCamelCase__    ,							attention_mask=UpperCamelCase__    ,							encoder_hidden_states=UpperCamelCase__    ,							)
														lowerCamelCase__      :			List[Any] 						= model(UpperCamelCase__    ,							attention_mask=UpperCamelCase__  )
														self.parent.assertEqual(result.last_hidden_state.shape    ,							(self.batch_size, self.seq_length, self.hidden_size)  )




							def 	lowerCamelCase_       (							self:       Any    ,							UpperCamelCase__:       str    ,							UpperCamelCase__:       str    ,							UpperCamelCase__:       int    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       Optional[Any]    ,							UpperCamelCase__:       Optional[int]    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       Optional[Any]    ,							UpperCamelCase__:       Union[str, Any]    ,							):
														lowerCamelCase__      :			Any 						= FalconForCausalLM(config=UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()
														lowerCamelCase__      :			Optional[Any] 						= model(UpperCamelCase__    ,							attention_mask=UpperCamelCase__    ,							labels=UpperCamelCase__  )
														self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.seq_length, self.vocab_size)  )




							def 	lowerCamelCase_       (							self:       List[Any]    ,							UpperCamelCase__:       Any    ,							UpperCamelCase__:       str    ,							UpperCamelCase__:       List[str]    ,							UpperCamelCase__:       List[Any]    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       int    ,							UpperCamelCase__:       Optional[int]    ,							UpperCamelCase__:       int    ,							UpperCamelCase__:       Optional[int]    ,							):
														lowerCamelCase__      :			List[Any] 						= True
														lowerCamelCase__      :			Dict 						= True
														lowerCamelCase__      :			str 						= FalconForCausalLM(config=UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()

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

														# create hypothetical multiple next token and extent to next_input_ids
														lowerCamelCase__      :			Union[str, Any] 						= ids_tensor((self.batch_size, 3)    ,							config.vocab_size  )
														lowerCamelCase__      :			Optional[int] 						= ids_tensor((self.batch_size, 3)    ,							vocab_size=2  )

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

														lowerCamelCase__      :			Tuple 						= model(
														    UpperCamelCase__    ,							attention_mask=UpperCamelCase__    ,							encoder_hidden_states=UpperCamelCase__    ,							encoder_attention_mask=UpperCamelCase__    ,							output_hidden_states=UpperCamelCase__    ,							)["""hidden_states"""][0]
														lowerCamelCase__      :			Dict 						= model(
														    UpperCamelCase__    ,							attention_mask=UpperCamelCase__    ,							encoder_hidden_states=UpperCamelCase__    ,							encoder_attention_mask=UpperCamelCase__    ,							past_key_values=UpperCamelCase__    ,							output_hidden_states=UpperCamelCase__    ,							)["""hidden_states"""][0]

														# select random slice
														lowerCamelCase__      :			List[Any] 						= ids_tensor((1,)    ,							output_from_past.shape[-1]  ).item()
														lowerCamelCase__      :			Any 						= output_from_no_past[:, -3:, random_slice_idx].detach()
														lowerCamelCase__      :			Any 						= 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(UpperCamelCase__    ,							UpperCamelCase__    ,							atol=1e-3  )  )




							def 	lowerCamelCase_       (							self:       Optional[Any]  ):
														lowerCamelCase__      :			str 						= self.prepare_config_and_inputs()
														(
														    lowerCamelCase__	
														)      :			List[str] 						= config_and_inputs
														lowerCamelCase__      :			Tuple 						= {"""input_ids""": input_ids, """attention_mask""": input_mask}
														return config, inputs_dict



@require_torch
class _lowercase			(       _lowercase       ,   _lowercase       ,   _lowercase       ,   unittest.TestCase	):
							a          = (
							    (
							        FalconModel,
							        FalconForCausalLM,
							        FalconForSequenceClassification,
							        FalconForTokenClassification,
							        FalconForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							a          = (FalconForCausalLM,) if is_torch_available() else ()
							a          = (
							    {
							        """feature-extraction""": FalconModel,
							        """text-classification""": FalconForSequenceClassification,
							        """text-generation""": FalconForCausalLM,
							        """question-answering""": FalconForQuestionAnswering,
							        """token-classification""": FalconForTokenClassification,
							        """zero-shot""": FalconForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							a          = False
							a          = False




							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														lowerCamelCase__      :			Tuple 						= FalconModelTester(self  )
														lowerCamelCase__      :			Optional[int] 						= ConfigTester(self    ,							config_class=UpperCamelCase__    ,							hidden_size=37  )




							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														self.config_tester.run_common_tests()




							def 	lowerCamelCase_       (							self:       Optional[int]  ):
														lowerCamelCase__      :			Optional[int] 						= self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       Dict  ):
														lowerCamelCase__      :			Tuple 						= self.model_tester.prepare_config_and_inputs()
														for alibi in [True, False]:
																					lowerCamelCase__      :			str 						= alibi
																					self.model_tester.create_and_check_model(UpperCamelCase__    ,							*UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														lowerCamelCase__      :			Optional[Any] 						= self.model_tester.prepare_config_and_inputs_for_common()
														lowerCamelCase__      :			Union[str, Any] 						= 3
														lowerCamelCase__      :			Optional[int] 						= input_dict["""input_ids"""]
														lowerCamelCase__      :			Any 						= input_ids.ne(1  ).to(UpperCamelCase__  )
														lowerCamelCase__      :			List[Any] 						= ids_tensor([self.model_tester.batch_size]    ,							self.model_tester.type_sequence_label_size  )
														lowerCamelCase__      :			Dict 						= FalconForSequenceClassification(UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()
														lowerCamelCase__      :			str 						= model(UpperCamelCase__    ,							attention_mask=UpperCamelCase__    ,							labels=UpperCamelCase__  )
														self.assertEqual(result.logits.shape    ,							(self.model_tester.batch_size, self.model_tester.num_labels)  )




							def 	lowerCamelCase_       (							self:       Dict  ):
														lowerCamelCase__      :			int 						= self.model_tester.prepare_config_and_inputs_for_common()
														lowerCamelCase__      :			int 						= 3
														lowerCamelCase__      :			Optional[Any] 						= """single_label_classification"""
														lowerCamelCase__      :			int 						= input_dict["""input_ids"""]
														lowerCamelCase__      :			int 						= input_ids.ne(1  ).to(UpperCamelCase__  )
														lowerCamelCase__      :			List[Any] 						= ids_tensor([self.model_tester.batch_size]    ,							self.model_tester.type_sequence_label_size  )
														lowerCamelCase__      :			str 						= FalconForSequenceClassification(UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()
														lowerCamelCase__      :			int 						= model(UpperCamelCase__    ,							attention_mask=UpperCamelCase__    ,							labels=UpperCamelCase__  )
														self.assertEqual(result.logits.shape    ,							(self.model_tester.batch_size, self.model_tester.num_labels)  )




							def 	lowerCamelCase_       (							self:       List[Any]  ):
														lowerCamelCase__      :			Dict 						= self.model_tester.prepare_config_and_inputs_for_common()
														lowerCamelCase__      :			Tuple 						= input_dict["""input_ids"""]
														lowerCamelCase__      :			Optional[int] 						= FalconForCausalLM(UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()
														lowerCamelCase__      :			int 						= model(UpperCamelCase__    ,							use_cache=UpperCamelCase__  )
														lowerCamelCase__      :			str 						= input_ids.shape[0]
														lowerCamelCase__      :			Dict 						= model._convert_to_rw_cache(result.past_key_values  )
														lowerCamelCase__      :			str 						= model._convert_cache_to_standard_format(UpperCamelCase__    ,							UpperCamelCase__  )
														for layer in range(len(UpperCamelCase__  )  ):
																					for tensor_idx in range(2  ):
																												self.assertTrue(rw_cache[layer][tensor_idx].ndim == 3  )
																												self.assertTrue(result.past_key_values[layer][tensor_idx].ndim == 4  )
																												self.assertTrue(
																												    torch.all(result.past_key_values[layer][tensor_idx] == standard_cache[layer][tensor_idx]  )  )




							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														lowerCamelCase__      :			Optional[int] 						= self.model_tester.prepare_config_and_inputs_for_common()
														lowerCamelCase__      :			List[Any] 						= 3
														lowerCamelCase__      :			Optional[Any] 						= """multi_label_classification"""
														lowerCamelCase__      :			List[str] 						= input_dict["""input_ids"""]
														lowerCamelCase__      :			str 						= input_ids.ne(1  ).to(UpperCamelCase__  )
														lowerCamelCase__      :			Tuple 						= ids_tensor(
														    [self.model_tester.batch_size, config.num_labels]    ,							self.model_tester.type_sequence_label_size  ).to(torch.float  )
														lowerCamelCase__      :			Dict 						= FalconForSequenceClassification(UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()
														lowerCamelCase__      :			Union[str, Any] 						= model(UpperCamelCase__    ,							attention_mask=UpperCamelCase__    ,							labels=UpperCamelCase__  )
														self.assertEqual(result.logits.shape    ,							(self.model_tester.batch_size, self.model_tester.num_labels)  )




							def 	lowerCamelCase_       (							self:       Optional[Any]  ):
														# Falcon can have different numbers of KV-heads than the number of query heads, so we need
														# to override this test to use the right head counts.
														for model_class in self.all_generative_model_classes:
																					lowerCamelCase__      :			Union[str, Any] 						= self.model_tester.prepare_config_and_inputs_for_common()

																					# If it doesn't support cache, pass the test
																					if not hasattr(UpperCamelCase__    ,							"""use_cache"""  ):
																												return

																					lowerCamelCase__      :			List[str] 						= model_class(UpperCamelCase__  ).to(UpperCamelCase__  )
																					if "use_cache" not in inputs:
																												lowerCamelCase__      :			int 						= True
																					lowerCamelCase__      :			List[Any] 						= model(**UpperCamelCase__  )

																					# If "past_key_values" is not returned, pass the test (e.g. RWKV uses a different cache name and format)
																					if "past_key_values" not in outputs:
																												return

																					lowerCamelCase__      :			Tuple 						= (
																					    getattr(UpperCamelCase__    ,							"""decoder_layers"""    ,							UpperCamelCase__  )
																					    or getattr(UpperCamelCase__    ,							"""num_decoder_layers"""    ,							UpperCamelCase__  )
																					    or config.num_hidden_layers
																					)
																					lowerCamelCase__      :			Optional[int] 						= getattr(UpperCamelCase__    ,							"""num_kv_heads"""    ,							config.num_attention_heads  )
																					lowerCamelCase__      :			Tuple 						= getattr(UpperCamelCase__    ,							"""d_model"""    ,							config.hidden_size  )
																					lowerCamelCase__      :			Union[str, Any] 						= embed_dim // num_attention_heads

																					lowerCamelCase__      :			Any 						= outputs["""past_key_values"""]
																					self.assertEqual(len(UpperCamelCase__  )    ,							UpperCamelCase__  )

																					lowerCamelCase__      :			Tuple 						= inputs["""input_ids"""].shape
																					for i in range(UpperCamelCase__  ):
																												if config.new_decoder_architecture:
																																			lowerCamelCase__      :			Dict 						= config.num_attention_heads
																												elif config.multi_query:
																																			lowerCamelCase__      :			List[str] 						= 1
																												self.assertEqual(len(past_kv[0]  )    ,							2  )  # K V for the decoder = 2
																												self.assertEqual(
																												    past_kv[i][0].shape    ,							(batch_size, num_attention_heads, seq_length, per_head_embed_dim)  )
																												self.assertEqual(
																												    past_kv[i][1].shape    ,							(batch_size, num_attention_heads, seq_length, per_head_embed_dim)  )



@require_torch
class _lowercase			(       unittest.TestCase	):




							@slow
							def 	lowerCamelCase_       (							self:       str  ):
														lowerCamelCase__      :			Union[str, Any] 						= AutoTokenizer.from_pretrained("""Rocketknight1/falcon-rw-1b"""  )
														lowerCamelCase__      :			Any 						= FalconForCausalLM.from_pretrained("""Rocketknight1/falcon-rw-1b"""  )
														model.eval()
														model.to(UpperCamelCase__  )
														lowerCamelCase__      :			List[Any] 						= tokenizer("""My favorite food is"""    ,							return_tensors="""pt"""  ).to(UpperCamelCase__  )

														lowerCamelCase__      :			str 						= (
														    """My favorite food is pizza. I love it so much that I have a pizza party every year for my birthday."""
														)

														lowerCamelCase__      :			List[str] 						= model.generate(**UpperCamelCase__    ,							do_sample=UpperCamelCase__    ,							max_new_tokens=19  )
														lowerCamelCase__      :			Optional[int] 						= tokenizer.batch_decode(UpperCamelCase__  )[0]

														self.assertEqual(UpperCamelCase__    ,							UpperCamelCase__  )




							@slow
							def 	lowerCamelCase_       (							self:       int  ):
														# The big models are way too big for the CI, so we use tiny random models that resemble their
														# architectures but with much smaller and fewer layers
														for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
																					lowerCamelCase__      :			List[Any] 						= AutoTokenizer.from_pretrained(UpperCamelCase__  )
																					lowerCamelCase__      :			Union[str, Any] 						= FalconForCausalLM.from_pretrained(UpperCamelCase__  )
																					model.eval()
																					model.to(UpperCamelCase__  )
																					lowerCamelCase__      :			List[str] 						= tokenizer("""My favorite food is"""    ,							return_tensors="""pt"""  ).to(UpperCamelCase__  )

																					# We just test that these run without errors - the models are randomly initialized
																					# and so the actual text outputs will be garbage
																					model.generate(**UpperCamelCase__    ,							do_sample=UpperCamelCase__    ,							max_new_tokens=4  )
																					model.generate(**UpperCamelCase__    ,							do_sample=UpperCamelCase__    ,							max_new_tokens=4  )
																					model.generate(**UpperCamelCase__    ,							num_beams=2    ,							max_new_tokens=4  )




							@slow
							def 	lowerCamelCase_       (							self:       str  ):
														# The big models are way too big for the CI, so we use tiny random models that resemble their
														# architectures but with much smaller and fewer layers
														with torch.no_grad():
																					for repo in [
																					    "Rocketknight1/falcon-rw-1b",
																					    "Rocketknight1/tiny-random-falcon-7b",
																					    "Rocketknight1/tiny-random-falcon-40b",
																					]:
																												lowerCamelCase__      :			Union[str, Any] 						= AutoTokenizer.from_pretrained(UpperCamelCase__  )
																												lowerCamelCase__      :			str 						= FalconForCausalLM.from_pretrained(UpperCamelCase__  )
																												model.eval()
																												model.to(device=UpperCamelCase__  )
																												lowerCamelCase__      :			Optional[Any] 						= tokenizer("""My favorite food is"""    ,							return_tensors="""pt"""  ).to(UpperCamelCase__  )

																												# Test results are the same with and without cache
																												lowerCamelCase__      :			Union[str, Any] 						= model.generate(**UpperCamelCase__    ,							do_sample=UpperCamelCase__    ,							max_new_tokens=20    ,							use_cache=UpperCamelCase__  )
																												lowerCamelCase__      :			str 						= model.generate(**UpperCamelCase__    ,							do_sample=UpperCamelCase__    ,							max_new_tokens=20    ,							use_cache=UpperCamelCase__  )
																												self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0  )









'''simple docstring'''







from statistics import mean

import numpy as np





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase       ,    UpperCamelCase       ,    UpperCamelCase       ,    UpperCamelCase   )   -> list:
							lowerCamelCase__      :			Optional[int] 						= 0
							# Number of processes finished
							lowerCamelCase__      :			Union[str, Any] 						= 0
							# Displays the finished process.
							# If it is 0, the performance is completed if it is 1, before the performance.
							lowerCamelCase__      :			Tuple 						= [0] * no_of_process
							# List to include calculation results
							lowerCamelCase__      :			List[str] 						= [0] * no_of_process

							# Sort by arrival time.
							lowerCamelCase__      :			Union[str, Any] 						= [burst_time[i] for i in np.argsort(UpperCamelCase   )]
							lowerCamelCase__      :			List[Any] 						= [process_name[i] for i in np.argsort(UpperCamelCase   )]
							arrival_time.sort()

							while no_of_process > finished_process_count:
														lowerCamelCase__      :			str 						= 0
														while finished_process[i] == 1:
																					i += 1
														if current_time < arrival_time[i]:
																					lowerCamelCase__      :			Union[str, Any] 						= arrival_time[i]

														lowerCamelCase__      :			Any 						= 0
														# Index showing the location of the process being performed
														lowerCamelCase__      :			Union[str, Any] 						= 0
														# Saves the current response ratio.
														lowerCamelCase__      :			Any 						= 0
														for i in range(0       ,    UpperCamelCase   ):
																					if finished_process[i] == 0 and arrival_time[i] <= current_time:
																												lowerCamelCase__      :			Optional[int] 						= (burst_time[i] + (current_time - arrival_time[i])) / burst_time[
																												    i
																												]
																					if response_ratio < temp:
																												lowerCamelCase__      :			int 						= temp
																												lowerCamelCase__      :			str 						= i

        # Calculate the turn around time
														lowerCamelCase__      :			Optional[int] 						= current_time + burst_time[loc] - arrival_time[loc]
														current_time += burst_time[loc]
														# Indicates that the process has been performed.
														lowerCamelCase__      :			List[str] 						= 1
														# Increase finished_process_count by 1
														finished_process_count += 1

							return turn_around_time





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase       ,    UpperCamelCase       ,    UpperCamelCase       ,    UpperCamelCase   )   -> list:
							lowerCamelCase__      :			int 						= [0] * no_of_process
							for i in range(0       ,    UpperCamelCase   ):
														lowerCamelCase__      :			Optional[Any] 						= turn_around_time[i] - burst_time[i]
							return waiting_time


if __name__ == "__main__":
			_A			:    List[str]					  =5
			_A			:    Optional[Any]					  =['''A''', '''B''', '''C''', '''D''', '''E''']
			_A			:    Optional[int]					  =[1, 2, 3, 4, 5]
			_A			:    Dict					  =[1, 2, 3, 4, 5]

			_A			:    Any					  =calculate_turn_around_time(
			    process_name, arrival_time, burst_time, no_of_process
			)
			_A			:    Optional[int]					  =calculate_waiting_time(
			    process_name, turn_around_time, burst_time, no_of_process
			)

			print('''Process name \tArrival time \tBurst time \tTurn around time \tWaiting time''')
			for i in range(0, no_of_process):
						print(
						    F'{process_name[i]}\t\t{arrival_time[i]}\t\t{burst_time[i]}\t\t'
						    F'{turn_around_time[i]}\t\t\t{waiting_time[i]}'
						)

			print(F'average waiting time : {mean(waiting_time):.5f}')
			print(F'average turn around time : {mean(turn_around_time):.5f}')

