



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    ):



       def 		_lowerCamelCase			(		self							:     Tuple):


           '''simple docstring'''

           __a						       =				'''ZinengTang/tvlt-base'''
           __a						       =				tempfile.mkdtemp()



       def 		_lowerCamelCase			(		self							:     Union[str, Any]     ,		**__SCREAMING_SNAKE_CASE							:     Tuple):


           '''simple docstring'''

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



       def 		_lowerCamelCase			(		self							:     List[Any]     ,		**__SCREAMING_SNAKE_CASE							:     Union[str, Any]):


           '''simple docstring'''

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



       def 		_lowerCamelCase			(		self							:     Union[str, Any]):


           '''simple docstring'''

           shutil.rmtree(self.tmpdirname)



       def 		_lowerCamelCase			(		self							:     List[str]):


           '''simple docstring'''

           __a						       =				self.get_image_processor()
           __a						       =				self.get_feature_extractor()

           __a						       =				TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE     ,		feature_extractor=__SCREAMING_SNAKE_CASE)
           processor.save_pretrained(self.tmpdirname)
           __a						       =				TvltProcessor.from_pretrained(self.tmpdirname)

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



       def 		_lowerCamelCase			(		self							:     Any):


           '''simple docstring'''

           __a						       =				self.get_image_processor()
           __a						       =				self.get_feature_extractor()

           __a						       =				TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE     ,		feature_extractor=__SCREAMING_SNAKE_CASE)

           __a						       =				np.ones([12_000])

           __a						       =				feature_extractor(__SCREAMING_SNAKE_CASE     ,		return_tensors='''np''')
           __a						       =				processor(audio=__SCREAMING_SNAKE_CASE     ,		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							:     Union[str, Any]):


           '''simple docstring'''

           __a						       =				self.get_image_processor()
           __a						       =				self.get_feature_extractor()

           __a						       =				TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE     ,		feature_extractor=__SCREAMING_SNAKE_CASE)

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

           __a						       =				image_processor(__SCREAMING_SNAKE_CASE     ,		return_tensors='''np''')
           __a						       =				processor(images=__SCREAMING_SNAKE_CASE     ,		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							:     Tuple):


           '''simple docstring'''

           __a						       =				self.get_image_processor()
           __a						       =				self.get_feature_extractor()

           __a						       =				TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE     ,		feature_extractor=__SCREAMING_SNAKE_CASE)

           __a						       =				np.ones([12_000])
           __a						       =				np.ones([3, 224, 224])

           __a						       =				processor(audio=__SCREAMING_SNAKE_CASE     ,		images=__SCREAMING_SNAKE_CASE)

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





       def 		_lowerCamelCase			(		self							:     Any):


           '''simple docstring'''

           __a						       =				self.get_image_processor()
           __a						       =				self.get_feature_extractor()

           __a						       =				TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE     ,		feature_extractor=__SCREAMING_SNAKE_CASE)

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










from collections import defaultdict

from graphs.minimum_spanning_tree_prims import prisms_algorithm as mst





def      __snake_case	(			):
    __a       ,   __a						       =				9, 14  # noqa: F841
    __a						       =				[
        [0, 1, 4],
        [0, 7, 8],
        [1, 2, 8],
        [7, 8, 7],
        [7, 6, 1],
        [2, 8, 2],
        [8, 6, 6],
        [2, 3, 7],
        [2, 5, 4],
        [6, 5, 2],
        [3, 5, 14],
        [3, 4, 9],
        [5, 4, 10],
        [1, 7, 11],
    ]

    __a						       =				defaultdict(_UpperCAmelCase				)
    for nodea, nodea, cost in edges:
        adjancency[nodea].append([nodea, cost]				)
        adjancency[nodea].append([nodea, cost]				)

    __a						       =				mst(_UpperCAmelCase				)

    __a						       =				[
        [7, 6, 1],
        [2, 8, 2],
        [6, 5, 2],
        [0, 1, 4],
        [2, 5, 4],
        [2, 3, 7],
        [0, 7, 8],
        [3, 4, 9],
    ]

    for answer in expected:
        __a						       =				tuple(answer[:2]				)
        __a						       =				tuple(edge[::-1]				)
        assert edge in result or reverse in result





