



"""simple docstring"""







import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask


if is_torch_available():
 import torch

 from transformers import BlipTextModel
 from transformers.models.blip.modeling_blip import BLIP_PRETRAINED_MODEL_ARCHIVE_LIST

class       UpperCamelCase  :





     """simple docstring"""






     def __init__(					self :							List[Any]	,      _lowerCamelCase :							str	,      _lowerCamelCase :							Optional[int]=1_2	,      _lowerCamelCase :							List[str]=7	,      _lowerCamelCase :							Union[str, Any]=True	,      _lowerCamelCase :							Optional[Any]=True	,      _lowerCamelCase :							str=True	,      _lowerCamelCase :							Dict=9_9	,      _lowerCamelCase :							Optional[int]=3_2	,      _lowerCamelCase :							Optional[Any]=3_2	,      _lowerCamelCase :							int=5	,      _lowerCamelCase :							Any=4	,      _lowerCamelCase :							List[str]=3_7	,      _lowerCamelCase :							List[str]=0.1	,      _lowerCamelCase :							Dict=0.1	,      _lowerCamelCase :							Optional[int]=5_1_2	,      _lowerCamelCase :							List[Any]=0.02	,      _lowerCamelCase :							List[str]=0	,      _lowerCamelCase :							List[str]=None	,      ):
          A__				=   parent
          A__				=   batch_size
          A__				=   seq_length
          A__				=   is_training
          A__				=   use_input_mask
          A__				=   use_labels
          A__				=   vocab_size
          A__				=   hidden_size
          A__				=   projection_dim
          A__				=   num_hidden_layers
          A__				=   num_attention_heads
          A__				=   intermediate_size
          A__				=   dropout
          A__				=   attention_dropout
          A__				=   max_position_embeddings
          A__				=   initializer_range
          A__				=   scope
          A__				=   bos_token_id





     def 						A__  (					self :							Optional[Any] ):
          A__				=   ids_tensor([self.batch_size, self.seq_length]	,      self.vocab_size )

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

          if input_mask is not None:
               A__	,     A__				=   input_mask.shape
               A__				=   np.random.randint(1	,      seq_length - 1	,      size=(batch_size,) )
               for batch_idx, start_index in enumerate(_lowerCamelCase ):
                    A__				=   1
                    A__				=   0

          A__				=   self.get_config()

          return config, input_ids, input_mask





     def 						A__  (					self :							str ):
          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 						A__  (					self :							int	,      _lowerCamelCase :							Union[str, Any]	,      _lowerCamelCase :							List[str]	,      _lowerCamelCase :							str ):
          A__				=   BlipTextModel(config=_lowerCamelCase )
          model.to(_lowerCamelCase )
          model.eval()
          with torch.no_grad():
               A__				=   model(_lowerCamelCase	,      attention_mask=_lowerCamelCase )
               A__				=   model(_lowerCamelCase )
          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 						A__  (					self :							List[str] ):
          A__				=   self.prepare_config_and_inputs()
          A__	,     A__	,     A__				=   config_and_inputs
          A__				=   {'''input_ids''': input_ids, '''attention_mask''': input_mask}
          return config, inputs_dict


@require_torch
class       UpperCamelCase  (					a      , unittest.TestCase				):





     """simple docstring"""






     _lowerCamelCase					: str				   =(BlipTextModel,) if is_torch_available() else ()
     _lowerCamelCase					: List[str]				   =False
     _lowerCamelCase					: Any				   =False
     _lowerCamelCase					: Dict				   =False





     def 						A__  (					self :							List[Any] ):
          A__				=   BlipTextModelTester(self )
          A__				=   ConfigTester(self	,      config_class=_lowerCamelCase	,      hidden_size=3_7 )





     def 						A__  (					self :							Union[str, Any] ):
          self.config_tester.run_common_tests()





     def 						A__  (					self :							Optional[int] ):
          A__				=   self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*_lowerCamelCase )





     def 						A__  (					self :							Tuple ):
          pass





     def 						A__  (					self :							Union[str, Any] ):
          pass





     @unittest.skip(reason='''Blip does not use inputs_embeds''' )
     def 						A__  (					self :							List[str] ):
          pass





     @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING''' )
     def 						A__  (					self :							Optional[int] ):
          pass





     @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING''' )
     def 						A__  (					self :							Optional[int] ):
          pass





     @slow
     def 						A__  (					self :							Tuple ):
          for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               A__				=   BlipTextModel.from_pretrained(_lowerCamelCase )
               self.assertIsNotNone(_lowerCamelCase )





     def 						A__  (					self :							Union[str, Any] ):
          super().test_pt_tf_model_equivalence(allow_missing_keys=_lowerCamelCase )








"""simple docstring"""







def   a_	(			__a      ):
     if not isinstance(__a		,							__a      ):
          raise TypeError('''recursive_lucas_number accepts only integer arguments.'''      )
     if n_th_number == 0:
          return 2
     if n_th_number == 1:
          return 1

     return recursive_lucas_number(n_th_number - 1      ) + recursive_lucas_number(
         n_th_number - 2      )



def   a_	(			__a      ):
     if not isinstance(__a		,							__a      ):
          raise TypeError('''dynamic_lucas_number accepts only integer arguments.'''      )
     A__	,     A__				=   2, 1
     for _ in range(__a      ):
          A__	,     A__				=   b, a + b
     return a


if __name__ == "__main__":
 from doctest import testmod

 testmod()
 __snake_case	:				Dict  					=			int(input('Enter the number of terms in lucas series:\n').strip())
 print('Using recursive function to calculate lucas series:')
 print(' '.join(str(recursive_lucas_number(i)) for i in range(n)))
 print('\nUsing dynamic function to calculate lucas series:')
 print(' '.join(str(dynamic_lucas_number(i)) for i in range(n)))



