

"""simple docstring"""

from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
    import tensorflow as tf

    from transformers import TFBlipTextModel
    from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST






class 			__a					:





       """simple docstring"""


       def __init__(   self			,					snake_case			,					snake_case=12			,					snake_case=7			,					snake_case=True			,					snake_case=True			,					snake_case=True			,					snake_case=99			,					snake_case=32			,					snake_case=32			,					snake_case=2			,					snake_case=4			,					snake_case=37			,					snake_case=0.1			,					snake_case=0.1			,					snake_case=512			,					snake_case=0.02			,					snake_case=0			,					snake_case=None			,					):





        """simple docstring"""

        lowerCAmelCase__   :				Union[str, Any] 			=				parent
        lowerCAmelCase__   :				List[Any] 			=				batch_size
        lowerCAmelCase__   :				Union[str, Any] 			=				seq_length
        lowerCAmelCase__   :				Optional[Any] 			=				is_training
        lowerCAmelCase__   :				List[Any] 			=				use_input_mask
        lowerCAmelCase__   :				int 			=				use_labels
        lowerCAmelCase__   :				Tuple 			=				vocab_size
        lowerCAmelCase__   :				Dict 			=				hidden_size
        lowerCAmelCase__   :				Union[str, Any] 			=				projection_dim
        lowerCAmelCase__   :				Optional[Any] 			=				num_hidden_layers
        lowerCAmelCase__   :				int 			=				num_attention_heads
        lowerCAmelCase__   :				Tuple 			=				intermediate_size
        lowerCAmelCase__   :				int 			=				dropout
        lowerCAmelCase__   :				List[Any] 			=				attention_dropout
        lowerCAmelCase__   :				Dict 			=				max_position_embeddings
        lowerCAmelCase__   :				Optional[int] 			=				initializer_range
        lowerCAmelCase__   :				Optional[Any] 			=				scope
        lowerCAmelCase__   :				List[Any] 			=				bos_token_id






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Any 			=				ids_tensor([self.batch_size, self.seq_length]			,					self.vocab_size   )

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

        if input_mask is not None:
         lowerCAmelCase__   :				str 			=				input_mask.numpy()
         lowerCAmelCase__			,						lowerCAmelCase__   :				int 			=				input_mask.shape
         lowerCAmelCase__   :				Optional[int] 			=				np.random.randint(1			,					seq_length - 1			,					size=(batch_size,)   )
         for batch_idx, start_index in enumerate(snake_case   ):
          lowerCAmelCase__   :				Union[str, Any] 			=				1
          lowerCAmelCase__   :				List[str] 			=				0

        lowerCAmelCase__   :				str 			=				self.get_config()

        return config, input_ids, tf.convert_to_tensor(snake_case   )






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        return BlipTextConfig(
            vocab_size=self.vocab_size			,					hidden_size=self.hidden_size			,					projection_dim=self.projection_dim			,					num_hidden_layers=self.num_hidden_layers			,					num_attention_heads=self.num_attention_heads			,					intermediate_size=self.intermediate_size			,					dropout=self.dropout			,					attention_dropout=self.attention_dropout			,					max_position_embeddings=self.max_position_embeddings			,					initializer_range=self.initializer_range			,					bos_token_id=self.bos_token_id			,					)






       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case			,					snake_case			,					snake_case   ):





        """simple docstring"""

        lowerCAmelCase__   :				Optional[int] 			=				TFBlipTextModel(config=snake_case   )
        lowerCAmelCase__   :				int 			=				model(snake_case			,					attention_mask=snake_case			,					training=snake_case   )
        lowerCAmelCase__   :				int 			=				model(snake_case			,					training=snake_case   )
        self.parent.assertEqual(result.last_hidden_state.shape			,					(self.batch_size, self.seq_length, self.hidden_size)   )
        self.parent.assertEqual(result.pooler_output.shape			,					(self.batch_size, self.hidden_size)   )






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Optional[Any] 			=				self.prepare_config_and_inputs()
        lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__   :				List[Any] 			=				config_and_inputs
        lowerCAmelCase__   :				Any 			=				{"input_ids": input_ids, "attention_mask": input_mask}
        return config, inputs_dict






@require_tf
class 			__a					(						__magic_name__       ,	unittest.TestCase       ):





       """simple docstring"""


       __UpperCamelCase					:      Any    =						(TFBlipTextModel,) if is_tf_available() else ()
       __UpperCamelCase					:      str    =						False
       __UpperCamelCase					:      Tuple    =						False
       __UpperCamelCase					:      List[Any]    =						False






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Union[str, Any] 			=				BlipTextModelTester(self   )
        lowerCAmelCase__   :				List[Any] 			=				ConfigTester(self			,					config_class=snake_case			,					hidden_size=37   )






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        self.config_tester.run_common_tests()






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Dict 			=				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*snake_case   )






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        pass






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        pass






       @unittest.skip(reason="Blip does not use inputs_embeds"   )
       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        pass






       @unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"   )
       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        pass






       @unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"   )
       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        pass






       @slow
       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         lowerCAmelCase__   :				Union[str, Any] 			=				TFBlipTextModel.from_pretrained(snake_case   )
         self.assertIsNotNone(snake_case   )






       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case=True   ):





        """simple docstring"""

        super().test_pt_tf_model_equivalence(allow_missing_keys=snake_case   )









"""simple docstring"""

def       SCREAMING_SNAKE_CASE							( lowercase__					,					lowercase__   )			->						list:
 lowerCAmelCase__   :				List[str] 			=				len(lowercase__   )
 lowerCAmelCase__   :				Dict 			=				[]
 for i in range(len(lowercase__   ) - pat_len + 1   ):
  lowerCAmelCase__   :				Union[str, Any] 			=				True
  for j in range(lowercase__   ):
   if s[i + j] != pattern[j]:
    lowerCAmelCase__   :				int 			=				False
    break
  if match_found:
   position.append(lowercase__   )
 return position


if __name__ == "__main__":
    assert naive_pattern_search("""ABCDEFG""", """DE""") == [3]
    print(naive_pattern_search("""ABAAABCDBBABCDDEBCABC""", """ABC"""))






