






import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VivitConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
  import torch
  from torch import nn

  from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VivitForVideoClassification, VivitModel
  from transformers.models.vivit.modeling_vivit import VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from transformers import VivitImageProcessor
class 							A_      :






 '''simple docstring'''




 def __init__(		self							,					_A							,					_A=2							,					_A=True							,					_A=True							,					_A=10							,					_A=10							,					_A=8							,					_A=[2, 4, 4]							,					_A=3							,					_A=768							,					_A=5							,					_A=4							,					_A=37							,					_A="gelu_fast"							,					_A=0.0							,					_A=0.0							,					_A=0.02							,					_A=1e-06							,					_A=True							,					_A=None							,					)	->						List[str]:

     """simple docstring"""



     _UpperCAmelCase			: Optional[int]     					=			parent
     _UpperCAmelCase			: List[str]     					=			batch_size
     _UpperCAmelCase			: int     					=			is_training
     _UpperCAmelCase			: int     					=			use_labels
     _UpperCAmelCase			: Union[str, Any]     					=			num_labels
     _UpperCAmelCase			: Union[str, Any]     					=			image_size
     _UpperCAmelCase			: Any     					=			num_frames
     _UpperCAmelCase			: Union[str, Any]     					=			tubelet_size
     _UpperCAmelCase			: int     					=			num_channels
     _UpperCAmelCase			: Any     					=			hidden_size
     _UpperCAmelCase			: Dict     					=			num_hidden_layers
     _UpperCAmelCase			: List[Any]     					=			num_attention_heads
     _UpperCAmelCase			: Dict     					=			intermediate_size
     _UpperCAmelCase			: List[str]     					=			hidden_act
     _UpperCAmelCase			: Optional[Any]     					=			hidden_dropout_prob
     _UpperCAmelCase			: List[Any]     					=			attention_probs_dropout_prob
     _UpperCAmelCase			: Optional[int]     					=			initializer_range
     _UpperCAmelCase			: Dict     					=			layer_norm_eps
     _UpperCAmelCase			: Any     					=			qkv_bias
     _UpperCAmelCase			: Union[str, Any]     					=			scope

     _UpperCAmelCase			: Union[str, Any]     					=			(
         (self.image_size // self.tubelet_size[2])
         * (self.image_size // self.tubelet_size[1])
         * (self.num_frames // self.tubelet_size[0])
     ) + 1  # CLS token


 def 	snake_case__			(		self)	->						Tuple:

     """simple docstring"""



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

     _UpperCAmelCase			: int     					=			None
     if self.use_labels:
         _UpperCAmelCase			: Any     					=			ids_tensor([self.batch_size]							,					self.num_labels)

     _UpperCAmelCase			: Tuple     					=			self.get_config()

     return config, pixel_values, labels


 def 	snake_case__			(		self)	->						Optional[Any]:

     """simple docstring"""



     _UpperCAmelCase			: Any     					=			VivitConfig(
         num_frames=self.num_frames							,					image_size=self.image_size							,					tubelet_size=self.tubelet_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							,					initializer_range=self.initializer_range							,					layer_norm_eps=self.layer_norm_eps							,					qkv_bias=self.qkv_bias							,					)
     _UpperCAmelCase			: Optional[Any]     					=			self.num_labels
     return config


 def 	snake_case__			(		self							,					_A							,					_A							,					_A)	->						List[Any]:

     """simple docstring"""



     _UpperCAmelCase			: Dict     					=			VivitModel(config=_A)
     model.to(_A)
     model.eval()
     _UpperCAmelCase			: Any     					=			model(_A)
     self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.hidden_size))


 def 	snake_case__			(		self							,					_A							,					_A							,					_A)	->						Union[str, Any]:

     """simple docstring"""



     _UpperCAmelCase			: Optional[Any]     					=			VivitForVideoClassification(_A)
     model.to(_A)
     model.eval()

     _UpperCAmelCase			: List[Any]     					=			model(_A)

     # verify the logits shape
     _UpperCAmelCase			: Tuple     					=			torch.Size((self.batch_size, self.num_labels))
     self.parent.assertEqual(result.logits.shape							,					_A)


 def 	snake_case__			(		self)	->						List[Any]:

     """simple docstring"""



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



@require_torch
class 							A_      (  __lowercase	,				unittest.TestCase     ):






 '''simple docstring'''




 _SCREAMING_SNAKE_CASE							:     Any	=   (VivitModel, VivitForVideoClassification) if is_torch_available() else ()

 _SCREAMING_SNAKE_CASE							:     str	=   False
 _SCREAMING_SNAKE_CASE							:     Any	=   False
 _SCREAMING_SNAKE_CASE							:     Optional[int]	=   False
 _SCREAMING_SNAKE_CASE							:     int	=   False


 def 	snake_case__			(		self)	->						int:

     """simple docstring"""



     _UpperCAmelCase			: Any     					=			VivitModelTester(self)
     _UpperCAmelCase			: List[Any]     					=			ConfigTester(self							,					config_class=_A							,					has_text_modality=_A							,					hidden_size=37)


 def 	snake_case__			(		self							,					_A							,					_A							,					_A=False)	->						Any:

     """simple docstring"""



     _UpperCAmelCase			: int     					=			copy.deepcopy(_A)

     if return_labels:
         if model_class in get_values(_A):
             _UpperCAmelCase			: Any     					=			torch.zeros(
                 self.model_tester.batch_size							,					dtype=torch.long							,					device=_A)

     return inputs_dict


 def 	snake_case__			(		self)	->						Optional[int]:

     """simple docstring"""



     self.config_tester.run_common_tests()


 @unittest.skip(reason='''Vivit does not use inputs_embeds''')
 def 	snake_case__			(		self)	->						Any:

     """simple docstring"""



     pass


 def 	snake_case__			(		self)	->						List[str]:

     """simple docstring"""



     _UpperCAmelCase					,	_UpperCAmelCase			: Optional[int]     					=			self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
         _UpperCAmelCase			: Union[str, Any]     					=			model_class(_A)
         self.assertIsInstance(model.get_input_embeddings()							,					(nn.Module))
         _UpperCAmelCase			: List[Any]     					=			model.get_output_embeddings()
         self.assertTrue(x is None or isinstance(_A							,					nn.Linear))


 def 	snake_case__			(		self)	->						Optional[int]:

     """simple docstring"""



     _UpperCAmelCase					,	_UpperCAmelCase			: Any     					=			self.model_tester.prepare_config_and_inputs_for_common()

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

         _UpperCAmelCase			: Union[str, Any]     					=			['''pixel_values''', '''head_mask''']
         self.assertListEqual(arg_names[:2]							,					_A)


 def 	snake_case__			(		self)	->						Union[str, Any]:

     """simple docstring"""



     _UpperCAmelCase			: Optional[Any]     					=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*_A)


 def 	snake_case__			(		self)	->						Tuple:

     """simple docstring"""



     _UpperCAmelCase			: Union[str, Any]     					=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_video_classification(*_A)


 @slow
 def 	snake_case__			(		self)	->						Dict:

     """simple docstring"""



     for model_name in VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         _UpperCAmelCase			: Union[str, Any]     					=			VivitModel.from_pretrained(_A)
         self.assertIsNotNone(_A)


 def 	snake_case__			(		self)	->						List[str]:

     """simple docstring"""



     _UpperCAmelCase					,	_UpperCAmelCase			: str     					=			self.model_tester.prepare_config_and_inputs_for_common()
     _UpperCAmelCase			: Tuple     					=			True

     for model_class in self.all_model_classes:
         _UpperCAmelCase			: Any     					=			self.model_tester.seq_length

         _UpperCAmelCase			: Union[str, Any]     					=			True
         _UpperCAmelCase			: Tuple     					=			False
         _UpperCAmelCase			: List[Any]     					=			True
         _UpperCAmelCase			: Optional[int]     					=			model_class(_A)
         model.to(_A)
         model.eval()
         with torch.no_grad():
             _UpperCAmelCase			: Optional[int]     					=			model(**self._prepare_for_class(_A							,					_A))
         _UpperCAmelCase			: int     					=			outputs.attentions
         self.assertEqual(len(_A)							,					self.model_tester.num_hidden_layers)

         # check that output_attentions also work using config
         del inputs_dict["output_attentions"]
         _UpperCAmelCase			: Union[str, Any]     					=			True
         _UpperCAmelCase			: Union[str, Any]     					=			model_class(_A)
         model.to(_A)
         model.eval()
         with torch.no_grad():
             _UpperCAmelCase			: Optional[Any]     					=			model(**self._prepare_for_class(_A							,					_A))
         _UpperCAmelCase			: Optional[int]     					=			outputs.attentions
         self.assertEqual(len(_A)							,					self.model_tester.num_hidden_layers)

         self.assertListEqual(
             list(attentions[0].shape[-3:])							,					[self.model_tester.num_attention_heads, seq_len, seq_len]							,					)
         _UpperCAmelCase			: int     					=			len(_A)

         # Check attention is always last and order is fine
         _UpperCAmelCase			: Dict     					=			True
         _UpperCAmelCase			: Any     					=			True
         _UpperCAmelCase			: Optional[Any]     					=			model_class(_A)
         model.to(_A)
         model.eval()
         with torch.no_grad():
             _UpperCAmelCase			: int     					=			model(**self._prepare_for_class(_A							,					_A))

         self.assertEqual(out_len + 1							,					len(_A))

         _UpperCAmelCase			: Any     					=			outputs.attentions

         self.assertEqual(len(_A)							,					self.model_tester.num_hidden_layers)

         self.assertListEqual(
             list(self_attentions[0].shape[-3:])							,					[self.model_tester.num_attention_heads, seq_len, seq_len]							,					)


 def 	snake_case__			(		self)	->						Tuple:

     """simple docstring"""



     def check_hidden_states_output(_A							,					_A							,					_A):
         _UpperCAmelCase			: Optional[int]     					=			model_class(_A)
         model.to(_A)
         model.eval()

         with torch.no_grad():
             _UpperCAmelCase			: Optional[Any]     					=			model(**self._prepare_for_class(_A							,					_A))

         _UpperCAmelCase			: Optional[int]     					=			outputs.hidden_states
         _UpperCAmelCase			: Dict     					=			self.model_tester.num_hidden_layers + 1
         self.assertEqual(len(_A)							,					_A)

         _UpperCAmelCase			: Optional[int]     					=			self.model_tester.seq_length

         self.assertListEqual(
             list(hidden_states[0].shape[-2:])							,					[seq_length, self.model_tester.hidden_size]							,					)

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

     for model_class in self.all_model_classes:
         _UpperCAmelCase			: Union[str, Any]     					=			True
         check_hidden_states_output(_A							,					_A							,					_A)

         # check that output_hidden_states also work using config
         del inputs_dict["output_hidden_states"]
         _UpperCAmelCase			: List[Any]     					=			True

         check_hidden_states_output(_A							,					_A							,					_A)


 @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.''')
 def 	snake_case__			(		self)	->						Optional[int]:

     """simple docstring"""



     pass



def        _lowerCamelCase		(  ) ->   Any:
    _UpperCAmelCase			: Optional[Any]     					=			hf_hub_download(
        repo_id='''hf-internal-testing/spaghetti-video'''						,						filename='''eating_spaghetti_32_frames.npy'''						,						repo_type='''dataset'''	)
    _UpperCAmelCase			: Dict     					=			np.load(__A	)
    return list(__A	)


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






 '''simple docstring'''




 @cached_property
 def 	snake_case__			(		self)	->						Union[str, Any]:

     """simple docstring"""



     return VivitImageProcessor() if is_vision_available() else None


 @slow
 def 	snake_case__			(		self)	->						int:

     """simple docstring"""



     _UpperCAmelCase			: Any     					=			VivitForVideoClassification.from_pretrained('''google/vivit-b-16x2-kinetics400''').to(_A)

     _UpperCAmelCase			: Optional[Any]     					=			self.default_image_processor
     _UpperCAmelCase			: List[str]     					=			prepare_video()
     _UpperCAmelCase			: List[Any]     					=			image_processor(_A							,					return_tensors='''pt''').to(_A)

     # forward pass
     with torch.no_grad():
         _UpperCAmelCase			: List[Any]     					=			model(**_A)

     # verify the logits
     _UpperCAmelCase			: Any     					=			torch.Size((1, 400))
     self.assertEqual(outputs.logits.shape							,					_A)

     # taken from original model
     _UpperCAmelCase			: Optional[Any]     					=			torch.tensor([-1.0543, 2.0764, -0.2104, 0.4439, -0.9658]).to(_A)

     self.assertTrue(torch.allclose(outputs.logits[0, :5]							,					_A							,					atol=1e-4))












def        _lowerCamelCase		(  __A      :							list	) ->   list:
    _UpperCAmelCase			: Dict     					=			1.3
    _UpperCAmelCase			: Any     					=			len(__A	)
    _UpperCAmelCase			: List[Any]     					=			False

    while not completed:
        # Update the gap value for a next comb
        _UpperCAmelCase			: Optional[Any]     					=			int(gap / shrink_factor	)
        if gap <= 1:
            _UpperCAmelCase			: Any     					=			True

        _UpperCAmelCase			: Optional[Any]     					=			0
        while index + gap < len(__A	):
            if data[index] > data[index + gap]:
                # Swap values
                _UpperCAmelCase					,	_UpperCAmelCase			: Union[str, Any]     					=			data[index + gap], data[index]
                _UpperCAmelCase			: Any     					=			False
            index += 1

    return data


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  SCREAMING_SNAKE_CASE								=  input('Enter numbers separated by a comma:\n').strip()
  SCREAMING_SNAKE_CASE								=  [int(item) for item in user_input.split(',')]
  print(comb_sort(unsorted))




