



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





     '''simple docstring'''



     def  __lowerCAmelCase	(					self		)							->					str:
         _UpperCAmelCase							:  Union[str, Any]											=    '''ZinengTang/tvlt-base'''
         _UpperCAmelCase							:  Dict											=    tempfile.mkdtemp()





     def  __lowerCAmelCase	(					self       ,	**A		)							->					int:
         return TvltImageProcessor.from_pretrained(self.checkpoint       ,	**A		)





     def  __lowerCAmelCase	(					self       ,	**A		)							->					Optional[Any]:
         return TvltFeatureExtractor.from_pretrained(self.checkpoint       ,	**A		)





     def  __lowerCAmelCase	(					self		)							->					Optional[Any]:
         shutil.rmtree(self.tmpdirname		)





     def  __lowerCAmelCase	(					self		)							->					Any:
         _UpperCAmelCase							:  str											=    self.get_image_processor()
         _UpperCAmelCase							:  Optional[Any]											=    self.get_feature_extractor()

         _UpperCAmelCase							:  Tuple											=    TvltProcessor(image_processor=A       ,	feature_extractor=A		)
         processor.save_pretrained(self.tmpdirname		)
         _UpperCAmelCase							:  int											=    TvltProcessor.from_pretrained(self.tmpdirname		)

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





     def  __lowerCAmelCase	(					self		)							->					Optional[Any]:
         _UpperCAmelCase							:  List[str]											=    self.get_image_processor()
         _UpperCAmelCase							:  int											=    self.get_feature_extractor()

         _UpperCAmelCase							:  List[str]											=    TvltProcessor(image_processor=A       ,	feature_extractor=A		)

         _UpperCAmelCase							:  Tuple											=    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		)							->					Optional[int]:
         _UpperCAmelCase							:  Union[str, Any]											=    self.get_image_processor()
         _UpperCAmelCase							:  Dict											=    self.get_feature_extractor()

         _UpperCAmelCase							:  Dict											=    TvltProcessor(image_processor=A       ,	feature_extractor=A		)

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

         _UpperCAmelCase							:  Tuple											=    image_processor(A       ,	return_tensors='''np'''		)
         _UpperCAmelCase							:  List[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		)							->					str:
         _UpperCAmelCase							:  Optional[int]											=    self.get_image_processor()
         _UpperCAmelCase							:  Union[str, Any]											=    self.get_feature_extractor()

         _UpperCAmelCase							:  Optional[int]											=    TvltProcessor(image_processor=A       ,	feature_extractor=A		)

         _UpperCAmelCase							:  List[Any]											=    np.ones([1_2_0_0_0]		)
         _UpperCAmelCase							:  Tuple											=    np.ones([3, 2_2_4, 2_2_4]		)

         _UpperCAmelCase							:  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		)							->					Optional[int]:
         _UpperCAmelCase							:  Any											=    self.get_image_processor()
         _UpperCAmelCase							:  int											=    self.get_feature_extractor()

         _UpperCAmelCase							:  List[str]											=    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"""
def  lowerCamelCase_						(UpperCamelCase__		:		int     ,       UpperCamelCase__		:		int							):
    if a < 0 or b < 0:
        raise ValueError('''the value of both inputs must be positive'''							)
    _UpperCAmelCase							:  List[str]											=    str(bin(UpperCamelCase__							)							)[2:]  # remove the leading "0b"
    _UpperCAmelCase							:  str											=    str(bin(UpperCamelCase__							)							)[2:]
    _UpperCAmelCase							:  List[str]											=    max(len(UpperCamelCase__							)     ,       len(UpperCamelCase__							)							)
    return "0b" + "".join(
        str(int('''1''' in (char_a, char_b)							)							)
        for char_a, char_b in zip(a_binary.zfill(UpperCamelCase__							)     ,       b_binary.zfill(UpperCamelCase__							)							)							)


if __name__ == "__main__":
  import doctest

  doctest.testmod()


