'''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    lowerCamelCase__  :



   def __init__(    self					,      lowerCAmelCase__					,      lowerCAmelCase__=12					,      lowerCAmelCase__=7					,      lowerCAmelCase__=True					,      lowerCAmelCase__=True					,      lowerCAmelCase__=True					,      lowerCAmelCase__=99					,      lowerCAmelCase__=32					,      lowerCAmelCase__=32					,      lowerCAmelCase__=5					,      lowerCAmelCase__=4					,      lowerCAmelCase__=37					,      lowerCAmelCase__=0.1					,      lowerCAmelCase__=0.1					,      lowerCAmelCase__=512					,      lowerCAmelCase__=0.02					,      lowerCAmelCase__=0					,      lowerCAmelCase__=None					,      )				->     Optional[int]:
        """simple docstring"""





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



   def  _UpperCamelCase		(    self     )				->     Optional[Any]:
        """simple docstring"""





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

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

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

        _UpperCamelCase  :Any       =self.get_config()

        return config, input_ids, input_mask



   def  _UpperCamelCase		(    self     )				->     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  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     Tuple:
        """simple docstring"""





        _UpperCamelCase  :Tuple       =BlipTextModel(config=lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()
        with torch.no_grad():
             _UpperCamelCase  :Union[str, Any]       =model(lowerCAmelCase__					,      attention_mask=lowerCAmelCase__     )
             _UpperCamelCase  :Optional[Any]       =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  _UpperCamelCase		(    self     )				->     Dict:
        """simple docstring"""





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




@require_torch
class    lowerCamelCase__  (   __snake_case       ,				unittest.TestCase     ):
   __UpperCAmelCase           =						(BlipTextModel,) if is_torch_available() else ()
   __UpperCAmelCase           =						False
   __UpperCAmelCase           =						False
   __UpperCAmelCase           =						False



   def  _UpperCamelCase		(    self     )				->     Optional[Any]:
        """simple docstring"""





        _UpperCamelCase  :int       =BlipTextModelTester(self     )
        _UpperCamelCase  :int       =ConfigTester(self					,      config_class=lowerCAmelCase__					,      hidden_size=37     )



   def  _UpperCamelCase		(    self     )				->     int:
        """simple docstring"""





        self.config_tester.run_common_tests()



   def  _UpperCamelCase		(    self     )				->     List[str]:
        """simple docstring"""





        _UpperCamelCase  :Optional[int]       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     Tuple:
        """simple docstring"""





        pass



   def  _UpperCamelCase		(    self     )				->     Any:
        """simple docstring"""





        pass



   @unittest.skip(reason="""Blip does not use inputs_embeds"""     )
   def  _UpperCamelCase		(    self     )				->     Union[str, Any]:
        """simple docstring"""





        pass



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





        pass



   @unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""     )
   def  _UpperCamelCase		(    self     )				->     Dict:
        """simple docstring"""





        pass



   @slow
   def  _UpperCamelCase		(    self     )				->     List[str]:
        """simple docstring"""





        for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             _UpperCamelCase  :List[Any]       =BlipTextModel.from_pretrained(lowerCAmelCase__     )
             self.assertIsNotNone(lowerCAmelCase__     )




   def  _UpperCamelCase		(    self     )				->     Dict:
        """simple docstring"""





        super().test_pt_tf_model_equivalence(allow_missing_keys=lowerCAmelCase__     )
'''simple docstring'''

from __future__ import annotations

_lowerCamelCase :				Optional[int]														= """Alexander Joslin"""



def  _lowerCAmelCase				(				__a      )  ->      int:
     '''simple docstring'''







     if number <= 0:
          _UpperCamelCase  :Optional[Any]       =F'''n must be greater than 0. Got n = {number}'''
          raise ValueError(__a      )

     _UpperCamelCase  :Optional[Any]       =[number + 1] * (number + 1)

     # starting position
     _UpperCamelCase  :int       =0
     for i in range(1			,      __a      ):
          _UpperCamelCase  :List[str]       =min(table[i + 1]			,      table[i] + 1      )
          # check if out of bounds
          if i * 2 <= number:
               _UpperCamelCase  :int       =min(table[i * 2]			,      table[i] + 1      )
          # check if out of bounds
          if i * 3 <= number:
               _UpperCamelCase  :Tuple       =min(table[i * 3]			,      table[i] + 1      )
     return table[number]


if __name__ == "__main__":
      import doctest

      doctest.testmod()