code: from __future__ import annotations
  
  import inspect
  import unittest
  
  from transformers import MobileViTConfig
  from transformers.file_utils import is_tf_available, is_vision_available
  from transformers.testing_utils import require_tf, slow
  
  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 numpy as np
   import tensorflow as tf
  
   from transformers import TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation, TFMobileViTModel
   from transformers.models.mobilevit.modeling_tf_mobilevit import TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  if is_vision_available():
   from PIL import Image
  
   from transformers import MobileViTImageProcessor
  
  
  
  
  class    __lowerCAmelCase  (       snake_case_						):
  
  
  
   '''simple docstring'''
  
   def 					__snake_case					(			self       :		Any  ) ->							Dict:
          _UpperCamelCase     :       str  						=  self.config_class(**self.inputs_dict  )
          self.parent.assertTrue(hasattr(lowerCamelCase       ,			'hidden_sizes'  )  )
          self.parent.assertTrue(hasattr(lowerCamelCase       ,			'neck_hidden_sizes'  )  )
          self.parent.assertTrue(hasattr(lowerCamelCase       ,			'num_attention_heads'  )  )
  
  
  
  
  class    __lowerCAmelCase  :
  
  
  
   '''simple docstring'''
  
   def __init__(			self       :		List[str]       ,			lowerCamelCase       :		List[Any]       ,			lowerCamelCase       :		int=1_3       ,			lowerCamelCase       :		Optional[int]=3_2       ,			lowerCamelCase       :		Union[str, Any]=2       ,			lowerCamelCase       :		Dict=3       ,			lowerCamelCase       :		Any=6_4_0       ,			lowerCamelCase       :		Optional[Any]=4       ,			lowerCamelCase       :		Dict="silu"       ,			lowerCamelCase       :		List[Any]=3       ,			lowerCamelCase       :		Union[str, Any]=3_2       ,			lowerCamelCase       :		List[str]=0.1       ,			lowerCamelCase       :		Any=0.1       ,			lowerCamelCase       :		str=0.1       ,			lowerCamelCase       :		Optional[int]=0.0_2       ,			lowerCamelCase       :		str=True       ,			lowerCamelCase       :		Dict=True       ,			lowerCamelCase       :		Optional[Any]=1_0       ,			lowerCamelCase       :		Any=None       ,			) ->							List[Any]:
          _UpperCamelCase     :       str  						=  parent
          _UpperCamelCase     :       int  						=  batch_size
          _UpperCamelCase     :       List[Any]  						=  image_size
          _UpperCamelCase     :       Any  						=  patch_size
          _UpperCamelCase     :       Optional[int]  						=  num_channels
          _UpperCamelCase     :       str  						=  last_hidden_size
          _UpperCamelCase     :       str  						=  num_attention_heads
          _UpperCamelCase     :       List[Any]  						=  hidden_act
          _UpperCamelCase     :       Dict  						=  conv_kernel_size
          _UpperCamelCase     :       int  						=  output_stride
          _UpperCamelCase     :       Union[str, Any]  						=  hidden_dropout_prob
          _UpperCamelCase     :       str  						=  attention_probs_dropout_prob
          _UpperCamelCase     :       Dict  						=  classifier_dropout_prob
          _UpperCamelCase     :       Any  						=  use_labels
          _UpperCamelCase     :       str  						=  is_training
          _UpperCamelCase     :       str  						=  num_labels
          _UpperCamelCase     :       Optional[Any]  						=  initializer_range
          _UpperCamelCase     :       Tuple  						=  scope
  
   def 					__snake_case					(			self       :		Optional[int]  ) ->							List[str]:
          _UpperCamelCase     :       Optional[int]  						=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )
  
          _UpperCamelCase     :       int  						=  None
          _UpperCamelCase     :       Any  						=  None
          if self.use_labels:
                 _UpperCamelCase     :       List[str]  						=  ids_tensor([self.batch_size]       ,			self.num_labels  )
                 _UpperCamelCase     :       str  						=  ids_tensor([self.batch_size, self.image_size, self.image_size]       ,			self.num_labels  )
  
          _UpperCamelCase     :       Any  						=  self.get_config()
  
          return config, pixel_values, labels, pixel_labels
  
   def 					__snake_case					(			self       :		List[Any]  ) ->							Any:
          return MobileViTConfig(
              image_size=self.image_size       ,			patch_size=self.patch_size       ,			num_channels=self.num_channels       ,			num_attention_heads=self.num_attention_heads       ,			hidden_act=self.hidden_act       ,			conv_kernel_size=self.conv_kernel_size       ,			output_stride=self.output_stride       ,			hidden_dropout_prob=self.hidden_dropout_prob       ,			attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,			classifier_dropout_prob=self.classifier_dropout_prob       ,			initializer_range=self.initializer_range       ,			)
  
   def 					__snake_case					(			self       :		List[Any]       ,			lowerCamelCase       :		List[str]       ,			lowerCamelCase       :		Dict       ,			lowerCamelCase       :		Optional[int]       ,			lowerCamelCase       :		Union[str, Any]  ) ->							Optional[Any]:
          _UpperCamelCase     :       int  						=  TFMobileViTModel(config=lowerCamelCase  )
          _UpperCamelCase     :       str  						=  model(lowerCamelCase       ,			training=lowerCamelCase  )
          _UpperCamelCase     :       List[str]  						=  self.image_size // self.output_stride
          self.parent.assertEqual(
              result.last_hidden_state.shape       ,			(self.batch_size, self.last_hidden_size, expected_height, expected_width)  )
  
   def 					__snake_case					(			self       :		Union[str, Any]       ,			lowerCamelCase       :		List[Any]       ,			lowerCamelCase       :		List[Any]       ,			lowerCamelCase       :		List[str]       ,			lowerCamelCase       :		str  ) ->							Dict:
          _UpperCamelCase     :       Optional[Any]  						=  self.num_labels
          _UpperCamelCase     :       Union[str, Any]  						=  TFMobileViTForImageClassification(lowerCamelCase  )
          _UpperCamelCase     :       int  						=  model(lowerCamelCase       ,			labels=lowerCamelCase       ,			training=lowerCamelCase  )
          self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.num_labels)  )
  
   def 					__snake_case					(			self       :		Union[str, Any]       ,			lowerCamelCase       :		List[Any]       ,			lowerCamelCase       :		Optional[Any]       ,			lowerCamelCase       :		Optional[int]       ,			lowerCamelCase       :		List[Any]  ) ->							Optional[int]:
          _UpperCamelCase     :       List[str]  						=  self.num_labels
          _UpperCamelCase     :       str  						=  TFMobileViTForSemanticSegmentation(lowerCamelCase  )
          _UpperCamelCase     :       Tuple  						=  self.image_size // self.output_stride
  
          _UpperCamelCase     :       Union[str, Any]  						=  model(lowerCamelCase       ,			training=lowerCamelCase  )
          self.parent.assertEqual(
              result.logits.shape       ,			(self.batch_size, self.num_labels, expected_height, expected_width)  )
  
          _UpperCamelCase     :       int  						=  model(lowerCamelCase       ,			labels=lowerCamelCase       ,			training=lowerCamelCase  )
          self.parent.assertEqual(
              result.logits.shape       ,			(self.batch_size, self.num_labels, expected_height, expected_width)  )
  
   def 					__snake_case					(			self       :		Optional[int]  ) ->							List[str]:
          _UpperCamelCase     :       Tuple  						=  self.prepare_config_and_inputs()
          _UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase     :       Optional[int]  						=  config_and_inputs
          _UpperCamelCase     :       str  						=  {'pixel_values': pixel_values}
          return config, inputs_dict
  
  
  
  
  @require_tf
  class    __lowerCAmelCase  (       snake_case_,	snake_case_,	unittest.TestCase						):
  
  
  
   '''simple docstring'''
   _lowerCamelCase						:	Tuple				    = (
       (TFMobileViTModel, TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation)
       if is_tf_available()
       else ()
   )
   _lowerCamelCase						:	List[str]				    = (
       {'feature-extraction': TFMobileViTModel, 'image-classification': TFMobileViTForImageClassification}
       if is_tf_available()
       else {}
   )
  
   _lowerCamelCase						:	List[Any]				    = False
   _lowerCamelCase						:	int				    = False
   _lowerCamelCase						:	Any				    = False
   _lowerCamelCase						:	Tuple				    = False
   _lowerCamelCase						:	List[Any]				    = False
  
   def 					__snake_case					(			self       :		Dict  ) ->							List[str]:
          _UpperCamelCase     :       int  						=  TFMobileViTModelTester(self  )
          _UpperCamelCase     :       List[str]  						=  TFMobileViTConfigTester(self       ,			config_class=lowerCamelCase       ,			has_text_modality=lowerCamelCase  )
  
   def 					__snake_case					(			self       :		Optional[int]  ) ->							Union[str, Any]:
          self.config_tester.run_common_tests()
  
   @unittest.skip(reason='MobileViT does not use inputs_embeds'  )
   def 					__snake_case					(			self       :		List[str]  ) ->							Any:
          pass
  
   @unittest.skip(reason='MobileViT does not support input and output embeddings'  )
   def 					__snake_case					(			self       :		Optional[int]  ) ->							int:
          pass
  
   @unittest.skip(reason='MobileViT does not output attentions'  )
   def 					__snake_case					(			self       :		List[Any]  ) ->							List[Any]:
          pass
  
   def 					__snake_case					(			self       :		Union[str, Any]  ) ->							Union[str, Any]:
          _UpperCamelCase						,      _UpperCamelCase     :       List[str]  						=  self.model_tester.prepare_config_and_inputs_for_common()
  
          for model_class in self.all_model_classes:
                 _UpperCamelCase     :       Optional[int]  						=  model_class(lowerCamelCase  )
                 _UpperCamelCase     :       List[str]  						=  inspect.signature(model.call  )
                 # signature.parameters is an OrderedDict => so arg_names order is deterministic
                 _UpperCamelCase     :       Dict  						=  [*signature.parameters.keys()]
  
                 _UpperCamelCase     :       List[str]  						=  ['pixel_values']
                 self.assertListEqual(arg_names[:1]       ,			lowerCamelCase  )
  
   def 					__snake_case					(			self       :		Any  ) ->							List[Any]:
          _UpperCamelCase     :       Optional[int]  						=  self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*lowerCamelCase  )
  
   def 					__snake_case					(			self       :		Union[str, Any]  ) ->							Optional[Any]:
          def check_hidden_states_output(lowerCamelCase       :		Optional[int]       ,			lowerCamelCase       :		int       ,			lowerCamelCase       :		Dict  ):
                 _UpperCamelCase     :       Any  						=  model_class(lowerCamelCase  )
  
                 _UpperCamelCase     :       Optional[Any]  						=  model(**self._prepare_for_class(lowerCamelCase       ,			lowerCamelCase  )  )
  
                 _UpperCamelCase     :       Optional[Any]  						=  outputs.hidden_states
  
                 _UpperCamelCase     :       Union[str, Any]  						=  5
                 self.assertEqual(len(lowerCamelCase  )       ,			lowerCamelCase  )
  
                 # MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
                 # with the width and height being successively divided by 2.
                 _UpperCamelCase     :       List[str]  						=  2
                 for i in range(len(lowerCamelCase  )  ):
                        self.assertListEqual(
                            list(hidden_states[i].shape[-2:]  )       ,			[self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]       ,			)
                        divisor *= 2
  
                 self.assertEqual(self.model_tester.output_stride       ,			divisor // 2  )
  
          _UpperCamelCase						,      _UpperCamelCase     :       Dict  						=  self.model_tester.prepare_config_and_inputs_for_common()
  
          for model_class in self.all_model_classes:
                 _UpperCamelCase     :       List[str]  						=  True
                 check_hidden_states_output(lowerCamelCase       ,			lowerCamelCase       ,			lowerCamelCase  )
  
                 # check that output_hidden_states also work using config
                 del inputs_dict["output_hidden_states"]
                 _UpperCamelCase     :       Optional[Any]  						=  True
  
                 check_hidden_states_output(lowerCamelCase       ,			lowerCamelCase       ,			lowerCamelCase  )
  
   def 					__snake_case					(			self       :		int  ) ->							Optional[int]:
          _UpperCamelCase     :       Dict  						=  self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*lowerCamelCase  )
  
   def 					__snake_case					(			self       :		List[str]  ) ->							List[Any]:
          _UpperCamelCase     :       Dict  						=  self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_semantic_segmentation(*lowerCamelCase  )
  
   @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 					__snake_case					(			self       :		Union[str, Any]  ) ->							Any:
          super().test_dataset_conversion()
  
   def 					__snake_case					(			self       :		int       ,			lowerCamelCase       :		List[str]       ,			lowerCamelCase       :		Tuple       ,			lowerCamelCase       :		Optional[Any]=2e-1       ,			lowerCamelCase       :		List[Any]=2e-1  ) ->							List[str]:
          self.assertTrue(np.allclose(lowerCamelCase       ,			lowerCamelCase       ,			atol=lowerCamelCase       ,			rtol=lowerCamelCase  )  )
  
   @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 					__snake_case					(			self       :		Any  ) ->							Dict:
          _UpperCamelCase						,      _UpperCamelCase     :       List[Any]  						=  self.model_tester.prepare_config_and_inputs_for_common()
  
          for model_class in self.all_model_classes:
                 # Since `TFMobileViTModel` cannot operate with the default `fit()` method.
                 if model_class.__name__ != "TFMobileViTModel":
                        _UpperCamelCase     :       List[str]  						=  model_class(lowerCamelCase  )
                        if getattr(lowerCamelCase       ,			'hf_compute_loss'       ,			lowerCamelCase  ):
                               super().test_keras_fit()
  
   def 					__snake_case					(			self       :		int  ) ->							Optional[Any]:
          _UpperCamelCase						,      _UpperCamelCase     :       int  						=  self.model_tester.prepare_config_and_inputs_for_common()
          for model_class in self.all_model_classes:
                 # set an ignore index to correctly test the masked loss used in
                 # `TFMobileViTForSemanticSegmentation`.
                 if model_class.__name__ != "TFMobileViTForSemanticSegmentation":
                        _UpperCamelCase     :       Optional[int]  						=  5
  
                 _UpperCamelCase     :       str  						=  model_class(lowerCamelCase  )
                 if getattr(lowerCamelCase       ,			'hf_compute_loss'       ,			lowerCamelCase  ):
                        # The number of elements in the loss should be the same as the number of elements in the label
                        _UpperCamelCase     :       int  						=  self._prepare_for_class(inputs_dict.copy()       ,			lowerCamelCase       ,			return_labels=lowerCamelCase  )
                        _UpperCamelCase     :       Optional[Any]  						=  prepared_for_class[
                            sorted(prepared_for_class.keys() - inputs_dict.keys()       ,			reverse=lowerCamelCase  )[0]
                        ]
                        _UpperCamelCase     :       Union[str, Any]  						=  added_label.shape.as_list()[:1]
  
                        # Test that model correctly compute the loss with kwargs
                        _UpperCamelCase     :       int  						=  self._prepare_for_class(inputs_dict.copy()       ,			lowerCamelCase       ,			return_labels=lowerCamelCase  )
                        _UpperCamelCase     :       Dict  						=  {'input_ids', 'pixel_values', 'input_features'}
                        _UpperCamelCase     :       Optional[int]  						=  possible_input_names.intersection(set(lowerCamelCase  )  ).pop()
                        _UpperCamelCase     :       List[str]  						=  prepared_for_class.pop(lowerCamelCase  )
  
                        _UpperCamelCase     :       Union[str, Any]  						=  model(lowerCamelCase       ,			**lowerCamelCase  )[0]
                        self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]  )
  
                        # Test that model correctly compute the loss when we mask some positions
                        _UpperCamelCase     :       Optional[Any]  						=  self._prepare_for_class(inputs_dict.copy()       ,			lowerCamelCase       ,			return_labels=lowerCamelCase  )
                        _UpperCamelCase     :       Dict  						=  {'input_ids', 'pixel_values', 'input_features'}
                        _UpperCamelCase     :       List[Any]  						=  possible_input_names.intersection(set(lowerCamelCase  )  ).pop()
                        _UpperCamelCase     :       Union[str, Any]  						=  prepared_for_class.pop(lowerCamelCase  )
                        if "labels" in prepared_for_class:
                               _UpperCamelCase     :       Optional[Any]  						=  prepared_for_class['labels'].numpy()
                               if len(labels.shape  ) > 1 and labels.shape[1] != 1:
                                      # labels[0] = -100
                                      _UpperCamelCase     :       Tuple  						=  tf.convert_to_tensor(lowerCamelCase  )
                                      _UpperCamelCase     :       List[str]  						=  model(lowerCamelCase       ,			**lowerCamelCase  )[0]
                                      self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]  )
                                      self.assertTrue(not np.any(np.isnan(loss.numpy()  )  )  )
  
                  # Test that model correctly compute the loss with a dict
                        _UpperCamelCase     :       Dict  						=  self._prepare_for_class(inputs_dict.copy()       ,			lowerCamelCase       ,			return_labels=lowerCamelCase  )
                        _UpperCamelCase     :       Tuple  						=  model(lowerCamelCase  )[0]
                        self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]  )
  
                        # Test that model correctly compute the loss with a tuple
                        _UpperCamelCase     :       Optional[Any]  						=  self._prepare_for_class(inputs_dict.copy()       ,			lowerCamelCase       ,			return_labels=lowerCamelCase  )
  
                        # Get keys that were added with the _prepare_for_class function
                        _UpperCamelCase     :       Dict  						=  prepared_for_class.keys() - inputs_dict.keys()
                        _UpperCamelCase     :       Tuple  						=  inspect.signature(model.call  ).parameters
                        _UpperCamelCase     :       Any  						=  list(signature.keys()  )
  
                        # Create a dictionary holding the location of the tensors in the tuple
                        _UpperCamelCase     :       Optional[Any]  						=  {0: input_name}
                        for label_key in label_keys:
                               _UpperCamelCase     :       Dict  						=  signature_names.index(lowerCamelCase  )
                               _UpperCamelCase     :       Dict  						=  label_key
                        _UpperCamelCase     :       str  						=  sorted(tuple_index_mapping.items()  )
                        # Initialize a list with their default values, update the values and convert to a tuple
                        _UpperCamelCase     :       List[str]  						=  []
  
                        for name in signature_names:
                               if name != "kwargs":
                                      list_input.append(signature[name].default  )
  
                        for index, value in sorted_tuple_index_mapping:
                               _UpperCamelCase     :       Dict  						=  prepared_for_class[value]
  
                        _UpperCamelCase     :       Tuple  						=  tuple(lowerCamelCase  )
  
                        # Send to model
                        _UpperCamelCase     :       Optional[int]  						=  model(tuple_input[:-1]  )[0]
  
                        self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]  )
  
   @slow
   def 					__snake_case					(			self       :		Dict  ) ->							List[str]:
          for model_name in TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 _UpperCamelCase     :       Tuple  						=  TFMobileViTModel.from_pretrained(lowerCamelCase  )
                 self.assertIsNotNone(lowerCamelCase  )
  
  
  def SCREAMING_SNAKE_CASE				(     ):
         _UpperCamelCase     :       Dict  						=  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'				)
         return image
  
  
  
  
  
  @require_tf
  class    __lowerCAmelCase  (       unittest.TestCase						):
  
  
  
   '''simple docstring'''
  
   @slow
   def 					__snake_case					(			self       :		List[Any]  ) ->							Optional[Any]:
          _UpperCamelCase     :       Optional[int]  						=  TFMobileViTForImageClassification.from_pretrained('apple/mobilevit-xx-small'  )
  
          _UpperCamelCase     :       List[str]  						=  MobileViTImageProcessor.from_pretrained('apple/mobilevit-xx-small'  )
          _UpperCamelCase     :       Tuple  						=  prepare_img()
          _UpperCamelCase     :       Union[str, Any]  						=  image_processor(images=lowerCamelCase       ,			return_tensors='tf'  )
  
          # forward pass
          _UpperCamelCase     :       List[Any]  						=  model(**lowerCamelCase       ,			training=lowerCamelCase  )
  
          # verify the logits
          _UpperCamelCase     :       Tuple  						=  tf.TensorShape((1, 1_0_0_0)  )
          self.assertEqual(outputs.logits.shape       ,			lowerCamelCase  )
  
          _UpperCamelCase     :       Optional[int]  						=  tf.constant([-1.9_3_6_4, -1.2_3_2_7, -0.4_6_5_3]  )
  
          tf.debugging.assert_near(outputs.logits[0, :3]       ,			lowerCamelCase       ,			atol=1e-4       ,			rtol=1e-04  )
  
   @slow
   def 					__snake_case					(			self       :		int  ) ->							Union[str, Any]:
          # `from_pt` will be removed
          _UpperCamelCase     :       Union[str, Any]  						=  TFMobileViTForSemanticSegmentation.from_pretrained('apple/deeplabv3-mobilevit-xx-small'  )
  
          _UpperCamelCase     :       str  						=  MobileViTImageProcessor.from_pretrained('apple/deeplabv3-mobilevit-xx-small'  )
  
          _UpperCamelCase     :       Dict  						=  prepare_img()
          _UpperCamelCase     :       Union[str, Any]  						=  image_processor(images=lowerCamelCase       ,			return_tensors='tf'  )
  
          # forward pass
          _UpperCamelCase     :       Optional[int]  						=  model(inputs.pixel_values       ,			training=lowerCamelCase  )
          _UpperCamelCase     :       Union[str, Any]  						=  outputs.logits
  
          # verify the logits
          _UpperCamelCase     :       List[str]  						=  tf.TensorShape((1, 2_1, 3_2, 3_2)  )
          self.assertEqual(logits.shape       ,			lowerCamelCase  )
  
          _UpperCamelCase     :       Tuple  						=  tf.constant(
              [
                  [[6.9_7_1_3, 6.9_7_8_6, 7.2_4_2_2], [7.2_8_9_3, 7.2_8_2_5, 7.4_4_4_6], [7.6_5_8_0, 7.8_7_9_7, 7.9_4_2_0]],
                  [[-1_0.6_8_6_9, -1_0.3_2_5_0, -1_0.3_4_7_1], [-1_0.4_2_2_8, -9.9_8_6_8, -9.7_1_3_2], [-1_1.0_4_0_5, -1_1.0_2_2_1, -1_0.7_3_1_8]],
                  [[-3.3_0_8_9, -2.8_5_3_9, -2.6_7_4_0], [-3.2_7_0_6, -2.5_6_2_1, -2.5_1_0_8], [-3.2_5_3_4, -2.6_6_1_5, -2.6_6_5_1]],
              ]  )
  
          tf.debugging.assert_near(logits[0, :3, :3, :3]       ,			lowerCamelCase       ,			rtol=1e-4       ,			atol=1e-4  )
  
  
  
  
style_context: from __future__ import annotations
  
  
  def SCREAMING_SNAKE_CASE				(     lowercase_:	int		,						lowercase_:	int		,						lowercase_:	int				):
         assert (
             c % greatest_common_divisor(lowercase_		,						lowercase_				) == 0
         )  # greatest_common_divisor(a,b) function implemented below
         ((_UpperCamelCase)						,      (_UpperCamelCase)						,      (_UpperCamelCase))     :       int  						=  extended_gcd(lowercase_		,						lowercase_				)  # extended_gcd(a,b) function implemented below
         _UpperCamelCase     :       List[Any]  						=  c / d
         return (r * x, r * y)
  
  
  def SCREAMING_SNAKE_CASE				(     lowercase_:	int		,						lowercase_:	int		,						lowercase_:	int		,						lowercase_:	int = 2				):
         ((_UpperCamelCase)						,      (_UpperCamelCase))     :       Tuple  						=  diophantine(lowercase_		,						lowercase_		,						lowercase_				)  # Initial value
         _UpperCamelCase     :       List[Any]  						=  greatest_common_divisor(lowercase_		,						lowercase_				)
         _UpperCamelCase     :       Optional[int]  						=  a // d
         _UpperCamelCase     :       Optional[Any]  						=  b // d
  
         for i in range(lowercase_				):
                _UpperCamelCase     :       Union[str, Any]  						=  xa + i * q
                _UpperCamelCase     :       List[Any]  						=  ya - i * p
                print(lowercase_		,						lowercase_				)
  
  
  def SCREAMING_SNAKE_CASE				(     lowercase_:	int		,						lowercase_:	int				):
         if a < b:
                _UpperCamelCase						,      _UpperCamelCase     :       Optional[Any]  						=  b, a
  
         while a % b != 0:
                _UpperCamelCase						,      _UpperCamelCase     :       Union[str, Any]  						=  b, a % b
  
         return b
  
  
  def SCREAMING_SNAKE_CASE				(     lowercase_:	int		,						lowercase_:	int				):
         assert a >= 0 and b >= 0
  
         if b == 0:
                _UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase     :       Optional[Any]  						=  a, 1, 0
         else:
                ((_UpperCamelCase)						,      (_UpperCamelCase)						,      (_UpperCamelCase))     :       Any  						=  extended_gcd(lowercase_		,						a % b				)
                _UpperCamelCase     :       Any  						=  q
                _UpperCamelCase     :       str  						=  p - q * (a // b)
  
         assert a % d == 0 and b % d == 0
         assert d == a * x + b * y
  
         return (d, x, y)
  
  
  if __name__ == "__main__":
   from doctest import testmod
  
   testmod(name='''diophantine''', verbose=True)
   testmod(name='''diophantine_all_soln''', verbose=True)
   testmod(name='''extended_gcd''', verbose=True)
   testmod(name='''greatest_common_divisor''', verbose=True)
  
  
  
  