


'''simple docstring'''






from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
		import numpy
		import tensorflow as tf

		from transformers import (
		    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    BertConfig,
		    DPRConfig,
		    TFDPRContextEncoder,
		    TFDPRQuestionEncoder,
		    TFDPRReader,
		)







class 			lowerCamelCase					:


					def __init__(					self	:  str       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Tuple=13       ,     __snake_case	:  Optional[Any]=7       ,     __snake_case	:  List[Any]=True       ,     __snake_case	:  Any=True       ,     __snake_case	:  int=True       ,     __snake_case	:  Dict=True       ,     __snake_case	:  int=99       ,     __snake_case	:  str=32       ,     __snake_case	:  Any=2       ,     __snake_case	:  Optional[Any]=4       ,     __snake_case	:  Dict=37       ,     __snake_case	:  Union[str, Any]="gelu"       ,     __snake_case	:  Dict=0.1       ,     __snake_case	:  Any=0.1       ,     __snake_case	:  Optional[Any]=5_12       ,     __snake_case	:  List[str]=16       ,     __snake_case	:  Dict=2       ,     __snake_case	:  str=0.02       ,     __snake_case	:  Tuple=3       ,     __snake_case	:  Union[str, Any]=4       ,     __snake_case	:  Tuple=None       ,     __snake_case	:  Optional[Any]=0       ,     ):





											'''simple docstring'''





											_snake_case:   Optional[Any]  					=		parent
											_snake_case:   Any  					=		batch_size
											_snake_case:   Optional[int]  					=		seq_length
											_snake_case:   Any  					=		is_training
											_snake_case:   Any  					=		use_input_mask
											_snake_case:   Union[str, Any]  					=		use_token_type_ids
											_snake_case:   Dict  					=		use_labels
											_snake_case:   List[Any]  					=		vocab_size
											_snake_case:   Union[str, Any]  					=		hidden_size
											_snake_case:   Optional[Any]  					=		num_hidden_layers
											_snake_case:   Tuple  					=		num_attention_heads
											_snake_case:   Dict  					=		intermediate_size
											_snake_case:   Tuple  					=		hidden_act
											_snake_case:   List[Any]  					=		hidden_dropout_prob
											_snake_case:   List[Any]  					=		attention_probs_dropout_prob
											_snake_case:   List[Any]  					=		max_position_embeddings
											_snake_case:   Union[str, Any]  					=		type_vocab_size
											_snake_case:   Any  					=		type_sequence_label_size
											_snake_case:   str  					=		initializer_range
											_snake_case:   List[str]  					=		num_labels
											_snake_case:   List[str]  					=		num_choices
											_snake_case:   List[Any]  					=		scope
											_snake_case:   int  					=		projection_dim


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





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

											_snake_case:   Dict  					=		None
											if self.use_input_mask:
																	# follow test_modeling_tf_ctrl.py
																	_snake_case:   Any  					=		random_attention_mask([self.batch_size, self.seq_length]       )

											_snake_case:   Tuple  					=		None
											if self.use_token_type_ids:
																	_snake_case:   Optional[int]  					=		ids_tensor([self.batch_size, self.seq_length]       ,     self.type_vocab_size       )

											_snake_case:   Optional[Any]  					=		None
											_snake_case:   str  					=		None
											_snake_case:   Tuple  					=		None
											if self.use_labels:
																	_snake_case:   List[Any]  					=		ids_tensor([self.batch_size]       ,     self.type_sequence_label_size       )
																	_snake_case:   int  					=		ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels       )
																	_snake_case:   List[str]  					=		ids_tensor([self.batch_size]       ,     self.num_choices       )

											_snake_case:   Optional[Any]  					=		BertConfig(
											    vocab_size=self.vocab_size       ,     hidden_size=self.hidden_size       ,     num_hidden_layers=self.num_hidden_layers       ,     num_attention_heads=self.num_attention_heads       ,     intermediate_size=self.intermediate_size       ,     hidden_act=self.hidden_act       ,     hidden_dropout_prob=self.hidden_dropout_prob       ,     attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,     max_position_embeddings=self.max_position_embeddings       ,     type_vocab_size=self.type_vocab_size       ,     is_decoder=lowercase_       ,     initializer_range=self.initializer_range       ,     )
											_snake_case:   List[Any]  					=		DPRConfig(projection_dim=self.projection_dim       ,     **config.to_dict()       )

											return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ,     __snake_case	:  int       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  int       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Dict       ,     __snake_case	:  List[Any]       ,     __snake_case	:  int       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		TFDPRContextEncoder(config=lowercase_       )
											_snake_case:   Union[str, Any]  					=		model(lowercase_       ,     attention_mask=lowercase_       ,     token_type_ids=lowercase_       )
											_snake_case:   str  					=		model(lowercase_       ,     token_type_ids=lowercase_       )
											_snake_case:   int  					=		model(lowercase_       )
											self.parent.assertEqual(result.pooler_output.shape       ,     (self.batch_size, self.projection_dim or self.hidden_size)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ,     __snake_case	:  List[str]       ,     __snake_case	:  Any       ,     __snake_case	:  List[Any]       ,     __snake_case	:  List[str]       ,     __snake_case	:  Tuple       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Optional[Any]       ):





											'''simple docstring'''





											_snake_case:   Dict  					=		TFDPRQuestionEncoder(config=lowercase_       )
											_snake_case:   Optional[int]  					=		model(lowercase_       ,     attention_mask=lowercase_       ,     token_type_ids=lowercase_       )
											_snake_case:   Optional[int]  					=		model(lowercase_       ,     token_type_ids=lowercase_       )
											_snake_case:   List[str]  					=		model(lowercase_       )
											self.parent.assertEqual(result.pooler_output.shape       ,     (self.batch_size, self.projection_dim or self.hidden_size)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  List[str]       ,     __snake_case	:  Tuple       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Dict       ,     __snake_case	:  int       ,     __snake_case	:  List[Any]       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		TFDPRReader(config=lowercase_       )
											_snake_case:   Any  					=		model(lowercase_       ,     attention_mask=lowercase_       )

											self.parent.assertEqual(result.start_logits.shape       ,     (self.batch_size, self.seq_length)       )
											self.parent.assertEqual(result.end_logits.shape       ,     (self.batch_size, self.seq_length)       )
											self.parent.assertEqual(result.relevance_logits.shape       ,     (self.batch_size,)       )




					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





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







@require_tf
class 			lowerCamelCase					(						snake_case__     ,							snake_case__     ,							unittest.TestCase  ):
					_SCREAMING_SNAKE_CASE							   =    (
					    (
					        TFDPRContextEncoder,
					        TFDPRQuestionEncoder,
					        TFDPRReader,
					    )
					    if is_tf_available()
					    else ()
					)
					_SCREAMING_SNAKE_CASE							   =    {"feature-extraction": TFDPRQuestionEncoder} if is_tf_available() else {}

					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





											_snake_case:   Any  					=		TFDPRModelTester(self       )
											_snake_case:   Tuple  					=		ConfigTester(self       ,     config_class=lowercase_       ,     hidden_size=37       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											self.config_tester.run_common_tests()


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[str]       ):





											'''simple docstring'''





											_snake_case:   int  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_dpr_context_encoder(*lowercase_       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											_snake_case:   Tuple  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_dpr_question_encoder(*lowercase_       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ):





											'''simple docstring'''





											_snake_case:   int  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_dpr_reader(*lowercase_       )




					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ):





											'''simple docstring'''





											for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_snake_case:   List[Any]  					=		TFDPRContextEncoder.from_pretrained(lowercase_       )
																	self.assertIsNotNone(lowercase_       )

											for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_snake_case:   List[str]  					=		TFDPRContextEncoder.from_pretrained(lowercase_       )
																	self.assertIsNotNone(lowercase_       )

											for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_snake_case:   Union[str, Any]  					=		TFDPRQuestionEncoder.from_pretrained(lowercase_       )
																	self.assertIsNotNone(lowercase_       )

											for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_snake_case:   Tuple  					=		TFDPRReader.from_pretrained(lowercase_       )
																	self.assertIsNotNone(lowercase_       )







@require_tf
class 			lowerCamelCase					(						unittest.TestCase  ):


					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ):





											'''simple docstring'''





											_snake_case:   Any  					=		TFDPRQuestionEncoder.from_pretrained('facebook/dpr-question_encoder-single-nq-base'       )

											_snake_case:   Dict  					=		tf.constant(
											    [[1_01, 75_92, 10_10, 20_03, 20_26, 38_99, 1_01_40, 10_29, 1_02]]       )  # [CLS] hello, is my dog cute? [SEP]
											_snake_case:   List[Any]  					=		model(lowercase_       )[0]  # embedding shape = (1, 768)
											# compare the actual values for a slice.
											_snake_case:   str  					=		tf.constant(
											    [
											        [
											            0.03_236_253,
											            0.12_753_335,
											            0.16_818_509,
											            0.00_279_786,
											            0.3_896_933,
											            0.24_264_945,
											            0.2_178_971,
											            -0.02_335_227,
											            -0.08_481_959,
											            -0.14_324_117,
											        ]
											    ]       )
											self.assertTrue(numpy.allclose(output[:, :10].numpy()       ,     expected_slice.numpy()       ,     atol=1e-4       )       )












'''simple docstring'''






def       lowercase_      (		lowercase__ = 50						)   ->int:
						_snake_case:   Union[str, Any]  					=		[[0] * 3 for _ in range(length + 1						)]

						for row_length in range(length + 1						):
												for tile_length in range(2				,  5						):
																		for tile_start in range(row_length - tile_length + 1						):
																								different_colour_ways_number[row_length][tile_length - 2] += (
																								    different_colour_ways_number[row_length - tile_start - tile_length][
																								        tile_length - 2
																								    ]
																								    + 1
																								)

						return sum(different_colour_ways_number[length]						)


if __name__ == "__main__":
		print(F'{solution() = }')





