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


 def __init__(    self  : str			,							a__  : Optional[Any]			,							a__  : Dict=12			,							a__  : Any=7			,							a__  : int=True			,							a__  : int=True			,							a__  : Union[str, Any]=True			,							a__  : Optional[int]=99			,							a__  : List[Any]=32			,							a__  : List[Any]=32			,							a__  : Union[str, Any]=2			,							a__  : List[Any]=4			,							a__  : List[str]=37			,							a__  : Any=0.1			,							a__  : Any=0.1			,							a__  : Optional[Any]=512			,							a__  : Union[str, Any]=0.02			,							a__  : int=0			,							a__  : Any=None			,							):
  '''simple docstring'''

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


 def    _A	(    self  : int    ):
  '''simple docstring'''

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

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

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

  lowerCAmelCase__     :   int     		=	self.get_config()

  return config, input_ids, tf.convert_to_tensor(a__    )


 def    _A	(    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    _A	(    self  : Dict			,							a__  : Optional[int]			,							a__  : Tuple			,							a__  : List[str]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   int     		=	TFBlipTextModel(config=a__    )
  lowerCAmelCase__     :   Dict     		=	model(a__			,							attention_mask=a__			,							training=a__    )
  lowerCAmelCase__     :   Union[str, Any]     		=	model(a__			,							training=a__    )
  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[Any]    ):
  '''simple docstring'''

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




@require_tf
class    lowerCAmelCase       (     UpperCamelCase_    ,  unittest.TestCase  ):
 A_				:				List[str]	=			(TFBlipTextModel,) if is_tf_available() else ()
 A_				:				Union[str, Any]	=			False
 A_				:				Any	=			False
 A_				:				Optional[int]	=			False


 def    _A	(    self  : Any    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Dict     		=	BlipTextModelTester(self    )
  lowerCAmelCase__     :   Optional[int]     		=	ConfigTester(self			,							config_class=a__			,							hidden_size=37    )


 def    _A	(    self  : str    ):
  '''simple docstring'''

  self.config_tester.run_common_tests()


 def    _A	(    self  : Union[str, Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[str]     		=	self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_model(*a__    )


 def    _A	(    self  : Union[str, Any]    ):
  '''simple docstring'''

  pass


 def    _A	(    self  : Union[str, Any]    ):
  '''simple docstring'''

  pass


 @unittest.skip(reason="Blip does not use inputs_embeds"    )
 def    _A	(    self  : Optional[Any]    ):
  '''simple docstring'''

  pass


 @unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"    )
 def    _A	(    self  : Union[str, Any]    ):
  '''simple docstring'''

  pass


 @unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"    )
 def    _A	(    self  : List[str]    ):
  '''simple docstring'''

  pass


 @slow
 def    _A	(    self  : List[str]    ):
  '''simple docstring'''

  for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   lowerCAmelCase__     :   int     		=	TFBlipTextModel.from_pretrained(a__    )
   self.assertIsNotNone(a__    )


 def    _A	(    self  : int			,							a__  : Optional[int]=True    ):
  '''simple docstring'''

  super().test_pt_tf_model_equivalence(allow_missing_keys=a__    )







'''simple docstring'''

from math import factorial

snake_case									=    {str(digit): factorial(digit) for digit in range(10)}


def        UpperCAmelCase_ (  lowerCamelCase_			):







 """simple docstring"""


 if not isinstance(lowerCamelCase_      ,			lowerCamelCase_			):
  raise TypeError("Parameter number must be int"			)

 if number < 0:
  raise ValueError("Parameter number must be greater than or equal to 0"			)

 # Converts number in string to iterate on its digits and adds its factorial.
 return sum(DIGIT_FACTORIAL[digit] for digit in str(lowerCamelCase_			)			)


def        UpperCAmelCase_ (  lowerCamelCase_ = 6_0      ,			lowerCamelCase_ = 1_0_0_0_0_0_0			):







 """simple docstring"""


 if not isinstance(lowerCamelCase_      ,			lowerCamelCase_			) or not isinstance(lowerCamelCase_      ,			lowerCamelCase_			):
  raise TypeError("Parameters chain_length and number_limit must be int"			)

 if chain_length <= 0 or number_limit <= 0:
  raise ValueError(
      "Parameters chain_length and number_limit must be greater than 0"			)

 # the counter for the chains with the exact desired length
 lowerCAmelCase__     :   str     		=	0
 # the cached sizes of the previous chains
 lowerCAmelCase__     :   dict[int, int]     		=	{}

 for start_chain_element in range(1      ,			lowerCamelCase_			):
  # The temporary set will contain the elements of the chain
  lowerCAmelCase__     :   Any     		=	set()
  lowerCAmelCase__     :   int     		=	0

  # Stop computing the chain when you find a cached size, a repeating item or the
  # length is greater then the desired one.
  lowerCAmelCase__     :   Dict     		=	start_chain_element
  while (
      chain_element not in chain_sets_lengths
      and chain_element not in chain_set
      and chain_set_length <= chain_length
  ):
   chain_set.add(lowerCamelCase_			)
   chain_set_length += 1
   lowerCAmelCase__     :   Dict     		=	digit_factorial_sum(lowerCamelCase_			)

  if chain_element in chain_sets_lengths:
   chain_set_length += chain_sets_lengths[chain_element]

  lowerCAmelCase__     :   Optional[Any]     		=	chain_set_length

  # If chain contains the exact amount of elements increase the counter
  if chain_set_length == chain_length:
   chains_counter += 1

 return chains_counter


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     print(f'{solution()}')





