




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




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




	def   lowercase__   (       self     :  List[str]      ):
							__snake_case						 =   ids_tensor([self.batch_size, self.seq_length]       ,		self.vocab_size      )

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

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

							__snake_case						 =   self.get_config()

							return config, input_ids, tf.convert_to_tensor(_A      )




	def   lowercase__   (       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   lowercase__   (       self     :  List[str]       ,		__lowerCAmelCase     :  Tuple       ,		__lowerCAmelCase     :  str       ,		__lowerCAmelCase     :  Optional[Any]      ):
							__snake_case						 =   TFBlipTextModel(config=_A      )
							__snake_case						 =   model(_A       ,		attention_mask=_A       ,		training=_A      )
							__snake_case						 =   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   lowercase__   (       self     :  Tuple      ):
							__snake_case						 =   self.prepare_config_and_inputs()
							__snake_case ,       __snake_case ,       __snake_case						 =   config_and_inputs
							__snake_case						 =   {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict





@require_tf
class 						a_				(			__lowercase     ,						unittest.TestCase						):
	lowercase_       :     Dict			  =      (TFBlipTextModel,) if is_tf_available() else ()
	lowercase_       :     Any			  =      False
	lowercase_       :     List[Any]			  =      False
	lowercase_       :     List[Any]			  =      False




	def   lowercase__   (       self     :  Dict      ):
							__snake_case						 =   BlipTextModelTester(self      )
							__snake_case						 =   ConfigTester(self       ,		config_class=_A       ,		hidden_size=3_7      )




	def   lowercase__   (       self     :  Dict      ):
							self.config_tester.run_common_tests()




	def   lowercase__   (       self     :  int      ):
							__snake_case						 =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_A      )




	def   lowercase__   (       self     :  List[Any]      ):
							pass




	def   lowercase__   (       self     :  Tuple      ):
							pass




	@unittest.skip(reason='Blip does not use inputs_embeds'      )
	def   lowercase__   (       self     :  Dict      ):
							pass




	@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'      )
	def   lowercase__   (       self     :  Dict      ):
							pass




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




	@slow
	def   lowercase__   (       self     :  Optional[int]      ):
							for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													__snake_case						 =   TFBlipTextModel.from_pretrained(_A      )
													self.assertIsNotNone(_A      )




	def   lowercase__   (       self     :  int       ,		__lowerCAmelCase     :  Optional[int]=True      ):
							super().test_pt_tf_model_equivalence(allow_missing_keys=_A      )


import math
class     lowerCAmelCase_     :







							def __init__(   self      :     Tuple ,			_A      :     int=0		):  # a graph with Node 0,1,...,N-1
												_UpperCamelCase			     =     n
												_UpperCamelCase			     =     [
												    [math.inf for j in range(0 ,			_A		)] for i in range(0 ,			_A		)
												]  # adjacency matrix for weight
												_UpperCamelCase			     =     [
												    [math.inf for j in range(0 ,			_A		)] for i in range(0 ,			_A		)
												]  # dp[i][j] stores minimum distance from i to j







							def  UpperCamelCase_						(   self      :     Dict ,			_A      :     str ,			_A      :     List[str] ,			_A      :     Optional[Any]		):
												_UpperCamelCase			     =     w







							def  UpperCamelCase_						(   self      :     Optional[int]		):
												for k in range(0 ,			self.n		):
																	for i in range(0 ,			self.n		):
																						for j in range(0 ,			self.n		):
																											_UpperCamelCase			     =     min(self.dp[i][j] ,			self.dp[i][k] + self.dp[k][j]		)







							def  UpperCamelCase_						(   self      :     List[str] ,			_A      :     Optional[int] ,			_A      :     Optional[int]		):
												return self.dp[u][v]


if __name__ == "__main__":
					_lowerCAmelCase       =		Graph(5)
					graph.add_edge(0, 2, 9)
					graph.add_edge(0, 4, 10)
					graph.add_edge(1, 3, 5)
					graph.add_edge(2, 3, 7)
					graph.add_edge(3, 0, 10)
					graph.add_edge(3, 1, 2)
					graph.add_edge(3, 2, 1)
					graph.add_edge(3, 4, 6)
					graph.add_edge(4, 1, 3)
					graph.add_edge(4, 2, 4)
					graph.add_edge(4, 3, 9)
					graph.floyd_warshall()
					graph.show_min(1, 4)
					graph.show_min(0, 3)
