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 		_lowercase						:

 def __init__( self	:							List[Any]   ,      snake_case	:							Any   ,      snake_case	:							List[str]=1_2   ,      snake_case	:							Tuple=7   ,      snake_case	:							int=True   ,      snake_case	:							Optional[Any]=True   ,      snake_case	:							Any=True   ,      snake_case	:							int=9_9   ,      snake_case	:							Optional[int]=3_2   ,      snake_case	:							Optional[Any]=3_2   ,      snake_case	:							Tuple=2   ,      snake_case	:							Optional[int]=4   ,      snake_case	:							Tuple=3_7   ,      snake_case	:							Optional[Any]=0.1   ,      snake_case	:							Tuple=0.1   ,      snake_case	:							Optional[int]=5_1_2   ,      snake_case	:							Tuple=0.02   ,      snake_case	:							Dict=0   ,      snake_case	:							List[str]=None   ,      )   ->						List[str]:

  """simple docstring"""





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

 def 						SCREAMING_SNAKE_CASE__   ( self	:							List[Any]			)   ->						List[Any]:

  """simple docstring"""





  UpperCamelCase_					:						str =					ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size			)

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

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

  UpperCamelCase_					:						List[str] =					self.get_config()

  return config, input_ids, tf.convert_to_tensor(snake_case			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							str			)   ->						Dict:

  """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	:							Optional[int]   ,      snake_case	:							str   ,      snake_case	:							Any   ,      snake_case	:							Dict			)   ->						int:

  """simple docstring"""





  UpperCamelCase_					:						str =					TFBlipTextModel(config=snake_case			)
  UpperCamelCase_					:						List[Any] =					model(snake_case   ,      attention_mask=snake_case   ,      training=snake_case			)
  UpperCamelCase_					:						Optional[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	:							Dict			)   ->						Any:

  """simple docstring"""





  UpperCamelCase_					:						Tuple =					self.prepare_config_and_inputs()
  UpperCamelCase_, UpperCamelCase_, UpperCamelCase_					:						List[str] =					config_and_inputs
  UpperCamelCase_					:						Union[str, Any] =					{'input_ids': input_ids, 'attention_mask': input_mask}
  return config, inputs_dict





@require_tf
class 		_lowercase						(					snake_case_						,      unittest.TestCase       ):
 lowercase				     =   (TFBlipTextModel,) if is_tf_available() else ()
 lowercase				     =   False
 lowercase				     =   False
 lowercase				     =   False

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Any			)   ->						Dict:

  """simple docstring"""





  UpperCamelCase_					:						Optional[int] =					BlipTextModelTester(self			)
  UpperCamelCase_					:						List[Any] =					ConfigTester(self   ,      config_class=snake_case   ,      hidden_size=3_7			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Dict			)   ->						List[str]:

  """simple docstring"""





  self.config_tester.run_common_tests()

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[int]			)   ->						Any:

  """simple docstring"""





  UpperCamelCase_					:						Any =					self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_model(*snake_case			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Any			)   ->						Tuple:

  """simple docstring"""





  pass

 def 						SCREAMING_SNAKE_CASE__   ( self	:							List[Any]			)   ->						int:

  """simple docstring"""





  pass

 @unittest.skip(reason='Blip does not use inputs_embeds'			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							Dict			)   ->						List[Any]:

  """simple docstring"""





  pass

 @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[Any]			)   ->						str:

  """simple docstring"""





  pass

 @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							List[str]			)   ->						Tuple:

  """simple docstring"""





  pass

 @slow
 def 						SCREAMING_SNAKE_CASE__   ( self	:							str			)   ->						str:

  """simple docstring"""





  for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   UpperCamelCase_					:						Tuple =					TFBlipTextModel.from_pretrained(snake_case			)
   self.assertIsNotNone(snake_case			)


 def 						SCREAMING_SNAKE_CASE__   ( self	:							Tuple   ,      snake_case	:							str=True			)   ->						List[str]:

  """simple docstring"""





  super().test_pt_tf_model_equivalence(allow_missing_keys=snake_case			)




from maths.prime_check import is_prime





def    __lowercase     (						lowerCamelCase					:     int	):
 if not isinstance(lowerCamelCase  ,  lowerCamelCase	):
  UpperCamelCase_					:						List[str] =					F"Input value of [number={number}] must be an integer"
  raise TypeError(lowerCamelCase	)
 if is_prime(lowerCamelCase	) and is_prime(number + 2	):
  return number + 2
 else:
  return -1


if __name__ == "__main__":
   import doctest

   doctest.testmod()



