
"""simple docstring"""





import unittest

from huggingface_hub import hf_hub_download

from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VideoMAEFeatureExtractor
from transformers.pipelines import VideoClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_decord,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
)

from .test_pipelines_common import ANY






@is_pipeline_test
@require_torch_or_tf
@require_vision
@require_decord
class    _UpperCAmelCase(   unittest.TestCase     ):
		lowercase__      =				MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



		def 						UpperCAmelCase							( self    ,		__a    ,		__a    ,		__a)	->	str:






							'''simple docstring'''
							_UpperCamelCase										=  hf_hub_download(
							    repo_id='''nateraw/video-demo'''    ,		filename='''archery.mp4'''    ,		repo_type='''dataset''')
							_UpperCamelCase										=  VideoClassificationPipeline(model=_lowerCAmelCase    ,		image_processor=_lowerCAmelCase    ,		top_k=2)
							_UpperCamelCase										=  [
							    example_video_filepath,
							    """https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4""",
							]
							return video_classifier, examples



		def 						UpperCAmelCase							( self    ,		__a    ,		__a)	->	Dict:






							'''simple docstring'''
							for example in examples:
												_UpperCamelCase										=  video_classifier(_lowerCAmelCase)

												self.assertEqual(
												    _lowerCAmelCase    ,		[
												        {'''score''': ANY(_lowerCAmelCase), '''label''': ANY(_lowerCAmelCase)},
												        {'''score''': ANY(_lowerCAmelCase), '''label''': ANY(_lowerCAmelCase)},
												    ]    ,		)



		@require_torch
		def 						UpperCAmelCase							( self)	->	Any:






							'''simple docstring'''
							_UpperCamelCase										=  """hf-internal-testing/tiny-random-VideoMAEForVideoClassification"""
							_UpperCamelCase										=  VideoMAEFeatureExtractor(
							    size={'''shortest_edge''': 10}    ,		crop_size={'''height''': 10, '''width''': 10})
							_UpperCamelCase										=  pipeline(
							    '''video-classification'''    ,		model=_lowerCAmelCase    ,		feature_extractor=_lowerCAmelCase    ,		frame_sampling_rate=4)

							_UpperCamelCase										=  hf_hub_download(repo_id='''nateraw/video-demo'''    ,		filename='''archery.mp4'''    ,		repo_type='''dataset''')
							_UpperCamelCase										=  video_classifier(_lowerCAmelCase    ,		top_k=2)
							self.assertEqual(
							    nested_simplify(_lowerCAmelCase    ,		decimals=4)    ,		[{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}]    ,		)

							_UpperCamelCase										=  video_classifier(
							    [
							        video_file_path,
							        video_file_path,
							    ]    ,		top_k=2    ,		)
							self.assertEqual(
							    nested_simplify(_lowerCAmelCase    ,		decimals=4)    ,		[
							        [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
							        [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
							    ]    ,		)




		@require_tf
		def 						UpperCAmelCase							( self)	->	Optional[int]:






							'''simple docstring'''
							pass








"""simple docstring"""





def 				lowerCamelCase__		(      __snake_case,					__snake_case     )							->		str:


					"""simple docstring"""





					if number < 0 or shift_amount < 0:
										raise ValueError('''both inputs must be positive integers'''     )

					_UpperCamelCase										=  str(bin(__snake_case     )     )
					binary_number += "0" * shift_amount
					return binary_number



def 				lowerCamelCase__		(      __snake_case,					__snake_case     )							->		str:


					"""simple docstring"""





					if number < 0 or shift_amount < 0:
										raise ValueError('''both inputs must be positive integers'''     )

					_UpperCamelCase										=  str(bin(__snake_case     )     )[2:]
					if shift_amount >= len(__snake_case     ):
										return "0b0"
					_UpperCamelCase										=  binary_number[: len(__snake_case     ) - shift_amount]
					return "0b" + shifted_binary_number



def 				lowerCamelCase__		(      __snake_case,					__snake_case     )							->		str:


					"""simple docstring"""





					if number >= 0:  # Get binary representation of positive number
										_UpperCamelCase										=  '''0''' + str(bin(__snake_case     )     ).strip('''-'''     )[2:]
					else:  # Get binary (2's complement) representation of negative number
										_UpperCamelCase										=  len(bin(__snake_case     )[3:]     )  # Find 2's complement of number
										_UpperCamelCase										=  bin(abs(__snake_case     ) - (1 << binary_number_length)     )[3:]
										_UpperCamelCase										=  (
										    '''1''' + '''0''' * (binary_number_length - len(__snake_case     )) + binary_number
										)

					if shift_amount >= len(__snake_case     ):
										return "0b" + binary_number[0] * len(__snake_case     )
					return (
					    "0b"
					    + binary_number[0] * shift_amount
					    + binary_number[: len(__snake_case     ) - shift_amount]
					)


if __name__ == "__main__":
				import doctest

				doctest.testmod()






