





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	:List[Any] )->					Any:
         __A          =				'''ZinengTang/tvlt-base'''
         __A          =				tempfile.mkdtemp()




   def _lowerCAmelCase      (self	:Optional[Any]    ,   **_UpperCamelCase	:Optional[Any] )->					Tuple:
         return TvltImageProcessor.from_pretrained(self.checkpoint    ,   **_UpperCamelCase )




   def _lowerCAmelCase      (self	:Union[str, Any]    ,   **_UpperCamelCase	:Optional[int] )->					Any:
         return TvltFeatureExtractor.from_pretrained(self.checkpoint    ,   **_UpperCamelCase )




   def _lowerCAmelCase      (self	:Union[str, Any] )->					Union[str, Any]:
         shutil.rmtree(self.tmpdirname )




   def _lowerCAmelCase      (self	:List[str] )->					Dict:
         __A          =				self.get_image_processor()
         __A          =				self.get_feature_extractor()

         __A          =				TvltProcessor(image_processor=_UpperCamelCase    ,   feature_extractor=_UpperCamelCase )
         processor.save_pretrained(self.tmpdirname )
         __A          =				TvltProcessor.from_pretrained(self.tmpdirname )

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




   def _lowerCAmelCase      (self	:List[Any] )->					Any:
         __A          =				self.get_image_processor()
         __A          =				self.get_feature_extractor()

         __A          =				TvltProcessor(image_processor=_UpperCamelCase    ,   feature_extractor=_UpperCamelCase )

         __A          =				np.ones([1_2000] )

         __A          =				feature_extractor(_UpperCamelCase    ,   return_tensors='''np''' )
         __A          =				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	:str )->					Union[str, Any]:
         __A          =				self.get_image_processor()
         __A          =				self.get_feature_extractor()

         __A          =				TvltProcessor(image_processor=_UpperCamelCase    ,   feature_extractor=_UpperCamelCase )

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

         __A          =				image_processor(_UpperCamelCase    ,   return_tensors='''np''' )
         __A          =				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	:int )->					Optional[int]:
         __A          =				self.get_image_processor()
         __A          =				self.get_feature_extractor()

         __A          =				TvltProcessor(image_processor=_UpperCamelCase    ,   feature_extractor=_UpperCamelCase )

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

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

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












from __future__ import annotations



def _a				(	lowerCamelCase:   list[float]					,				lowerCamelCase:   Tuple )	->						List[str]:







      '''simple docstring'''






      print(F"""Vertex\tShortest Distance from vertex {src}""" )
      for i, d in enumerate(lowerCamelCase ):
            print(F"""{i}\t\t{d}""" )



def _a				(	lowerCamelCase:   list[dict[str, int]]					,				lowerCamelCase:   list[float]					,				lowerCamelCase:   int )	->						Union[str, Any]:







      '''simple docstring'''






      for j in range(lowerCamelCase ):
            __A   ,						__A   ,						__A          =				(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])
            if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
                  return True
      return False



def _a				(	lowerCamelCase:   list[dict[str, int]]					,				lowerCamelCase:   int					,				lowerCamelCase:   int					,				lowerCamelCase:   int )	->						list[float]:







      '''simple docstring'''






      __A          =				[float('''inf''' )] * vertex_count
      __A          =				0.0

      for _ in range(vertex_count - 1 ):
            for j in range(lowerCamelCase ):
                  __A   ,						__A   ,						__A          =				(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])

                  if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
                        __A          =				distance[u] + w

      __A          =				check_negative_cycle(lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase )
      if negative_cycle_exists:
            raise Exception('''Negative cycle found''' )

      return distance


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       snake_case__					:							Dict													=     int(input('Enter number of vertices: ').strip())
       snake_case__					:							Optional[int]													=     int(input('Enter number of edges: ').strip())

       snake_case__					:							list[dict[str, int]]													=     [{} for _ in range(E)]

       for i in range(E):
              print('Edge ', i + 1)
              snake_case__						,    snake_case__						,    snake_case__					:							Dict													=     (
                  int(x)
                  for x in input('Enter source, destination, weight: ').strip().split(' ')
              )
              snake_case__					:							List[Any]													=     {'src': src, 'dst': dest, 'weight': weight}

       snake_case__					:							Union[str, Any]													=     int(input('\nEnter shortest path source:').strip())
       snake_case__					:							List[Any]													=     bellman_ford(graph, V, E, source)
       print_distance(shortest_distance, 0)





