


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   :						Union[str, Any]		)						->       List[Any]:




							"""simple docstring"""


							lowercase__					      =		"""ZinengTang/tvlt-base"""
							lowercase__					      =		tempfile.mkdtemp()

					def   lowerCamelCase__					(self   :						str				, **_UpperCAmelCase   :						Optional[Any]		)						->       List[str]:




							"""simple docstring"""


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

					def   lowerCamelCase__					(self   :						List[Any]				, **_UpperCAmelCase   :						Union[str, Any]		)						->       Optional[int]:




							"""simple docstring"""


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

					def   lowerCamelCase__					(self   :						Tuple		)						->       Union[str, Any]:




							"""simple docstring"""


							shutil.rmtree(self.tmpdirname		)

					def   lowerCamelCase__					(self   :						Union[str, Any]		)						->       Optional[Any]:




							"""simple docstring"""


							lowercase__					      =		self.get_image_processor()
							lowercase__					      =		self.get_feature_extractor()

							lowercase__					      =		TvltProcessor(image_processor=_UpperCAmelCase				, feature_extractor=_UpperCAmelCase		)
							processor.save_pretrained(self.tmpdirname		)
							lowercase__					      =		TvltProcessor.from_pretrained(self.tmpdirname		)

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

					def   lowerCamelCase__					(self   :						List[Any]		)						->       Tuple:




							"""simple docstring"""


							lowercase__					      =		self.get_image_processor()
							lowercase__					      =		self.get_feature_extractor()

							lowercase__					      =		TvltProcessor(image_processor=_UpperCAmelCase				, feature_extractor=_UpperCAmelCase		)

							lowercase__					      =		np.ones([1_2000]		)

							lowercase__					      =		feature_extractor(_UpperCAmelCase				, return_tensors="""np"""		)
							lowercase__					      =		processor(audio=_UpperCAmelCase				, 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[Any]		)						->       Any:




							"""simple docstring"""


							lowercase__					      =		self.get_image_processor()
							lowercase__					      =		self.get_feature_extractor()

							lowercase__					      =		TvltProcessor(image_processor=_UpperCAmelCase				, feature_extractor=_UpperCAmelCase		)

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

							lowercase__					      =		image_processor(_UpperCAmelCase				, return_tensors="""np"""		)
							lowercase__					      =		processor(images=_UpperCAmelCase				, 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   :						Optional[int]		)						->       Dict:




							"""simple docstring"""


							lowercase__					      =		self.get_image_processor()
							lowercase__					      =		self.get_feature_extractor()

							lowercase__					      =		TvltProcessor(image_processor=_UpperCAmelCase				, feature_extractor=_UpperCAmelCase		)

							lowercase__					      =		np.ones([1_2000]		)
							lowercase__					      =		np.ones([3, 224, 224]		)

							lowercase__					      =		processor(audio=_UpperCAmelCase				, images=_UpperCAmelCase		)

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


					def   lowerCamelCase__					(self   :						str		)						->       List[Any]:




							"""simple docstring"""


							lowercase__					      =		self.get_image_processor()
							lowercase__					      =		self.get_feature_extractor()

							lowercase__					      =		TvltProcessor(image_processor=_UpperCAmelCase				, feature_extractor=_UpperCAmelCase		)

							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 			UpperCamelCase (     __magic_name__					:							str					)       ->  List[str]:  # noqa: E741
		"""simple docstring"""




		lowercase__					      =		len(__magic_name__					)
		lowercase__					      =		0
		lowercase__					      =		[0] * n
		lowercase__					      =		[False] * n
		lowercase__					      =		[False] * n

		def dfs(__magic_name__					:							str   ,   __magic_name__					:							List[str]   ,   __magic_name__					:							str   ,   __magic_name__					:							Any					):
				if parent == root:
						out_edge_count += 1
				lowercase__					      =		True
				lowercase__					      =		at

				for to in l[at]:
						if to == parent:
								pass
						elif not visited[to]:
								lowercase__					      =		dfs(__magic_name__   ,   __magic_name__   ,   __magic_name__   ,   __magic_name__					)
								lowercase__					      =		min(low[at]   ,   low[to]					)

								# AP found via bridge
								if at < low[to]:
										lowercase__					      =		True
								# AP found via cycle
								if at == low[to]:
										lowercase__					      =		True
						else:
								lowercase__					      =		min(low[at]   ,   __magic_name__					)
				return out_edge_count

		for i in range(__magic_name__					):
				if not visited[i]:
						lowercase__					      =		0
						lowercase__					      =		dfs(__magic_name__   ,   __magic_name__   ,   -1   ,   __magic_name__					)
						lowercase__					      =		out_edge_count > 1

		for x in range(len(__magic_name__					)					):
				if is_art[x] is True:
						print(__magic_name__					)


# Adjacency list of graph
A	:		List[str]    =       {
    0: [1, 2],
    1: [0, 2],
    2: [0, 1, 3, 5],
    3: [2, 4],
    4: [3],
    5: [2, 6, 8],
    6: [5, 7],
    7: [6, 8],
    8: [5, 7],
}







compute_ap(data)

