



'''simple docstring'''







from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import ConvNextConfig
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 TFConvNextForImageClassification, TFConvNextModel


if is_vision_available():
							from PIL import Image

							from transformers import ConvNextImageProcessor




class 				__lowerCAmelCase:






			def __init__(   self  :							List[Any]      ,       SCREAMING_SNAKE_CASE  :							Optional[int]      ,       SCREAMING_SNAKE_CASE  :							Tuple=13      ,       SCREAMING_SNAKE_CASE  :							Tuple=32      ,       SCREAMING_SNAKE_CASE  :							List[Any]=3      ,       SCREAMING_SNAKE_CASE  :							Union[str, Any]=4      ,       SCREAMING_SNAKE_CASE  :							Tuple=[10, 20, 30, 40]      ,       SCREAMING_SNAKE_CASE  :							Tuple=[2, 2, 3, 2]      ,       SCREAMING_SNAKE_CASE  :							Optional[Any]=True      ,       SCREAMING_SNAKE_CASE  :							Dict=True      ,       SCREAMING_SNAKE_CASE  :							Optional[int]=37      ,       SCREAMING_SNAKE_CASE  :							List[Any]="gelu"      ,       SCREAMING_SNAKE_CASE  :							int=10      ,       SCREAMING_SNAKE_CASE  :							Optional[int]=0.02      ,       SCREAMING_SNAKE_CASE  :							List[Any]=3      ,       SCREAMING_SNAKE_CASE  :							Union[str, Any]=None      ,       ):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Any										=      parent
					SCREAMING_SNAKE_CASE_						:List[Any]										=      batch_size
					SCREAMING_SNAKE_CASE_						:int										=      image_size
					SCREAMING_SNAKE_CASE_						:Optional[int]										=      num_channels
					SCREAMING_SNAKE_CASE_						:Optional[Any]										=      num_stages
					SCREAMING_SNAKE_CASE_						:Dict										=      hidden_sizes
					SCREAMING_SNAKE_CASE_						:Any										=      depths
					SCREAMING_SNAKE_CASE_						:Optional[Any]										=      is_training
					SCREAMING_SNAKE_CASE_						:List[Any]										=      use_labels
					SCREAMING_SNAKE_CASE_						:Tuple										=      intermediate_size
					SCREAMING_SNAKE_CASE_						:Any										=      hidden_act
					SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      type_sequence_label_size
					SCREAMING_SNAKE_CASE_						:List[Any]										=      initializer_range
					SCREAMING_SNAKE_CASE_						:Optional[int]										=      scope






			def 				_lowercase	(   self  :							Optional[int]	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Dict										=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

					SCREAMING_SNAKE_CASE_						:List[str]										=      None
					if self.use_labels:
							SCREAMING_SNAKE_CASE_						:str										=      ids_tensor([self.batch_size]      ,       self.type_sequence_label_size	)

					SCREAMING_SNAKE_CASE_						:str										=      self.get_config()

					return config, pixel_values, labels






			def 				_lowercase	(   self  :							List[str]	):




					"""simple docstring"""







					return ConvNextConfig(
					    num_channels=self.num_channels      ,       hidden_sizes=self.hidden_sizes      ,       depths=self.depths      ,       num_stages=self.num_stages      ,       hidden_act=self.hidden_act      ,       is_decoder=snake_case__      ,       initializer_range=self.initializer_range      ,       )






			def 				_lowercase	(   self  :							Optional[int]      ,       SCREAMING_SNAKE_CASE  :							List[Any]      ,       SCREAMING_SNAKE_CASE  :							int      ,       SCREAMING_SNAKE_CASE  :							Any	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Optional[Any]										=      TFConvNextModel(config=snake_case__	)
					SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      model(snake_case__      ,       training=snake_case__	)
					# expected last hidden states: B, C, H // 32, W // 32
					self.parent.assertEqual(
					    result.last_hidden_state.shape      ,       (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)      ,       )






			def 				_lowercase	(   self  :							Dict      ,       SCREAMING_SNAKE_CASE  :							int      ,       SCREAMING_SNAKE_CASE  :							Union[str, Any]      ,       SCREAMING_SNAKE_CASE  :							Optional[int]	):




					"""simple docstring"""







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






			def 				_lowercase	(   self  :							Dict	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      self.prepare_config_and_inputs()
					SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:Optional[int]										=      config_and_inputs
					SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      {'pixel_values': pixel_values}
					return config, inputs_dict




@require_tf
class 				__lowerCAmelCase(							lowercase_		,			lowercase_		,			unittest.TestCase      ):
			__snake_case  :		List[str]		=      (TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
			__snake_case  :		Any		=      (
			    {'feature-extraction': TFConvNextModel, 'image-classification': TFConvNextForImageClassification}
			    if is_tf_available()
			    else {}
			)

			__snake_case  :		int		=      False
			__snake_case  :		List[str]		=      False
			__snake_case  :		Optional[Any]		=      False
			__snake_case  :		List[str]		=      False
			__snake_case  :		List[Any]		=      False






			def 				_lowercase	(   self  :							str	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:str										=      TFConvNextModelTester(self	)
					SCREAMING_SNAKE_CASE_						:Any										=      ConfigTester(
					    self      ,       config_class=snake_case__      ,       has_text_modality=snake_case__      ,       hidden_size=37      ,       )






			@unittest.skip(reason='ConvNext does not use inputs_embeds'	)
			def 				_lowercase	(   self  :							Tuple	):




					"""simple docstring"""







					pass






			@unittest.skipIf(
			    not is_tf_available() or len(tf.config.list_physical_devices('GPU'	)	) == 0      ,       reason='TF does not support backprop for grouped convolutions on CPU.'      ,       )
			@slow
			def 				_lowercase	(   self  :							Optional[int]	):




					"""simple docstring"""







					super().test_keras_fit()






			@unittest.skip(reason='ConvNext does not support input and output embeddings'	)
			def 				_lowercase	(   self  :							Dict	):




					"""simple docstring"""







					pass






			def 				_lowercase	(   self  :							List[str]	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:List[Any]										=      self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
							SCREAMING_SNAKE_CASE_						:int										=      model_class(snake_case__	)
							SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      inspect.signature(model.call	)
							# signature.parameters is an OrderedDict => so arg_names order is deterministic
							SCREAMING_SNAKE_CASE_						:Any										=      [*signature.parameters.keys()]

							SCREAMING_SNAKE_CASE_						:Dict										=      ['pixel_values']
							self.assertListEqual(arg_names[:1]      ,       snake_case__	)






			def 				_lowercase	(   self  :							Optional[int]	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Any										=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*snake_case__	)






			@unittest.skipIf(
			    not is_tf_available() or len(tf.config.list_physical_devices('GPU'	)	) == 0      ,       reason='TF does not support backprop for grouped convolutions on CPU.'      ,       )
			def 				_lowercase	(   self  :							List[Any]	):




					"""simple docstring"""







					super().test_dataset_conversion()






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




					"""simple docstring"""







					def check_hidden_states_output(SCREAMING_SNAKE_CASE  :							List[str]      ,       SCREAMING_SNAKE_CASE  :							Optional[int]      ,       SCREAMING_SNAKE_CASE  :							int	):
							SCREAMING_SNAKE_CASE_						:Optional[int]										=      model_class(snake_case__	)

							SCREAMING_SNAKE_CASE_						:Any										=      model(**self._prepare_for_class(snake_case__      ,       snake_case__	)	)
							SCREAMING_SNAKE_CASE_						:Dict										=      outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

							SCREAMING_SNAKE_CASE_						:Dict										=      self.model_tester.num_stages
							self.assertEqual(len(snake_case__	)      ,       expected_num_stages + 1	)

							# ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
							self.assertListEqual(
							    list(hidden_states[0].shape[-2:]	)      ,       [self.model_tester.image_size // 4, self.model_tester.image_size // 4]      ,       )

					SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:List[str]										=      self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
							SCREAMING_SNAKE_CASE_						:Dict										=      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"]
							SCREAMING_SNAKE_CASE_						:Optional[int]										=      True

							check_hidden_states_output(snake_case__      ,       snake_case__      ,       snake_case__	)






			def 				_lowercase	(   self  :							Optional[int]	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:Tuple										=      self.model_tester.prepare_config_and_inputs_for_common()

					def check_equivalence(SCREAMING_SNAKE_CASE  :							int      ,       SCREAMING_SNAKE_CASE  :							List[str]      ,       SCREAMING_SNAKE_CASE  :							List[str]      ,       SCREAMING_SNAKE_CASE  :							Any={}	):
							SCREAMING_SNAKE_CASE_						:Dict										=      model(snake_case__      ,       return_dict=snake_case__      ,       **snake_case__	)
							SCREAMING_SNAKE_CASE_						:List[str]										=      model(snake_case__      ,       return_dict=snake_case__      ,       **snake_case__	).to_tuple()

							def recursive_check(SCREAMING_SNAKE_CASE  :							List[str]      ,       SCREAMING_SNAKE_CASE  :							Dict	):
									if isinstance(snake_case__      ,       (List, Tuple)	):
											for tuple_iterable_value, dict_iterable_value in zip(snake_case__      ,       snake_case__	):
													recursive_check(snake_case__      ,       snake_case__	)
									elif tuple_object is None:
											return
									else:
											self.assertTrue(
											    all(tf.equal(snake_case__      ,       snake_case__	)	)      ,       msg=(
											        'Tuple and dict output are not equal. Difference:'
											        f' {tf.math.reduce_max(tf.abs(tuple_object - dict_object	)	)}'
											    )      ,       )

									recursive_check(snake_case__      ,       snake_case__	)

					for model_class in self.all_model_classes:
							SCREAMING_SNAKE_CASE_						:int										=      model_class(snake_case__	)

							SCREAMING_SNAKE_CASE_						:int										=      self._prepare_for_class(snake_case__      ,       snake_case__	)
							SCREAMING_SNAKE_CASE_						:List[str]										=      self._prepare_for_class(snake_case__      ,       snake_case__	)
							check_equivalence(snake_case__      ,       snake_case__      ,       snake_case__	)

							SCREAMING_SNAKE_CASE_						:Optional[Any]										=      self._prepare_for_class(snake_case__      ,       snake_case__      ,       return_labels=snake_case__	)
							SCREAMING_SNAKE_CASE_						:int										=      self._prepare_for_class(snake_case__      ,       snake_case__      ,       return_labels=snake_case__	)
							check_equivalence(snake_case__      ,       snake_case__      ,       snake_case__	)

							SCREAMING_SNAKE_CASE_						:Dict										=      self._prepare_for_class(snake_case__      ,       snake_case__	)
							SCREAMING_SNAKE_CASE_						:Optional[int]										=      self._prepare_for_class(snake_case__      ,       snake_case__	)
							check_equivalence(snake_case__      ,       snake_case__      ,       snake_case__      ,       {'output_hidden_states': True}	)

							SCREAMING_SNAKE_CASE_						:int										=      self._prepare_for_class(snake_case__      ,       snake_case__      ,       return_labels=snake_case__	)
							SCREAMING_SNAKE_CASE_						:str										=      self._prepare_for_class(snake_case__      ,       snake_case__      ,       return_labels=snake_case__	)
							check_equivalence(snake_case__      ,       snake_case__      ,       snake_case__      ,       {'output_hidden_states': True}	)






			def 				_lowercase	(   self  :							Tuple	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_classification(*snake_case__	)






			@slow
			def 				_lowercase	(   self  :							int	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:int										=      TFConvNextModel.from_pretrained('facebook/convnext-tiny-224'	)
					self.assertIsNotNone(snake_case__	)







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





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






			@cached_property
			def 				_lowercase	(   self  :							Optional[int]	):




					"""simple docstring"""







					return ConvNextImageProcessor.from_pretrained('facebook/convnext-tiny-224'	) if is_vision_available() else None






			@slow
			def 				_lowercase	(   self  :							Optional[Any]	):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Tuple										=      TFConvNextForImageClassification.from_pretrained('facebook/convnext-tiny-224'	)

					SCREAMING_SNAKE_CASE_						:Optional[Any]										=      self.default_image_processor
					SCREAMING_SNAKE_CASE_						:List[str]										=      prepare_img()
					SCREAMING_SNAKE_CASE_						:Optional[int]										=      image_processor(images=snake_case__      ,       return_tensors='tf'	)

					# forward pass
					SCREAMING_SNAKE_CASE_						:Any										=      model(**snake_case__	)

					# verify the logits
					SCREAMING_SNAKE_CASE_						:Dict										=      tf.TensorShape((1, 1_000)	)
					self.assertEqual(outputs.logits.shape      ,       snake_case__	)

					SCREAMING_SNAKE_CASE_						:Tuple										=      tf.constant([-0.02_60, -0.47_39, 0.19_11]	)

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








from typing import Literal

lowerCamelCase					    =	'''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''
def 							UpperCAmelCase   ( _lowercase,   _lowercase,   _lowercase   ):


    '''simple docstring'''



    _lowercase     			=						LETTERS if mode == 'decrypt' else key
    _lowercase     			=						key if mode == 'decrypt' else LETTERS
    _lowercase     			=						''
    # loop through each symbol in the message
    for symbol in message:
        if symbol.upper() in chars_a:
            # encrypt/decrypt the symbol
            _lowercase     			=						chars_a.find(symbol.upper()   )
            if symbol.isupper():
                translated += chars_b[sym_index].upper()
            else:
                translated += chars_b[sym_index].lower()
        else:
            # symbol is not in LETTERS, just add it
            translated += symbol
    return translated
def 							UpperCAmelCase   ( _lowercase,   _lowercase   ):


    '''simple docstring'''



    return translate_message(_lowercase,   _lowercase,   'encrypt'   )
def 							UpperCAmelCase   ( _lowercase,   _lowercase   ):


    '''simple docstring'''



    return translate_message(_lowercase,   _lowercase,   'decrypt'   )
def 							UpperCAmelCase   ( ):


    '''simple docstring'''



    _lowercase     			=						'Hello World'
    _lowercase     			=						'QWERTYUIOPASDFGHJKLZXCVBNM'
    _lowercase     			=						'decrypt'  # set to 'encrypt' or 'decrypt'

    if mode == "encrypt":
        _lowercase     			=						encrypt_message(_lowercase,   _lowercase   )
    elif mode == "decrypt":
        _lowercase     			=						decrypt_message(_lowercase,   _lowercase   )
    print(f'''Using the key {key}, the {mode}ed message is: {translated}'''   )


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   main()
