






"""simple docstring"""







import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
  from transformers import TvltImageProcessor

if is_speech_available():
  from transformers import TvltFeatureExtractor

from transformers import TvltProcessor







@require_torch
class  lowerCamelCase__ (	unittest.TestCase			):






    def     _UpperCamelCase							(			self ):
          UpperCAmelCase          =	"""ZinengTang/tvlt-base"""
          UpperCAmelCase          =	tempfile.mkdtemp()






    def     _UpperCamelCase							(			self     ,**A ):
          return TvltImageProcessor.from_pretrained(self.checkpoint     ,**A )






    def     _UpperCamelCase							(			self     ,**A ):
          return TvltFeatureExtractor.from_pretrained(self.checkpoint     ,**A )






    def     _UpperCamelCase							(			self ):
          shutil.rmtree(self.tmpdirname )






    def     _UpperCamelCase							(			self ):
          UpperCAmelCase          =	self.get_image_processor()
          UpperCAmelCase          =	self.get_feature_extractor()

          UpperCAmelCase          =	TvltProcessor(image_processor=A     ,feature_extractor=A )
          processor.save_pretrained(self.tmpdirname )
          UpperCAmelCase          =	TvltProcessor.from_pretrained(self.tmpdirname )

          self.assertIsInstance(processor.feature_extractor     ,A )
          self.assertIsInstance(processor.image_processor     ,A )






    def     _UpperCamelCase							(			self ):
          UpperCAmelCase          =	self.get_image_processor()
          UpperCAmelCase          =	self.get_feature_extractor()

          UpperCAmelCase          =	TvltProcessor(image_processor=A     ,feature_extractor=A )

          UpperCAmelCase          =	np.ones([12_000] )

          UpperCAmelCase          =	feature_extractor(A     ,return_tensors="""np""" )
          UpperCAmelCase          =	processor(audio=A     ,return_tensors="""np""" )

          for key in audio_dict.keys():
                self.assertAlmostEqual(audio_dict[key].sum()     ,input_processor[key].sum()     ,delta=1e-2 )






    def     _UpperCamelCase							(			self ):
          UpperCAmelCase          =	self.get_image_processor()
          UpperCAmelCase          =	self.get_feature_extractor()

          UpperCAmelCase          =	TvltProcessor(image_processor=A     ,feature_extractor=A )

          UpperCAmelCase          =	np.ones([3, 224, 224] )

          UpperCAmelCase          =	image_processor(A     ,return_tensors="""np""" )
          UpperCAmelCase          =	processor(images=A     ,return_tensors="""np""" )

          for key in image_dict.keys():
                self.assertAlmostEqual(image_dict[key].sum()     ,input_processor[key].sum()     ,delta=1e-2 )






    def     _UpperCamelCase							(			self ):
          UpperCAmelCase          =	self.get_image_processor()
          UpperCAmelCase          =	self.get_feature_extractor()

          UpperCAmelCase          =	TvltProcessor(image_processor=A     ,feature_extractor=A )

          UpperCAmelCase          =	np.ones([12_000] )
          UpperCAmelCase          =	np.ones([3, 224, 224] )

          UpperCAmelCase          =	processor(audio=A     ,images=A )

          self.assertListEqual(list(inputs.keys() )     ,["""audio_values""", """audio_mask""", """pixel_values""", """pixel_mask"""] )

          # test if it raises when no input is passed
          with pytest.raises(A ):
                processor()






    def     _UpperCamelCase							(			self ):
          UpperCAmelCase          =	self.get_image_processor()
          UpperCAmelCase          =	self.get_feature_extractor()

          UpperCAmelCase          =	TvltProcessor(image_processor=A     ,feature_extractor=A )

          self.assertListEqual(
              processor.model_input_names     ,image_processor.model_input_names + feature_extractor.model_input_names     ,msg="""`processor` and `image_processor`+`feature_extractor` model input names do not match"""     ,)











"""simple docstring"""







from __future__ import annotations

def _a			(		_snake_case				,	_snake_case = None				,	_snake_case = None							):







      """simple docstring"""






      if start is None:
            UpperCAmelCase          =	0

      if end is None:
            UpperCAmelCase          =	len(_snake_case							) - 1

      if start >= end:
            return

      UpperCAmelCase          =	(start + end) // 2

      slowsort(_snake_case				,	_snake_case				,	_snake_case							)
      slowsort(_snake_case				,	mid + 1				,	_snake_case							)

      if sequence[end] < sequence[mid]:
            UpperCAmelCase      , UpperCAmelCase          =	sequence[mid], sequence[end]

      slowsort(_snake_case				,	_snake_case				,	end - 1							)


if __name__ == "__main__":
  from doctest import testmod

  testmod()



