



import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import ViTImageProcessor







class 	UpperCAmelCase	(		unittest.TestCase):


 '''simple docstring'''




 def __init__(   self							,  lowerCAmelCase_							,  lowerCAmelCase_=1_3							,  lowerCAmelCase_=3							,  lowerCAmelCase_=2_2_4							,  lowerCAmelCase_=3_0							,  lowerCAmelCase_=4_0_0							,  lowerCAmelCase_=True							,  lowerCAmelCase_=None							,  lowerCAmelCase_=True							,  lowerCAmelCase_=[0.5, 0.5, 0.5]							,  lowerCAmelCase_=[0.5, 0.5, 0.5]							,  ) ->      Dict:



      """simple docstring"""







      a_       		=size if size is not None else {'''height''': 1_8, '''width''': 1_8}
      a_       		=parent
      a_       		=batch_size
      a_       		=num_channels
      a_       		=image_size
      a_       		=min_resolution
      a_       		=max_resolution
      a_       		=do_resize
      a_       		=size
      a_       		=do_normalize
      a_       		=image_mean
      a_       		=image_std




 def       lowercase_  (   self) ->      Optional[int]:



      """simple docstring"""







      return {
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_normalize": self.do_normalize,
          "do_resize": self.do_resize,
          "size": self.size,
      }







@require_torch
@require_vision
class 	UpperCAmelCase	(		lowerCamelCase__					,	unittest.TestCase):


 '''simple docstring'''




 __magic_name__					: Any  =      ViTImageProcessor if is_vision_available() else None




 def       lowercase_  (   self) ->      str:



      """simple docstring"""







      a_       		=EfficientFormerImageProcessorTester(self)




 @property
 def       lowercase_  (   self) ->      str:



      """simple docstring"""







      return self.image_proc_tester.prepare_image_processor_dict()




 def       lowercase_  (   self) ->      Any:



      """simple docstring"""







      a_       		=self.image_processing_class(**self.image_processor_dict)
      self.assertTrue(hasattr(__lowerCamelCase							,  "image_mean"))
      self.assertTrue(hasattr(__lowerCamelCase							,  "image_std"))
      self.assertTrue(hasattr(__lowerCamelCase							,  "do_normalize"))
      self.assertTrue(hasattr(__lowerCamelCase							,  "do_resize"))
      self.assertTrue(hasattr(__lowerCamelCase							,  "size"))




 def       lowercase_  (   self) ->      List[Any]:



      """simple docstring"""







      pass




 def       lowercase_  (   self) ->      List[str]:



      """simple docstring"""







      a_       		=self.image_processing_class(**self.image_processor_dict)
      # create random PIL images
      a_       		=prepare_image_inputs(self.image_proc_tester							,  equal_resolution=__lowerCamelCase)
      for image in image_inputs:
           self.assertIsInstance(__lowerCamelCase							,  Image.Image)

      # Test not batched input
      a_       		=image_processor(image_inputs[0]							,  return_tensors="pt").pixel_values
      self.assertEqual(
          encoded_images.shape							,  (
              1,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )							,  )

      # Test batched
      a_       		=image_processor(__lowerCamelCase							,  return_tensors="pt").pixel_values
      self.assertEqual(
          encoded_images.shape							,  (
              self.image_proc_tester.batch_size,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )							,  )




 def       lowercase_  (   self) ->      Optional[Any]:



      """simple docstring"""







      a_       		=self.image_processing_class(**self.image_processor_dict)
      # create random numpy tensors
      a_       		=prepare_image_inputs(self.image_proc_tester							,  equal_resolution=__lowerCamelCase							,  numpify=__lowerCamelCase)
      for image in image_inputs:
           self.assertIsInstance(__lowerCamelCase							,  np.ndarray)

      # Test not batched input
      a_       		=image_processor(image_inputs[0]							,  return_tensors="pt").pixel_values
      self.assertEqual(
          encoded_images.shape							,  (
              1,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )							,  )

      # Test batched
      a_       		=image_processor(__lowerCamelCase							,  return_tensors="pt").pixel_values
      self.assertEqual(
          encoded_images.shape							,  (
              self.image_proc_tester.batch_size,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )							,  )




 def       lowercase_  (   self) ->      Any:



      """simple docstring"""







      a_       		=self.image_processing_class(**self.image_processor_dict)
      # create random PyTorch tensors
      a_       		=prepare_image_inputs(self.image_proc_tester							,  equal_resolution=__lowerCamelCase							,  torchify=__lowerCamelCase)
      for image in image_inputs:
           self.assertIsInstance(__lowerCamelCase							,  torch.Tensor)

      # Test not batched input
      a_       		=image_processor(image_inputs[0]							,  return_tensors="pt").pixel_values
      self.assertEqual(
          encoded_images.shape							,  (
              1,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )							,  )

      # Test batched
      a_       		=image_processor(__lowerCamelCase							,  return_tensors="pt").pixel_values
      self.assertEqual(
          encoded_images.shape							,  (
              self.image_proc_tester.batch_size,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )							,  )







'''simple docstring'''


from __future__ import annotations






def  UpperCAmelCase_       (		lowercase__       ,	lowercase__       ):


     '''simple docstring'''







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






def  UpperCAmelCase_       (		lowercase__       ,	lowercase__       ,	lowercase__       ):


     '''simple docstring'''







     for j in range(lowercase__       ):
          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  UpperCAmelCase_       (		lowercase__       ,	lowercase__       ,	lowercase__       ,	lowercase__       ):


     '''simple docstring'''







     a_       		=[float("inf"       )] * vertex_count
     a_       		=0.0

     for _ in range(vertex_count - 1       ):
          for j in range(lowercase__       ):
               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(lowercase__       ,	lowercase__       ,	lowercase__       )
     if negative_cycle_exists:
          raise Exception("Negative cycle found"       )

     return distance


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  lowercase							       =			int(input('''Enter number of vertices: ''').strip())
  lowercase							       =			int(input('''Enter number of edges: ''').strip())

  lowercase							       =			[{} for _ in range(E)]

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

  lowercase							       =			int(input('''\nEnter shortest path source:''').strip())
  lowercase							       =			bellman_ford(graph, V, E, source)
  print_distance(shortest_distance, 0)


