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





   """simple docstring"""





   def 			_lowerCAmelCase		( self     :		Optional[int]			)       ->    List[str]:







      """simple docstring"""




      _UpperCAmelCase							:	Tuple							=   "ZinengTang/tvlt-base"
      _UpperCAmelCase							:	Any							=   tempfile.mkdtemp()




   def 			_lowerCAmelCase		( self     :		str						,     **lowerCAmelCase__     :		Union[str, Any]			)       ->    str:







      """simple docstring"""




      return TvltImageProcessor.from_pretrained(self.checkpoint						,     **a__			)




   def 			_lowerCAmelCase		( self     :		List[Any]						,     **lowerCAmelCase__     :		List[Any]			)       ->    int:







      """simple docstring"""




      return TvltFeatureExtractor.from_pretrained(self.checkpoint						,     **a__			)




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







      """simple docstring"""




      shutil.rmtree(self.tmpdirname			)




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







      """simple docstring"""




      _UpperCAmelCase							:	Tuple							=   self.get_image_processor()
      _UpperCAmelCase							:	int							=   self.get_feature_extractor()

      _UpperCAmelCase							:	int							=   TvltProcessor(image_processor=a__						,     feature_extractor=a__			)
      processor.save_pretrained(self.tmpdirname			)
      _UpperCAmelCase							:	List[Any]							=   TvltProcessor.from_pretrained(self.tmpdirname			)

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




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







      """simple docstring"""




      _UpperCAmelCase							:	str							=   self.get_image_processor()
      _UpperCAmelCase							:	Dict							=   self.get_feature_extractor()

      _UpperCAmelCase							:	Tuple							=   TvltProcessor(image_processor=a__						,     feature_extractor=a__			)

      _UpperCAmelCase							:	List[str]							=   np.ones([1_2_0_0_0]			)

      _UpperCAmelCase							:	Tuple							=   feature_extractor(a__						,     return_tensors="np"			)
      _UpperCAmelCase							:	List[str]							=   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 			_lowerCAmelCase		( self     :		Dict			)       ->    Dict:







      """simple docstring"""




      _UpperCAmelCase							:	Optional[Any]							=   self.get_image_processor()
      _UpperCAmelCase							:	List[str]							=   self.get_feature_extractor()

      _UpperCAmelCase							:	Optional[Any]							=   TvltProcessor(image_processor=a__						,     feature_extractor=a__			)

      _UpperCAmelCase							:	Any							=   np.ones([3, 2_2_4, 2_2_4]			)

      _UpperCAmelCase							:	Any							=   image_processor(a__						,     return_tensors="np"			)
      _UpperCAmelCase							:	Any							=   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 			_lowerCAmelCase		( self     :		List[Any]			)       ->    Any:







      """simple docstring"""




      _UpperCAmelCase							:	Any							=   self.get_image_processor()
      _UpperCAmelCase							:	Optional[int]							=   self.get_feature_extractor()

      _UpperCAmelCase							:	List[Any]							=   TvltProcessor(image_processor=a__						,     feature_extractor=a__			)

      _UpperCAmelCase							:	List[str]							=   np.ones([1_2_0_0_0]			)
      _UpperCAmelCase							:	Optional[int]							=   np.ones([3, 2_2_4, 2_2_4]			)

      _UpperCAmelCase							:	Optional[int]							=   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 			_lowerCAmelCase		( self     :		Dict			)       ->    str:







      """simple docstring"""




      _UpperCAmelCase							:	List[Any]							=   self.get_image_processor()
      _UpperCAmelCase							:	int							=   self.get_feature_extractor()

      _UpperCAmelCase							:	Tuple							=   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"						,     )






def lowerCamelCase__    (							snake_case_	:  int       )      ->				int:
   if not isinstance(snake_case_       ,      snake_case_       ) or number < 0:
      raise ValueError('''Input must be a non-negative integer'''       )

   __snake_case							       =   0
   while number:
      # This way we arrive at next set bit (next 1) instead of looping
      # through each bit and checking for 1s hence the
      # loop won't run 32 times it will only run the number of `1` times
      number &= number - 1
      count += 1
   return count


if __name__ == "__main__":
    import doctest

    doctest.testmod()

