"""simple docstring"""




import inspect
import unittest
from math import floor

from transformers import CvtConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import CvtForImageClassification, CvtModel
			from transformers.models.cvt.modeling_cvt import CVT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor

class       a_      (     __lowercase			):




					def 						_SCREAMING_SNAKE_CASE						(	self						:     str     ):
							lowerCAmelCase__        =   self.config_class(**self.inputs_dict     )
							self.parent.assertTrue(hasattr(snake_case__  ,						"""embed_dim"""     )     )
							self.parent.assertTrue(hasattr(snake_case__  ,						"""num_heads"""     )     )

class       a_      :




					def __init__(	self						:     List[Any]  ,						snake_case__						:     Dict  ,						snake_case__						:     Optional[int]=13  ,						snake_case__						:     Any=64  ,						snake_case__						:     List[str]=3  ,						snake_case__						:     int=[16, 48, 96]  ,						snake_case__						:     str=[1, 3, 6]  ,						snake_case__						:     Optional[Any]=[1, 2, 10]  ,						snake_case__						:     Dict=[7, 3, 3]  ,						snake_case__						:     List[Any]=[4, 2, 2]  ,						snake_case__						:     Optional[Any]=[2, 1, 1]  ,						snake_case__						:     Tuple=[2, 2, 2]  ,						snake_case__						:     Union[str, Any]=[False, False, True]  ,						snake_case__						:     int=[0.0, 0.0, 0.0]  ,						snake_case__						:     str=0.02  ,						snake_case__						:     str=1E-12  ,						snake_case__						:     Optional[int]=True  ,						snake_case__						:     List[str]=True  ,						snake_case__						:     List[Any]=2  ,						):
							lowerCAmelCase__        =   parent
							lowerCAmelCase__        =   batch_size
							lowerCAmelCase__        =   image_size
							lowerCAmelCase__        =   patch_sizes
							lowerCAmelCase__        =   patch_stride
							lowerCAmelCase__        =   patch_padding
							lowerCAmelCase__        =   is_training
							lowerCAmelCase__        =   use_labels
							lowerCAmelCase__        =   num_labels
							lowerCAmelCase__        =   num_channels
							lowerCAmelCase__        =   embed_dim
							lowerCAmelCase__        =   num_heads
							lowerCAmelCase__        =   stride_kv
							lowerCAmelCase__        =   depth
							lowerCAmelCase__        =   cls_token
							lowerCAmelCase__        =   attention_drop_rate
							lowerCAmelCase__        =   initializer_range
							lowerCAmelCase__        =   layer_norm_eps




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[int]     ):
							lowerCAmelCase__        =   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

							lowerCAmelCase__        =   None
							if self.use_labels:
									lowerCAmelCase__        =   ids_tensor([self.batch_size]  ,						self.num_labels     )

							lowerCAmelCase__        =   self.get_config()
							return config, pixel_values, labels




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Tuple     ):
							return CvtConfig(
							    image_size=self.image_size  ,						num_labels=self.num_labels  ,						num_channels=self.num_channels  ,						embed_dim=self.embed_dim  ,						num_heads=self.num_heads  ,						patch_sizes=self.patch_sizes  ,						patch_padding=self.patch_padding  ,						patch_stride=self.patch_stride  ,						stride_kv=self.stride_kv  ,						depth=self.depth  ,						cls_token=self.cls_token  ,						attention_drop_rate=self.attention_drop_rate  ,						initializer_range=self.initializer_range  ,						)




					def 						_SCREAMING_SNAKE_CASE						(	self						:     str  ,						snake_case__						:     List[Any]  ,						snake_case__						:     Optional[Any]  ,						snake_case__						:     List[Any]     ):
							lowerCAmelCase__        =   CvtModel(config=snake_case__     )
							model.to(snake_case__     )
							model.eval()
							lowerCAmelCase__        =   model(snake_case__     )
							lowerCAmelCase__        =   (self.image_size, self.image_size)
							lowerCAmelCase__        =   image_size[0], image_size[1]
							for i in range(len(self.depth     )     ):
									lowerCAmelCase__        =   floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1     )
									lowerCAmelCase__        =   floor(((width + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1     )
							self.parent.assertEqual(result.last_hidden_state.shape  ,						(self.batch_size, self.embed_dim[-1], height, width)     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     str  ,						snake_case__						:     Tuple  ,						snake_case__						:     Optional[Any]  ,						snake_case__						:     Optional[Any]     ):
							lowerCAmelCase__        =   self.num_labels
							lowerCAmelCase__        =   CvtForImageClassification(snake_case__     )
							model.to(snake_case__     )
							model.eval()
							lowerCAmelCase__        =   model(snake_case__  ,						labels=snake_case__     )
							self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_labels)     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     str     ):
							lowerCAmelCase__        =   self.prepare_config_and_inputs()
							lowerCAmelCase__        =   config_and_inputs
							lowerCAmelCase__        =   {"pixel_values": pixel_values}
							return config, inputs_dict

@require_torch
class       a_      (     __lowercase ,		__lowercase ,		unittest.TestCase			):
					UpperCamelCase_ :	Optional[int]			=    (CvtModel, CvtForImageClassification) if is_torch_available() else ()
					UpperCamelCase_ :	Tuple			=    (
					    {"feature-extraction": CvtModel, "image-classification": CvtForImageClassification}
					    if is_torch_available()
					    else {}
					)

					UpperCamelCase_ :	Optional[int]			=    False
					UpperCamelCase_ :	List[Any]			=    False
					UpperCamelCase_ :	Any			=    False
					UpperCamelCase_ :	int			=    False
					UpperCamelCase_ :	Any			=    False




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Tuple     ):
							lowerCAmelCase__        =   CvtModelTester(self     )
							lowerCAmelCase__        =   ConfigTester(self  ,						config_class=snake_case__  ,						has_text_modality=snake_case__  ,						hidden_size=37     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[Any]     ):
							self.create_and_test_config_common_properties()
							self.config_tester.create_and_test_config_to_json_string()
							self.config_tester.create_and_test_config_to_json_file()
							self.config_tester.create_and_test_config_from_and_save_pretrained()
							self.config_tester.create_and_test_config_with_num_labels()
							self.config_tester.check_config_can_be_init_without_params()
							self.config_tester.check_config_arguments_init()




					def 						_SCREAMING_SNAKE_CASE						(	self						:     int     ):
							return




					@unittest.skip(reason="""Cvt does not output attentions"""     )
					def 						_SCREAMING_SNAKE_CASE						(	self						:     List[str]     ):
							pass




					@unittest.skip(reason="""Cvt does not use inputs_embeds"""     )
					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[Any]     ):
							pass




					@unittest.skip(reason="""Cvt does not support input and output embeddings"""     )
					def 						_SCREAMING_SNAKE_CASE						(	self						:     int     ):
							pass




					def 						_SCREAMING_SNAKE_CASE						(	self						:     List[Any]     ):
							lowerCAmelCase__        =   self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									lowerCAmelCase__        =   model_class(snake_case__     )
									lowerCAmelCase__        =   inspect.signature(model.forward     )
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									lowerCAmelCase__        =   [*signature.parameters.keys()]

									lowerCAmelCase__        =   ["pixel_values"]
									self.assertListEqual(arg_names[:1]  ,						snake_case__     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Dict     ):
							lowerCAmelCase__        =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*snake_case__     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Tuple     ):
							def check_hidden_states_output(snake_case__						:     str  ,						snake_case__						:     str  ,						snake_case__						:     List[str]     ):
									lowerCAmelCase__        =   model_class(snake_case__     )
									model.to(snake_case__     )
									model.eval()

									with torch.no_grad():
											lowerCAmelCase__        =   model(**self._prepare_for_class(snake_case__  ,						snake_case__     )     )

									lowerCAmelCase__        =   outputs.hidden_states

									lowerCAmelCase__        =   len(self.model_tester.depth     )
									self.assertEqual(len(snake_case__     )  ,						snake_case__     )

									# verify the first hidden states (first block)
									self.assertListEqual(
									    list(hidden_states[0].shape[-3:]     )  ,						[
									        self.model_tester.embed_dim[0],
									        self.model_tester.image_size // 4,
									        self.model_tester.image_size // 4,
									    ]  ,						)

							lowerCAmelCase__        =   self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									lowerCAmelCase__        =   True
									check_hidden_states_output(snake_case__  ,						snake_case__  ,						snake_case__     )

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									lowerCAmelCase__        =   True

									check_hidden_states_output(snake_case__  ,						snake_case__  ,						snake_case__     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[int]     ):
							lowerCAmelCase__        =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*snake_case__     )




					@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""     )
					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[Any]     ):
							pass




					@slow
					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[int]     ):
							for model_name in CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									lowerCAmelCase__        =   CvtModel.from_pretrained(snake_case__     )
									self.assertIsNotNone(snake_case__     )







def 							_UpperCAmelCase		(       ):





		"""simple docstring"""




		lowerCAmelCase__        =   Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""     )
		return image






@require_torch
@require_vision
class       a_      (     unittest.TestCase			):




					@cached_property
					def 						_SCREAMING_SNAKE_CASE						(	self						:     int     ):
							return AutoImageProcessor.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]     )




					@slow
					def 						_SCREAMING_SNAKE_CASE						(	self						:     Dict     ):
							lowerCAmelCase__        =   CvtForImageClassification.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]     ).to(snake_case__     )

							lowerCAmelCase__        =   self.default_image_processor
							lowerCAmelCase__        =   prepare_img()
							lowerCAmelCase__        =   image_processor(images=snake_case__  ,						return_tensors="""pt"""     ).to(snake_case__     )

							# forward pass
							with torch.no_grad():
									lowerCAmelCase__        =   model(**snake_case__     )

							# verify the logits
							lowerCAmelCase__        =   torch.Size((1, 1000)     )
							self.assertEqual(outputs.logits.shape  ,						snake_case__     )

							lowerCAmelCase__        =   torch.tensor([0.9285, 0.9015, -0.3150]     ).to(snake_case__     )

							self.assertTrue(torch.allclose(outputs.logits[0, :3]  ,						snake_case__  ,						atol=1E-4     )     )



"""simple docstring"""




def 							_UpperCAmelCase		(       lowerCamelCase__ = 50     ):





		"""simple docstring"""




		lowerCAmelCase__        =   [[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() = }")




