


"""simple docstring"""







import string

import numpy
def 					a__			(				SCREAMING_SNAKE_CASE    :    Dict				,      SCREAMING_SNAKE_CASE    :    Tuple				):


  '''simple docstring'''







  return b if a == 0 else greatest_common_divisor(b % a				,      A__				)


class       SCREAMING_SNAKE_CASE__				:
       """simple docstring"""


       a  :				Union[str, Any]   =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)
       a  :				Tuple   =numpy.vectorize(lambda lowercase				: x % 36				)

       a  :				Optional[Any]   =numpy.vectorize(__UpperCAmelCase				)

       def __init__(						self		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     int								=							self.modulus(snake_case__						)  # mod36 calc's on the encrypt key
         self.check_determinant()  # validate the determinant of the encryption key
         lowerCAmelCase     :     List[str]								=							encrypt_key.shape[0]

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         return self.key_string.index(snake_case__						)

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         return self.key_string[round(snake_case__						)]

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Tuple								=							round(numpy.linalg.det(self.encrypt_key						)						)

         if det < 0:
           lowerCAmelCase     :     List[Any]								=							det % len(self.key_string						)

         lowerCAmelCase     :     str								=							len(self.key_string						)
         if greatest_common_divisor(snake_case__		,     len(self.key_string						)						) != 1:
           lowerCAmelCase     :     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(snake_case__						)

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     List[str]								=							[char for char in text.upper() if char in self.key_string]

         lowerCAmelCase     :     Tuple								=							chars[-1]
         while len(snake_case__						) % self.break_key != 0:
           chars.append(snake_case__						)

         return "".join(snake_case__						)

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     Optional[int]								=							self.process_text(text.upper()						)
         lowerCAmelCase     :     List[Any]								=							''

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

         return encrypted

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							round(numpy.linalg.det(self.encrypt_key						)						)

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

         lowerCAmelCase     :     Any								=							(
             det_inv
             * numpy.linalg.det(self.encrypt_key						)
             * numpy.linalg.inv(self.encrypt_key						)
         )

         return self.to_int(self.modulus(snake_case__						)						)







       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     Optional[Any]								=							self.make_decrypt_key()
         lowerCAmelCase     :     Dict								=							self.process_text(text.upper()						)
         lowerCAmelCase     :     List[Any]								=							''

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

         return decrypted

def 					a__			(				):


  '''simple docstring'''







  lowerCAmelCase     :     Optional[int]								=							int(input("Enter the order of the encryption key: "				)				)
  lowerCAmelCase     :     Optional[Any]								=							[]

  print("Enter each row of the encryption key with space separated integers"				)
  for _ in range(A__				):
    lowerCAmelCase     :     Dict								=							[int(A__				) for x in input().split()]
    hill_matrix.append(A__				)

  lowerCAmelCase     :     List[str]								=							HillCipher(numpy.array(A__				)				)

  print("Would you like to encrypt or decrypt some text? (1 or 2)"				)
  lowerCAmelCase     :     str								=							input("\n1. Encrypt\n2. Decrypt\n"				)
  if option == "1":
    lowerCAmelCase     :     Any								=							input("What text would you like to encrypt?: "				)
    print("Your encrypted text is:"				)
    print(hc.encrypt(A__				)				)
  elif option == "2":
    lowerCAmelCase     :     str								=							input("What text would you like to decrypt?: "				)
    print("Your decrypted text is:"				)
    print(hc.decrypt(A__				)				)


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     main()












import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
    import tensorflow as tf

    from transformers import TensorFlowBenchmark, TensorFlowBenchmarkArguments





@require_tf
class  A__    (							unittest.TestCase	):




   """simple docstring"""



   def 							__lowercase		(					self					,  lowercase)			->						Dict:







          '''simple docstring'''

          for model_result in results.values():
                 for batch_size, sequence_length in zip(model_result['bs']					,  model_result['ss']):
                        a__						:	int =				model_result['result'][batch_size][sequence_length]
                        self.assertIsNotNone(lowercase)

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







          '''simple docstring'''

          a__						:	Tuple =				'sshleifer/tiny-gpt2'
          a__						:	str =				TensorFlowBenchmarkArguments(
              models=[MODEL_ID]					,  training=lowercase					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  eager_mode=lowercase					,  multi_process=lowercase					,  )
          a__						:	List[Any] =				TensorFlowBenchmark(lowercase)
          a__						:	Any =				benchmark.run()
          self.check_results_dict_not_empty(results.time_inference_result)
          self.check_results_dict_not_empty(results.memory_inference_result)

   def 							__lowercase		(					self)			->						Tuple:







          '''simple docstring'''

          a__						:	Optional[Any] =				'sgugger/tiny-distilbert-classification'
          a__						:	List[str] =				TensorFlowBenchmarkArguments(
              models=[MODEL_ID]					,  training=lowercase					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  multi_process=lowercase					,  only_pretrain_model=lowercase					,  )
          a__						:	str =				TensorFlowBenchmark(lowercase)
          a__						:	int =				benchmark.run()
          self.check_results_dict_not_empty(results.time_inference_result)
          self.check_results_dict_not_empty(results.memory_inference_result)

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







          '''simple docstring'''

          a__						:	Union[str, Any] =				'sshleifer/tiny-gpt2'
          a__						:	Dict =				TensorFlowBenchmarkArguments(
              models=[MODEL_ID]					,  training=lowercase					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  multi_process=lowercase					,  )
          a__						:	List[str] =				TensorFlowBenchmark(lowercase)
          a__						:	Tuple =				benchmark.run()
          self.check_results_dict_not_empty(results.time_inference_result)
          self.check_results_dict_not_empty(results.memory_inference_result)

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







          '''simple docstring'''

          a__						:	str =				'sshleifer/tiny-gpt2'
          a__						:	str =				AutoConfig.from_pretrained(lowercase)
          a__						:	Any =				TensorFlowBenchmarkArguments(
              models=[MODEL_ID]					,  training=lowercase					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  eager_mode=lowercase					,  multi_process=lowercase					,  )
          a__						:	Optional[Any] =				TensorFlowBenchmark(lowercase					,  [config])
          a__						:	Union[str, Any] =				benchmark.run()
          self.check_results_dict_not_empty(results.time_inference_result)
          self.check_results_dict_not_empty(results.memory_inference_result)

   def 							__lowercase		(					self)			->						str:







          '''simple docstring'''

          a__						:	Dict =				'sshleifer/tiny-gpt2'
          a__						:	Union[str, Any] =				AutoConfig.from_pretrained(lowercase)
          a__						:	Optional[int] =				TensorFlowBenchmarkArguments(
              models=[MODEL_ID]					,  training=lowercase					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  multi_process=lowercase					,  )
          a__						:	str =				TensorFlowBenchmark(lowercase					,  [config])
          a__						:	List[str] =				benchmark.run()
          self.check_results_dict_not_empty(results.time_inference_result)
          self.check_results_dict_not_empty(results.memory_inference_result)

   def 							__lowercase		(					self)			->						Dict:







          '''simple docstring'''

          a__						:	Optional[int] =				'sshleifer/tiny-gpt2'
          a__						:	Any =				TensorFlowBenchmarkArguments(
              models=[MODEL_ID]					,  training=lowercase					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  multi_process=lowercase					,  )
          a__						:	Tuple =				TensorFlowBenchmark(lowercase)
          a__						:	str =				benchmark.run()
          self.check_results_dict_not_empty(results.time_train_result)
          self.check_results_dict_not_empty(results.memory_train_result)

   def 							__lowercase		(					self)			->						int:







          '''simple docstring'''

          a__						:	Optional[Any] =				'sshleifer/tiny-gpt2'
          a__						:	List[Any] =				AutoConfig.from_pretrained(lowercase)
          a__						:	List[Any] =				TensorFlowBenchmarkArguments(
              models=[MODEL_ID]					,  training=lowercase					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  multi_process=lowercase					,  )
          a__						:	Optional[Any] =				TensorFlowBenchmark(lowercase					,  [config])
          a__						:	List[Any] =				benchmark.run()
          self.check_results_dict_not_empty(results.time_train_result)
          self.check_results_dict_not_empty(results.memory_train_result)

   def 							__lowercase		(					self)			->						int:







          '''simple docstring'''

          a__						:	Optional[int] =				'patrickvonplaten/t5-tiny-random'
          a__						:	Optional[int] =				AutoConfig.from_pretrained(lowercase)
          a__						:	Any =				TensorFlowBenchmarkArguments(
              models=[MODEL_ID]					,  training=lowercase					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  multi_process=lowercase					,  )
          a__						:	List[Any] =				TensorFlowBenchmark(lowercase					,  configs=[config])
          a__						:	Union[str, Any] =				benchmark.run()
          self.check_results_dict_not_empty(results.time_inference_result)
          self.check_results_dict_not_empty(results.memory_inference_result)

   @unittest.skipIf(is_tf_available() and len(tf.config.list_physical_devices('GPU')) == 0					,  'Cannot do xla on CPU.')
   def 							__lowercase		(					self)			->						List[Any]:







          '''simple docstring'''

          a__						:	Optional[int] =				'sshleifer/tiny-gpt2'
          a__						:	str =				TensorFlowBenchmarkArguments(
              models=[MODEL_ID]					,  training=lowercase					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  use_xla=lowercase					,  multi_process=lowercase					,  )
          a__						:	int =				TensorFlowBenchmark(lowercase)
          a__						:	Tuple =				benchmark.run()
          self.check_results_dict_not_empty(results.time_inference_result)
          self.check_results_dict_not_empty(results.memory_inference_result)

   def 							__lowercase		(					self)			->						Dict:







          '''simple docstring'''

          a__						:	str =				'sshleifer/tiny-gpt2'
          with tempfile.TemporaryDirectory() as tmp_dir:
                 a__						:	int =				TensorFlowBenchmarkArguments(
                     models=[MODEL_ID]					,  inference=lowercase					,  save_to_csv=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  inference_time_csv_file=os.path.join(lowercase					,  'inf_time.csv')					,  inference_memory_csv_file=os.path.join(lowercase					,  'inf_mem.csv')					,  env_info_csv_file=os.path.join(lowercase					,  'env.csv')					,  multi_process=lowercase					,  )
                 a__						:	List[str] =				TensorFlowBenchmark(lowercase)
                 benchmark.run()
                 self.assertTrue(Path(os.path.join(lowercase					,  'inf_time.csv')).exists())
                 self.assertTrue(Path(os.path.join(lowercase					,  'inf_mem.csv')).exists())
                 self.assertTrue(Path(os.path.join(lowercase					,  'env.csv')).exists())

   def 							__lowercase		(					self)			->						str:







          '''simple docstring'''

          a__						:	Union[str, Any] =				'sshleifer/tiny-gpt2'

          def _check_summary_is_not_empty(lowercase):
                 self.assertTrue(hasattr(lowercase					,  'sequential'))
                 self.assertTrue(hasattr(lowercase					,  'cumulative'))
                 self.assertTrue(hasattr(lowercase					,  'current'))
                 self.assertTrue(hasattr(lowercase					,  'total'))

          with tempfile.TemporaryDirectory() as tmp_dir:
                 a__						:	List[str] =				TensorFlowBenchmarkArguments(
                     models=[MODEL_ID]					,  inference=lowercase					,  sequence_lengths=[8]					,  batch_sizes=[1]					,  log_filename=os.path.join(lowercase					,  'log.txt')					,  log_print=lowercase					,  trace_memory_line_by_line=lowercase					,  eager_mode=lowercase					,  multi_process=lowercase					,  )
                 a__						:	List[str] =				TensorFlowBenchmark(lowercase)
                 a__						:	Any =				benchmark.run()
                 _check_summary_is_not_empty(result.inference_summary)
                 self.assertTrue(Path(os.path.join(lowercase					,  'log.txt')).exists())


