


'''simple docstring'''
from __future__ import annotations

import inspect
import unittest

from transformers import ViTConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

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


if is_tf_available():
		import tensorflow as tf

		from transformers import TFViTForImageClassification, TFViTModel


if is_vision_available():
		from PIL import Image

		from transformers import ViTImageProcessor
class        lowercase     :

		"""simple docstring"""

		def __init__(		self   ,       UpperCamelCase_   ,       UpperCamelCase_=13   ,       UpperCamelCase_=30   ,       UpperCamelCase_=2   ,       UpperCamelCase_=3   ,       UpperCamelCase_=True   ,       UpperCamelCase_=True   ,       UpperCamelCase_=32   ,       UpperCamelCase_=2   ,       UpperCamelCase_=4   ,       UpperCamelCase_=37   ,       UpperCamelCase_="gelu"   ,       UpperCamelCase_=0.1   ,       UpperCamelCase_=0.1   ,       UpperCamelCase_=10   ,       UpperCamelCase_=0.02   ,       UpperCamelCase_=3   ,       UpperCamelCase_=None   ,       ):

							'''simple docstring'''


							UpperCamelCase__       :Union[str, Any]							 =			parent
							UpperCamelCase__       :Union[str, Any]							 =			batch_size
							UpperCamelCase__       :str							 =			image_size
							UpperCamelCase__       :str							 =			patch_size
							UpperCamelCase__       :Union[str, Any]							 =			num_channels
							UpperCamelCase__       :Optional[Any]							 =			is_training
							UpperCamelCase__       :str							 =			use_labels
							UpperCamelCase__       :Any							 =			hidden_size
							UpperCamelCase__       :List[str]							 =			num_hidden_layers
							UpperCamelCase__       :Dict							 =			num_attention_heads
							UpperCamelCase__       :Optional[int]							 =			intermediate_size
							UpperCamelCase__       :Any							 =			hidden_act
							UpperCamelCase__       :Optional[Any]							 =			hidden_dropout_prob
							UpperCamelCase__       :Any							 =			attention_probs_dropout_prob
							UpperCamelCase__       :Union[str, Any]							 =			type_sequence_label_size
							UpperCamelCase__       :Dict							 =			initializer_range
							UpperCamelCase__       :Optional[Any]							 =			scope

							# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
							UpperCamelCase__       :Union[str, Any]							 =			(image_size // patch_size) ** 2
							UpperCamelCase__       :List[Any]							 =			num_patches + 1




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :str							 =			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

							UpperCamelCase__       :int							 =			None
							if self.use_labels:
												UpperCamelCase__       :Optional[int]							 =			ids_tensor([self.batch_size]   ,       self.type_sequence_label_size							)

							UpperCamelCase__       :str							 =			self.get_config()

							return config, pixel_values, labels




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return ViTConfig(
							    image_size=self.image_size   ,       patch_size=self.patch_size   ,       num_channels=self.num_channels   ,       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   ,       is_decoder=UpperCamelCase_   ,       initializer_range=self.initializer_range   ,       )




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__       :Dict							 =			TFViTModel(config=UpperCamelCase_							)
							UpperCamelCase__       :Optional[Any]							 =			model(UpperCamelCase_   ,       training=UpperCamelCase_							)
							self.parent.assertEqual(result.last_hidden_state.shape   ,       (self.batch_size, self.seq_length, self.hidden_size)							)

							# Test with an image with different size than the one specified in config.
							UpperCamelCase__       :Any							 =			self.image_size // 2
							UpperCamelCase__       :Dict							 =			pixel_values[:, :, :image_size, :image_size]
							UpperCamelCase__       :Optional[Any]							 =			model(UpperCamelCase_   ,       interpolate_pos_encoding=UpperCamelCase_   ,       training=UpperCamelCase_							)
							UpperCamelCase__       :Optional[Any]							 =			(image_size // self.patch_size) ** 2 + 1
							self.parent.assertEqual(result.last_hidden_state.shape   ,       (self.batch_size, seq_length, self.hidden_size)							)




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__       :List[str]							 =			self.type_sequence_label_size
							UpperCamelCase__       :Optional[int]							 =			TFViTForImageClassification(UpperCamelCase_							)
							UpperCamelCase__       :Union[str, Any]							 =			model(UpperCamelCase_   ,       labels=UpperCamelCase_   ,       training=UpperCamelCase_							)
							self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.type_sequence_label_size)							)

							# Test with an image with different size than the one specified in config.
							UpperCamelCase__       :Optional[Any]							 =			self.image_size // 2
							UpperCamelCase__       :List[Any]							 =			pixel_values[:, :, :image_size, :image_size]
							UpperCamelCase__       :Any							 =			model(UpperCamelCase_   ,       interpolate_pos_encoding=UpperCamelCase_   ,       training=UpperCamelCase_							)
							self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.type_sequence_label_size)							)

							# test greyscale images
							UpperCamelCase__       :int							 =			1
							UpperCamelCase__       :Any							 =			TFViTForImageClassification(UpperCamelCase_							)
							UpperCamelCase__       :Any							 =			floats_tensor([self.batch_size, 1, self.image_size, self.image_size]							)
							UpperCamelCase__       :Union[str, Any]							 =			model(UpperCamelCase_							)
							self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.type_sequence_label_size)							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :List[str]							 =			self.prepare_config_and_inputs()
							UpperCamelCase__       :str							 =			config_and_inputs
							UpperCamelCase__       :int							 =			{'''pixel_values''': pixel_values}
							return config, inputs_dict



@require_tf
class        lowercase     (							A__     ,		A__     ,		unittest.TestCase ):

		"""simple docstring"""

		_a   			=    (TFViTModel, TFViTForImageClassification) if is_tf_available() else ()
		_a   			=    (
		    {'feature-extraction': TFViTModel, 'image-classification': TFViTForImageClassification}
		    if is_tf_available()
		    else {}
		)

		_a   			=    False
		_a   			=    False
		_a   			=    False




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Optional[Any]							 =			TFViTModelTester(self							)
							UpperCamelCase__       :List[Any]							 =			ConfigTester(self   ,       config_class=UpperCamelCase_   ,       has_text_modality=UpperCamelCase_   ,       hidden_size=37							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							self.config_tester.run_common_tests()




		@unittest.skip(reason='''ViT does not use inputs_embeds'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							pass




		@unittest.skip(reason='''ViT does not use inputs_embeds'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							pass




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Tuple							 =			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__       :Optional[Any]							 =			model_class(UpperCamelCase_							)
												self.assertIsInstance(model.get_input_embeddings()   ,       (tf.keras.layers.Layer)							)
												UpperCamelCase__       :Dict							 =			model.get_output_embeddings()
												self.assertTrue(x is None or isinstance(UpperCamelCase_   ,       tf.keras.layers.Layer							)							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Union[str, Any]							 =			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__       :List[str]							 =			model_class(UpperCamelCase_							)
												UpperCamelCase__       :Optional[Any]							 =			inspect.signature(model.call							)
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												UpperCamelCase__       :Optional[int]							 =			[*signature.parameters.keys()]

												UpperCamelCase__       :List[str]							 =			['''pixel_values''']
												self.assertListEqual(arg_names[:1]   ,       UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :List[str]							 =			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :str							 =			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*UpperCamelCase_							)




		@slow
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :str							 =			TFViTModel.from_pretrained('''google/vit-base-patch16-224'''							)
							self.assertIsNotNone(UpperCamelCase_							)



def       a				(      )  ->     List[Any]:



					'''simple docstring'''






					UpperCamelCase__       :Tuple							 =			Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''       )
					return image







@require_tf
@require_vision
class        lowercase     (							unittest.TestCase ):

		"""simple docstring"""

		@cached_property
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return ViTImageProcessor.from_pretrained('''google/vit-base-patch16-224'''							) if is_vision_available() else None




		@slow
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :int							 =			TFViTForImageClassification.from_pretrained('''google/vit-base-patch16-224'''							)

							UpperCamelCase__       :int							 =			self.default_image_processor
							UpperCamelCase__       :Any							 =			prepare_img()
							UpperCamelCase__       :Dict							 =			image_processor(images=UpperCamelCase_   ,       return_tensors='''tf'''							)

							# forward pass
							UpperCamelCase__       :Optional[Any]							 =			model(**UpperCamelCase_							)

							# verify the logits
							UpperCamelCase__       :Optional[Any]							 =			tf.TensorShape((1, 1000)							)
							self.assertEqual(outputs.logits.shape   ,       UpperCamelCase_							)

							UpperCamelCase__       :List[str]							 =			tf.constant([-0.2744, 0.8215, -0.0836]							)

							tf.debugging.assert_near(outputs.logits[0, :3]   ,       UpperCamelCase_   ,       atol=1e-4							)










'''simple docstring'''
from __future__ import annotations

from typing import Any


def       a				(      __a       )  ->     None:



					'''simple docstring'''






					create_state_space_tree(__a			, []			, 0       )


def       a				(      __a			, __a			, __a       )  ->     None:



					'''simple docstring'''






					if index == len(__a       ):
										print(__a       )
										return

					create_state_space_tree(__a			, __a			, index + 1       )
					current_subsequence.append(sequence[index]       )
					create_state_space_tree(__a			, __a			, index + 1       )
					current_subsequence.pop()


if __name__ == "__main__":
		__snake_case											=					[3, 1, 2, 4]
		generate_all_subsequences(seq)

		seq.clear()
		seq.extend(['''A''', '''B''', '''C'''])
		generate_all_subsequences(seq)