


"""simple docstring"""





from timeit import timeit

snake_case__						:   Any			 = {
    '''MALAYALAM''': True,
    '''String''': False,
    '''rotor''': True,
    '''level''': True,
    '''A''': True,
    '''BB''': True,
    '''ABC''': False,
    '''amanaplanacanalpanama''': True,  # "a man a plan a canal panama"
}
# Ensure our test data is valid
assert all((key == key[::-1]) is value for key, value in test_data.items())


def    _snake_case  (  _snake_case :	str	):
      lowerCAmelCase    :		Any				=      0
      lowerCAmelCase    :		List[str]				=      len(_snake_case	) - 1
      while start_i < end_i:
            if s[start_i] == s[end_i]:
                  start_i += 1
                  end_i -= 1
            else:
                  return False
      return True


def    _snake_case  (  _snake_case :	str	):
      lowerCAmelCase    :		int				=      len(_snake_case	) // 2
      lowerCAmelCase    :		Any				=      len(_snake_case	)

      # We need to traverse till half of the length of string
      # as we can get access of the i'th last element from
      # i'th index.
      # eg: [0,1,2,3,4,5] => 4th index can be accessed
      # with the help of 1st index (i==n-i-1)
      # where n is length of string
      return all(s[i] == s[n - i - 1] for i in range(_snake_case	)	)


def    _snake_case  (  _snake_case :	str	):
      if len(_snake_case	) <= 2:
            return True
      if s[0] == s[len(_snake_case	) - 1]:
            return is_palindrome_recursive(s[1:-1]	)
      else:
            return False


def    _snake_case  (  _snake_case :	str	):
      return s == s[::-1]


def    _snake_case  (  _snake_case :	str	):
      lowerCAmelCase    :		int				=      f'''all({name}(key) is value for key, value in test_data.items())'''
      lowerCAmelCase    :		int				=      f'''from __main__ import test_data, {name}'''
      lowerCAmelCase    :		Union[str, Any]				=      500000
      lowerCAmelCase    :		Union[str, Any]				=      timeit(stmt=_snake_case       ,      setup=_snake_case       ,      number=_snake_case	)
      print(f'''{name:<35} finished {number:,} runs in {result:.5f} seconds'''	)


if __name__ == "__main__":
 for key, value in test_data.items():
  assert is_palindrome(key) is is_palindrome_recursive(key)
  assert is_palindrome(key) is is_palindrome_slice(key)
  print(f"""{key:21} {value}""")
 print('''a man a plan a canal panama''')

 # finished 500,000 runs in 0.46793 seconds
 benchmark_function('''is_palindrome_slice''')
 # finished 500,000 runs in 0.85234 seconds
 benchmark_function('''is_palindrome''')
 # finished 500,000 runs in 1.32028 seconds
 benchmark_function('''is_palindrome_recursive''')
 # finished 500,000 runs in 2.08679 seconds
 benchmark_function('''is_palindrome_traversal''')





import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

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.models.esm.modeling_esmfold import EsmForProteinFolding


class       SCREAMING_SNAKE_CASE__					:





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





    def       snake_case_				(      self):
         lowercase__    :   List[Any]      =       ids_tensor([self.batch_size, self.seq_length]						,   self.vocab_size)

         lowercase__    :   List[Any]      =       None
         if self.use_input_mask:
              lowercase__    :   Union[str, Any]      =       random_attention_mask([self.batch_size, self.seq_length])

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

         lowercase__    :   int      =       self.get_config()

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





    def       snake_case_				(      self):
         lowercase__    :   str      =       EsmConfig(
             vocab_size=33						,   hidden_size=self.hidden_size						,   pad_token_id=1						,   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						,   initializer_range=self.initializer_range						,   is_folding_model=a						,   esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}						,   )
         return config





    def       snake_case_				(      self						,   a						,   a						,   a						,   a						,   a						,   a):
         lowercase__    :   Dict      =       EsmForProteinFolding(config=a).float()
         model.to(a)
         model.eval()
         lowercase__    :   Union[str, Any]      =       model(a						,   attention_mask=a)
         lowercase__    :   Dict      =       model(a)
         lowercase__    :   int      =       model(a)

         self.parent.assertEqual(result.positions.shape						,   (8, self.batch_size, self.seq_length, 14, 3))
         self.parent.assertEqual(result.angles.shape						,   (8, self.batch_size, self.seq_length, 7, 2))





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



@require_torch
class       SCREAMING_SNAKE_CASE__					(__snake_case		,       __snake_case		,       unittest.TestCase     ):
    __lowerCamelCase						:       Dict														=     False

    __lowerCamelCase						:       Dict														=     (EsmForProteinFolding,) if is_torch_available() else ()
    __lowerCamelCase						:       Union[str, Any]														=     ()
    __lowerCamelCase						:       List[Any]														=     {} if is_torch_available() else {}
    __lowerCamelCase						:       Optional[Any]														=     False





    def       snake_case_				(      self):
         lowercase__    :   Tuple      =       EsmFoldModelTester(self)
         lowercase__    :   List[Any]      =       ConfigTester(self						,   config_class=a						,   hidden_size=37)





    def       snake_case_				(      self):
         self.config_tester.run_common_tests()





    def       snake_case_				(      self):
         lowercase__    :   Optional[int]      =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*a)





    @unittest.skip('Does not support attention outputs')
    def       snake_case_				(      self):
         pass





    @unittest.skip
    def       snake_case_				(      self):
         pass





    @unittest.skip('Esm does not support embedding resizing')
    def       snake_case_				(      self):
         pass





    @unittest.skip('Esm does not support embedding resizing')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support passing input embeds!')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not output hidden states in the normal way.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMfold does not output hidden states in the normal way.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold only has one output format.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support input chunking.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support torchscript compilation.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support torchscript compilation.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support torchscript compilation.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support data parallel.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.')
    def       snake_case_				(      self):
         pass



@require_torch
class       SCREAMING_SNAKE_CASE__					(__snake_case     ):





    @slow
    def       snake_case_				(      self):
         lowercase__    :   Dict      =       EsmForProteinFolding.from_pretrained('facebook/esmfold_v1').float()
         model.eval()
         lowercase__    :   Optional[Any]      =       torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]])
         lowercase__    :   Optional[int]      =       model(a)['positions']
         lowercase__    :   Dict      =       torch.tensor([2.5_828, 0.7_993, -10.9_334]						,   dtype=torch.floataa)
         self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]						,   a						,   atol=1e-4))

