

import math
import unittest

from transformers import BioGptConfig, 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 (
					    BioGptForCausalLM,
					    BioGptForSequenceClassification,
					    BioGptForTokenClassification,
					    BioGptModel,
					    BioGptTokenizer,
					)
					from transformers.models.biogpt.modeling_biogpt import BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST





class       snake_case_  :







			'''simple docstring'''

			def __init__(	self					:							List[str]				,  _UpperCamelCase					:							Dict				,  _UpperCamelCase					:							int=1_3				,  _UpperCamelCase					:							Tuple=7				,  _UpperCamelCase					:							Optional[Any]=True				,  _UpperCamelCase					:							int=True				,  _UpperCamelCase					:							Optional[int]=False				,  _UpperCamelCase					:							int=True				,  _UpperCamelCase					:							List[Any]=9_9				,  _UpperCamelCase					:							Union[str, Any]=3_2				,  _UpperCamelCase					:							Union[str, Any]=5				,  _UpperCamelCase					:							int=4				,  _UpperCamelCase					:							str=3_7				,  _UpperCamelCase					:							List[str]="gelu"				,  _UpperCamelCase					:							Optional[int]=0.1				,  _UpperCamelCase					:							List[Any]=0.1				,  _UpperCamelCase					:							Any=5_1_2				,  _UpperCamelCase					:							List[str]=1_6				,  _UpperCamelCase					:							Tuple=2				,  _UpperCamelCase					:							Optional[Any]=0.02				,  _UpperCamelCase					:							Union[str, Any]=3				,  _UpperCamelCase					:							Optional[Any]=4				,  _UpperCamelCase					:							Optional[int]=None				,  ) ->Optional[Any]:
									snake_case_  =      parent
									snake_case_  =      batch_size
									snake_case_  =      seq_length
									snake_case_  =      is_training
									snake_case_  =      use_input_mask
									snake_case_  =      use_token_type_ids
									snake_case_  =      use_labels
									snake_case_  =      vocab_size
									snake_case_  =      hidden_size
									snake_case_  =      num_hidden_layers
									snake_case_  =      num_attention_heads
									snake_case_  =      intermediate_size
									snake_case_  =      hidden_act
									snake_case_  =      hidden_dropout_prob
									snake_case_  =      attention_probs_dropout_prob
									snake_case_  =      max_position_embeddings
									snake_case_  =      type_vocab_size
									snake_case_  =      type_sequence_label_size
									snake_case_  =      initializer_range
									snake_case_  =      num_labels
									snake_case_  =      num_choices
									snake_case_  =      scope







			def 							snake_case__(	self					:							Dict				) ->int:
									snake_case_  =      ids_tensor([self.batch_size, self.seq_length]				,  self.vocab_size				)

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

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

									snake_case_  =      None
									snake_case_  =      None
									snake_case_  =      None
									if self.use_labels:
															snake_case_  =      ids_tensor([self.batch_size]				,  self.type_sequence_label_size				)
															snake_case_  =      ids_tensor([self.batch_size, self.seq_length]				,  self.num_labels				)
															snake_case_  =      ids_tensor([self.batch_size]				,  self.num_choices				)

									snake_case_  =      self.get_config()

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







			def 							snake_case__(	self					:							int				) ->Tuple:
									return BioGptConfig(
									    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=__A				,  initializer_range=self.initializer_range				,  )







			def 							snake_case__(	self					:							Tuple				,  _UpperCamelCase					:							Optional[int]				,  _UpperCamelCase					:							Union[str, Any]				,  _UpperCamelCase					:							List[str]				,  _UpperCamelCase					:							List[Any]				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							Dict				,  _UpperCamelCase					:							List[str]				) ->Optional[int]:
									snake_case_  =      BioGptModel(config=__A				)
									model.to(__A				)
									model.eval()
									snake_case_  =      model(__A				,  attention_mask=__A				)
									snake_case_  =      model(__A				)
									self.parent.assertEqual(result.last_hidden_state.shape				,  (self.batch_size, self.seq_length, self.hidden_size)				)







			def 							snake_case__(	self					:							Tuple				,  _UpperCamelCase					:							Union[str, Any]				,  _UpperCamelCase					:							List[Any]				,  _UpperCamelCase					:							Dict				,  _UpperCamelCase					:							Dict				,  _UpperCamelCase					:							List[str]				,  _UpperCamelCase					:							Union[str, Any]				,  _UpperCamelCase					:							Tuple				,  _UpperCamelCase					:							Optional[int]				,  _UpperCamelCase					:							List[Any]				,  ) ->Any:
									snake_case_  =      BioGptForCausalLM(config=__A				)
									model.to(__A				)
									model.eval()
									snake_case_  =      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 							snake_case__(	self					:							Optional[Any]				,  _UpperCamelCase					:							Any				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							List[str]				,  *_UpperCamelCase					:							List[Any]				) ->List[Any]:
									snake_case_  =      BioGptModel(config=__A				)
									model.to(__A				)
									model.eval()

									# create attention mask
									snake_case_  =      torch.ones(input_ids.shape				,  dtype=torch.long				,  device=__A				)
									snake_case_  =      self.seq_length // 2
									snake_case_  =      0

									# first forward pass
									snake_case_  =      model(__A				,  attention_mask=__A				).to_tuple()

									# create hypothetical next token and extent to next_input_ids
									snake_case_  =      ids_tensor((self.batch_size, 1)				,  config.vocab_size				)

									# change a random masked slice from input_ids
									snake_case_  =      ids_tensor((1,)				,  __A				).item() + 1
									snake_case_  =      ids_tensor((self.batch_size, 1)				,  config.vocab_size				).squeeze(-1				)
									snake_case_  =      random_other_next_tokens

									# append to next input_ids and attn_mask
									snake_case_  =      torch.cat([input_ids, next_tokens]				,  dim=-1				)
									snake_case_  =      torch.cat(
									    [attn_mask, torch.ones((attn_mask.shape[0], 1)				,  dtype=torch.long				,  device=__A				)]				,  dim=1				,  )

									# get two different outputs
									snake_case_  =      model(__A				,  attention_mask=__A				)['''last_hidden_state''']
									snake_case_  =      model(__A				,  past_key_values=__A				,  attention_mask=__A				)['''last_hidden_state''']

									# select random slice
									snake_case_  =      ids_tensor((1,)				,  output_from_past.shape[-1]				).item()
									snake_case_  =      output_from_no_past[:, -1, random_slice_idx].detach()
									snake_case_  =      output_from_past[:, 0, random_slice_idx].detach()

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







			def 							snake_case__(	self					:							Tuple				,  _UpperCamelCase					:							Any				,  _UpperCamelCase					:							Dict				,  _UpperCamelCase					:							List[Any]				,  _UpperCamelCase					:							Dict				,  _UpperCamelCase					:							Optional[Any]				,  *_UpperCamelCase					:							Optional[Any]				) ->List[str]:
									snake_case_  =      BioGptModel(config=__A				).to(__A				).eval()

									snake_case_  =      torch.ones(input_ids.shape				,  dtype=torch.long				,  device=__A				)

									# first forward pass
									snake_case_  =      model(__A				,  attention_mask=__A				,  use_cache=__A				)

									snake_case_  =      outputs.to_tuple()

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

									# append to next input_ids and
									snake_case_  =      torch.cat([input_ids, next_tokens]				,  dim=-1				)
									snake_case_  =      torch.cat([attention_mask, next_attn_mask]				,  dim=-1				)

									snake_case_  =      model(__A				,  attention_mask=__A				)['''last_hidden_state''']
									snake_case_  =      model(__A				,  attention_mask=__A				,  past_key_values=__A				)[
									    '''last_hidden_state'''
									]

									# select random slice
									snake_case_  =      ids_tensor((1,)				,  output_from_past.shape[-1]				).item()
									snake_case_  =      output_from_no_past[:, -3:, random_slice_idx].detach()
									snake_case_  =      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 							snake_case__(	self					:							List[str]				,  _UpperCamelCase					:							str				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							List[str]				,  _UpperCamelCase					:							Any				,  _UpperCamelCase					:							Any				,  *_UpperCamelCase					:							List[str]				,  _UpperCamelCase					:							Optional[int]=False				) ->List[str]:
									snake_case_  =      BioGptForCausalLM(__A				)
									model.to(__A				)
									if gradient_checkpointing:
															model.gradient_checkpointing_enable()

									snake_case_  =      model(__A				,  labels=__A				)
									self.parent.assertEqual(result.loss.shape				,  ()				)
									self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.vocab_size)				)
									result.loss.backward()







			def 							snake_case__(	self					:							int				,  _UpperCamelCase					:							Tuple				,  *_UpperCamelCase					:							int				) ->Optional[Any]:
									snake_case_  =      BioGptModel(__A				)
									snake_case_  =      model.config.initializer_range / math.sqrt(2 * model.config.num_hidden_layers				)
									for key in model.state_dict().keys():
															if "c_proj" in key and "weight" in key:
																					self.parent.assertLessEqual(abs(torch.std(model.state_dict()[key]				) - model_std				)				,  0.001				)
																					self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]				) - 0.0				)				,  0.01				)







			def 							snake_case__(	self					:							Any				,  _UpperCamelCase					:							Dict				,  _UpperCamelCase					:							int				,  _UpperCamelCase					:							List[Any]				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							int				,  *_UpperCamelCase					:							Dict				) ->List[Any]:
									snake_case_  =      self.num_labels
									snake_case_  =      BioGptForTokenClassification(__A				)
									model.to(__A				)
									model.eval()
									snake_case_  =      model(__A				,  attention_mask=__A				,  token_type_ids=__A				)
									self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.num_labels)				)







			def 							snake_case__(	self					:							str				) ->Optional[int]:
									snake_case_  =      self.prepare_config_and_inputs()
									(
									    snake_case_     
									)  =      config_and_inputs
									snake_case_  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask}
									return config, inputs_dict






@require_torch
class       snake_case_  (						__A      ,			__A      ,			__A      ,			unittest.TestCase   ):







			'''simple docstring'''

			SCREAMING_SNAKE_CASE	:  Dict		     =							(
			    (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
			    if is_torch_available()
			    else ()
			)
			SCREAMING_SNAKE_CASE	:  Tuple		     =							(BioGptForCausalLM,) if is_torch_available() else ()
			SCREAMING_SNAKE_CASE	:  Any		     =							(
			    {
			        "feature-extraction": BioGptModel,
			        "text-classification": BioGptForSequenceClassification,
			        "text-generation": BioGptForCausalLM,
			        "token-classification": BioGptForTokenClassification,
			        "zero-shot": BioGptForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			SCREAMING_SNAKE_CASE	:  int		     =							False







			def 							snake_case__(	self					:							Optional[Any]				) ->List[str]:
									snake_case_  =      BioGptModelTester(self				)
									snake_case_  =      ConfigTester(self				,  config_class=__A				,  hidden_size=3_7				)







			def 							snake_case__(	self					:							Optional[Any]				) ->Any:
									self.config_tester.run_common_tests()







			def 							snake_case__(	self					:							Union[str, Any]				) ->str:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*__A				)







			def 							snake_case__(	self					:							List[str]				) ->Union[str, Any]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									for type in ["absolute", "relative_key", "relative_key_query"]:
															snake_case_  =      type
															self.model_tester.create_and_check_model(*__A				)







			def 							snake_case__(	self					:							Any				) ->Optional[Any]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_biogpt_model_attention_mask_past(*__A				)







			def 							snake_case__(	self					:							Optional[int]				) ->str:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_forward_and_backwards(*__A				,  gradient_checkpointing=__A				)







			def 							snake_case__(	self					:							Dict				) ->Union[str, Any]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_biogpt_model_past_large_inputs(*__A				)







			def 							snake_case__(	self					:							Optional[Any]				) ->Optional[int]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_biogpt_weight_initialization(*__A				)







			def 							snake_case__(	self					:							Dict				) ->Union[str, Any]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_biogpt_for_token_classification(*__A				)







			@slow
			def 							snake_case__(	self					:							str				) ->Any:
									snake_case_  =      BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''				)
									model.to(__A				)
									snake_case_  =      BioGptTokenizer.from_pretrained('''microsoft/biogpt'''				)

									snake_case_  =      '''left'''

									# Define PAD Token = EOS Token = 50256
									snake_case_  =      tokenizer.eos_token
									snake_case_  =      model.config.eos_token_id

									# use different length sentences to test batching
									snake_case_  =      [
									    '''Hello, my dog is a little''',
									    '''Today, I''',
									]

									snake_case_  =      tokenizer(__A				,  return_tensors='''pt'''				,  padding=__A				)
									snake_case_  =      inputs['''input_ids'''].to(__A				)

									snake_case_  =      model.generate(
									    input_ids=__A				,  attention_mask=inputs['''attention_mask'''].to(__A				)				,  )

									snake_case_  =      tokenizer(sentences[0]				,  return_tensors='''pt'''				).input_ids.to(__A				)
									snake_case_  =      model.generate(input_ids=__A				)

									snake_case_  =      inputs_non_padded.shape[-1] - inputs['''attention_mask'''][-1].long().sum().cpu().item()
									snake_case_  =      tokenizer(sentences[1]				,  return_tensors='''pt'''				).input_ids.to(__A				)
									snake_case_  =      model.generate(input_ids=__A				,  max_length=model.config.max_length - num_paddings				)

									snake_case_  =      tokenizer.batch_decode(__A				,  skip_special_tokens=__A				)
									snake_case_  =      tokenizer.decode(output_non_padded[0]				,  skip_special_tokens=__A				)
									snake_case_  =      tokenizer.decode(output_padded[0]				,  skip_special_tokens=__A				)

									snake_case_  =      [
									    '''Hello, my dog is a little bit bigger than a little bit.''',
									    '''Today, I have a good idea of how to use the information''',
									]
									self.assertListEqual(__A				,  __A				)
									self.assertListEqual(__A				,  [non_padded_sentence, padded_sentence]				)







			@slow
			def 							snake_case__(	self					:							Optional[Any]				) ->Dict:
									for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															snake_case_  =      BioGptModel.from_pretrained(__A				)
															self.assertIsNotNone(__A				)







			def 							snake_case__(	self					:							Optional[int]				) ->Dict:
									snake_case_  =      self.model_tester.prepare_config_and_inputs_for_common()
									snake_case_  =      3
									snake_case_  =      input_dict['''input_ids''']
									snake_case_  =      input_ids.ne(1				).to(__A				)
									snake_case_  =      ids_tensor([self.model_tester.batch_size]				,  self.model_tester.type_sequence_label_size				)
									snake_case_  =      BioGptForSequenceClassification(__A				)
									model.to(__A				)
									model.eval()
									snake_case_  =      model(__A				,  attention_mask=__A				,  labels=__A				)
									self.assertEqual(result.logits.shape				,  (self.model_tester.batch_size, self.model_tester.num_labels)				)







			def 							snake_case__(	self					:							Union[str, Any]				) ->List[Any]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs_for_common()
									snake_case_  =      3
									snake_case_  =      '''multi_label_classification'''
									snake_case_  =      input_dict['''input_ids''']
									snake_case_  =      input_ids.ne(1				).to(__A				)
									snake_case_  =      ids_tensor(
									    [self.model_tester.batch_size, config.num_labels]				,  self.model_tester.type_sequence_label_size				).to(torch.float				)
									snake_case_  =      BioGptForSequenceClassification(__A				)
									model.to(__A				)
									model.eval()
									snake_case_  =      model(__A				,  attention_mask=__A				,  labels=__A				)
									self.assertEqual(result.logits.shape				,  (self.model_tester.batch_size, self.model_tester.num_labels)				)






@require_torch
class       snake_case_  (						unittest.TestCase   ):







			'''simple docstring'''

			@slow
			def 							snake_case__(	self					:							List[Any]				) ->List[str]:
									snake_case_  =      BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''				)
									snake_case_  =      torch.tensor([[2, 4_8_0_5, 9, 6_5_6, 2_1]]				)
									snake_case_  =      model(__A				)[0]

									snake_case_  =      4_2_3_8_4

									snake_case_  =      torch.Size((1, 5, vocab_size)				)
									self.assertEqual(output.shape				,  __A				)

									snake_case_  =      torch.tensor(
									    [[[-9.5236, -9.8918, 10.4557], [-11.0469, -9.6423, 8.1022], [-8.8664, -7.8826, 5.5325]]]				)

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







			@slow
			def 							snake_case__(	self					:							Any				) ->Dict:
									snake_case_  =      BioGptTokenizer.from_pretrained('''microsoft/biogpt'''				)
									snake_case_  =      BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''				)
									model.to(__A				)

									torch.manual_seed(0				)
									snake_case_  =      tokenizer('''COVID-19 is'''				,  return_tensors='''pt'''				).to(__A				)
									snake_case_  =      model.generate(
									    **__A				,  min_length=1_0_0				,  max_length=1_0_2_4				,  num_beams=5				,  early_stopping=__A				,  )
									snake_case_  =      tokenizer.decode(output_ids[0]				,  skip_special_tokens=__A				)

									snake_case_  =      (
									    '''COVID-19 is a global pandemic caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), the'''
									    ''' causative agent of coronavirus disease 2019 (COVID-19), which has spread to more than 200 countries and'''
									    ''' territories, including the United States (US), Canada, Australia, New Zealand, the United Kingdom (UK),'''
									    ''' and the United States of America (USA), as of March 11, 2020, with more than 800,000 confirmed cases and'''
									    ''' more than 800,000 deaths.'''
									)
									self.assertEqual(__A				,  __A				)

import string

import numpy
def 							SCREAMING_SNAKE_CASE_	(					UpperCAmelCase_	:     int			,							UpperCAmelCase_	:     int				)			->						int:
       return b if a == 0 else greatest_common_divisor(b % a			,							UpperCAmelCase_				)


class 			lowercase_		:
       __lowerCamelCase				       =						string.ascii_uppercase + string.digits
       # This cipher takes alphanumerics into account
       # i.e. a total of 36 characters

       # take x and return x % len(key_string)
       __lowerCamelCase				       =						numpy.vectorize(lambda A       : x % 3_6       )

       __lowerCamelCase				       =						numpy.vectorize(A       )


       def __init__(    self						,       __A				)						->    None:
              SCREAMING_SNAKE_CASE_							:				Union[str, Any]		=self.modulus(__A				)  # mod36 calc's on the encrypt key
              self.check_determinant()  # validate the determinant of the encryption key
              SCREAMING_SNAKE_CASE_							:				Dict		=encrypt_key.shape[0]


       def 	_snake_case				(    self						,       __A				)						->    int:
              return self.key_string.index(__A				)


       def 	_snake_case				(    self						,       __A				)						->    str:
              return self.key_string[round(__A				)]


       def 	_snake_case				(    self				)						->    None:
              SCREAMING_SNAKE_CASE_							:				List[str]		=round(numpy.linalg.det(self.encrypt_key				)				)

              if det < 0:
                     SCREAMING_SNAKE_CASE_							:				Optional[int]		=det % len(self.key_string				)

              SCREAMING_SNAKE_CASE_							:				List[Any]		=len(self.key_string				)
              if greatest_common_divisor(__A						,       len(self.key_string				)				) != 1:
                     SCREAMING_SNAKE_CASE_							:				Any		=(
                         F'determinant modular {req_l} of encryption key({det}) '
                         F'is not co prime w.r.t {req_l}.\nTry another key.'
                     )
                     raise ValueError(__A				)


       def 	_snake_case				(    self						,       __A				)						->    str:
              SCREAMING_SNAKE_CASE_							:				List[Any]		=[char for char in text.upper() if char in self.key_string]

              SCREAMING_SNAKE_CASE_							:				Optional[Any]		=chars[-1]
              while len(__A				) % self.break_key != 0:
                     chars.append(__A				)

              return "".join(__A				)


       def 	_snake_case				(    self						,       __A				)						->    str:
              SCREAMING_SNAKE_CASE_							:				Dict		=self.process_text(text.upper()				)
              SCREAMING_SNAKE_CASE_							:				Dict		=''''''

              for i in range(0						,       len(__A				) - self.break_key + 1						,       self.break_key				):
                     SCREAMING_SNAKE_CASE_							:				Any		=text[i : i + self.break_key]
                     SCREAMING_SNAKE_CASE_							:				Optional[int]		=[self.replace_letters(__A				) for char in batch]
                     SCREAMING_SNAKE_CASE_							:				Union[str, Any]		=numpy.array([vec]				).T
                     SCREAMING_SNAKE_CASE_							:				List[str]		=self.modulus(self.encrypt_key.dot(__A				)				).T.tolist()[
                         0
                     ]
                     SCREAMING_SNAKE_CASE_							:				List[Any]		=''''''.join(
                         self.replace_digits(__A				) for num in batch_encrypted				)
                     encrypted += encrypted_batch

              return encrypted


       def 	_snake_case				(    self				)						->    numpy.ndarray:
              SCREAMING_SNAKE_CASE_							:				Union[str, Any]		=round(numpy.linalg.det(self.encrypt_key				)				)

              if det < 0:
                     SCREAMING_SNAKE_CASE_							:				Optional[Any]		=det % len(self.key_string				)
              SCREAMING_SNAKE_CASE_							:				List[Any]		=None
              for i in range(len(self.key_string				)				):
                     if (det * i) % len(self.key_string				) == 1:
                            SCREAMING_SNAKE_CASE_							:				List[str]		=i
                            break

              SCREAMING_SNAKE_CASE_							:				List[str]		=(
                  det_inv
                  * numpy.linalg.det(self.encrypt_key				)
                  * numpy.linalg.inv(self.encrypt_key				)
              )

              return self.to_int(self.modulus(__A				)				)





       def 	_snake_case				(    self						,       __A				)						->    str:
              SCREAMING_SNAKE_CASE_							:				int		=self.make_decrypt_key()
              SCREAMING_SNAKE_CASE_							:				Optional[Any]		=self.process_text(text.upper()				)
              SCREAMING_SNAKE_CASE_							:				Any		=''''''

              for i in range(0						,       len(__A				) - self.break_key + 1						,       self.break_key				):
                     SCREAMING_SNAKE_CASE_							:				List[str]		=text[i : i + self.break_key]
                     SCREAMING_SNAKE_CASE_							:				Union[str, Any]		=[self.replace_letters(__A				) for char in batch]
                     SCREAMING_SNAKE_CASE_							:				Union[str, Any]		=numpy.array([vec]				).T
                     SCREAMING_SNAKE_CASE_							:				str		=self.modulus(decrypt_key.dot(__A				)				).T.tolist()[0]
                     SCREAMING_SNAKE_CASE_							:				Union[str, Any]		=''''''.join(
                         self.replace_digits(__A				) for num in batch_decrypted				)
                     decrypted += decrypted_batch

              return decrypted






def 							SCREAMING_SNAKE_CASE_	(					)			->						None:
       SCREAMING_SNAKE_CASE_							:				List[str]		=int(input('''Enter the order of the encryption key: '''				)				)
       SCREAMING_SNAKE_CASE_							:				Union[str, Any]		=[]

       print('''Enter each row of the encryption key with space separated integers'''				)
       for _ in range(UpperCAmelCase_				):
              SCREAMING_SNAKE_CASE_							:				Tuple		=[int(UpperCAmelCase_				) for x in input().split()]
              hill_matrix.append(UpperCAmelCase_				)

       SCREAMING_SNAKE_CASE_							:				Optional[int]		=HillCipher(numpy.array(UpperCAmelCase_				)				)

       print('''Would you like to encrypt or decrypt some text? (1 or 2)'''				)
       SCREAMING_SNAKE_CASE_							:				Dict		=input('''\n1. Encrypt\n2. Decrypt\n'''				)
       if option == "1":
              SCREAMING_SNAKE_CASE_							:				List[Any]		=input('''What text would you like to encrypt?: '''				)
              print('''Your encrypted text is:'''				)
              print(hc.encrypt(UpperCAmelCase_				)				)
       elif option == "2":
              SCREAMING_SNAKE_CASE_							:				Any		=input('''What text would you like to decrypt?: '''				)
              print('''Your decrypted text is:'''				)
              print(hc.decrypt(UpperCAmelCase_				)				)


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 main()
