


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 		_snake_case  (				unittest.TestCase							):




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       a						:Optional[int]										=	'''ZinengTang/tvlt-base'''
       a						:List[str]										=	tempfile.mkdtemp()




 def 	SCREAMING_SNAKE_CASE__    (		self ,  **_lowerCamelCase   ):
       return TvltImageProcessor.from_pretrained(self.checkpoint ,  **_lowerCamelCase   )




 def 	SCREAMING_SNAKE_CASE__    (		self ,  **_lowerCamelCase   ):
       return TvltFeatureExtractor.from_pretrained(self.checkpoint ,  **_lowerCamelCase   )




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




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       a						:Optional[Any]										=	self.get_image_processor()
       a						:List[Any]										=	self.get_feature_extractor()

       a						:List[Any]										=	TvltProcessor(image_processor=_lowerCamelCase ,  feature_extractor=_lowerCamelCase   )
       processor.save_pretrained(self.tmpdirname   )
       a						:List[Any]										=	TvltProcessor.from_pretrained(self.tmpdirname   )

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




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       a						:Union[str, Any]										=	self.get_image_processor()
       a						:Union[str, Any]										=	self.get_feature_extractor()

       a						:Optional[Any]										=	TvltProcessor(image_processor=_lowerCamelCase ,  feature_extractor=_lowerCamelCase   )

       a						:List[Any]										=	np.ones([1_2000]   )

       a						:str										=	feature_extractor(_lowerCamelCase ,  return_tensors='''np'''   )
       a						:str										=	processor(audio=_lowerCamelCase ,  return_tensors='''np'''   )

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




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       a						:int										=	self.get_image_processor()
       a						:Dict										=	self.get_feature_extractor()

       a						:List[Any]										=	TvltProcessor(image_processor=_lowerCamelCase ,  feature_extractor=_lowerCamelCase   )

       a						:Dict										=	np.ones([3, 224, 224]   )

       a						:Tuple										=	image_processor(_lowerCamelCase ,  return_tensors='''np'''   )
       a						:Optional[int]										=	processor(images=_lowerCamelCase ,  return_tensors='''np'''   )

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




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       a						:Tuple										=	self.get_image_processor()
       a						:Union[str, Any]										=	self.get_feature_extractor()

       a						:List[Any]										=	TvltProcessor(image_processor=_lowerCamelCase ,  feature_extractor=_lowerCamelCase   )

       a						:Optional[int]										=	np.ones([1_2000]   )
       a						:Optional[int]										=	np.ones([3, 224, 224]   )

       a						:Union[str, Any]										=	processor(audio=_lowerCamelCase ,  images=_lowerCamelCase   )

       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(_lowerCamelCase   ):
             processor()




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       a						:Optional[int]										=	self.get_image_processor()
       a						:List[Any]										=	self.get_feature_extractor()

       a						:List[Any]										=	TvltProcessor(image_processor=_lowerCamelCase ,  feature_extractor=_lowerCamelCase   )

       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''' ,  )









import math
def     __lowerCamelCase						(			UpperCAmelCase_						:		float			,  UpperCAmelCase_						:		float						):




      """simple docstring"""





      return math.pow(UpperCAmelCase_			,  2						) - a
def     __lowerCamelCase						(			UpperCAmelCase_						:		float						):




      """simple docstring"""





      return 2 * x
def     __lowerCamelCase						(			UpperCAmelCase_						:		float						):




      """simple docstring"""





      a						:int										=	2.0

      while start <= a:
            a						:int										=	math.pow(UpperCAmelCase_			,  2						)

      return start
def     __lowerCamelCase						(			UpperCAmelCase_						:		float			,  UpperCAmelCase_						:		int = 9999			,  UpperCAmelCase_						:		float = 0.00000000000001						):




      """simple docstring"""





      if a < 0:
            raise ValueError('''math domain error'''						)

      a						:List[Any]										=	get_initial_point(UpperCAmelCase_						)

      for _ in range(UpperCAmelCase_						):
            a						:Optional[int]										=	value
            a						:int										=	value - fx(UpperCAmelCase_			,  UpperCAmelCase_						) / fx_derivative(UpperCAmelCase_						)
            if abs(prev_value - value						) < tolerance:
                  return value

      return value


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

     testmod()





