



"""simple docstring"""







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_video_inputs


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import VivitImageProcessor







class       UpperCamelCase__   (	unittest.TestCase  ):




      """simple docstring"""




      def __init__(      self				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      Any    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]=7    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=3    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]=1_0    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]=1_8    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=3_0    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=4_0_0    ,			SCREAMING_SNAKE_CASE_				:      int=True    ,			SCREAMING_SNAKE_CASE_				:      Dict=None    ,			SCREAMING_SNAKE_CASE_				:      Any=True    ,			SCREAMING_SNAKE_CASE_				:      List[Any]=[0.5, 0.5, 0.5]    ,			SCREAMING_SNAKE_CASE_				:      Any=[0.5, 0.5, 0.5]    ,			SCREAMING_SNAKE_CASE_				:      str=None    ,			):
        lowerCAmelCase_   :				List[Any]								= size if size is not None else {"shortest_edge": 1_8}
        lowerCAmelCase_   :				str								= crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}

        lowerCAmelCase_   :				List[Any]								= parent
        lowerCAmelCase_   :				Union[str, Any]								= batch_size
        lowerCAmelCase_   :				Any								= num_channels
        lowerCAmelCase_   :				Any								= num_frames
        lowerCAmelCase_   :				Tuple								= image_size
        lowerCAmelCase_   :				Any								= min_resolution
        lowerCAmelCase_   :				Dict								= max_resolution
        lowerCAmelCase_   :				Union[str, Any]								= do_resize
        lowerCAmelCase_   :				int								= size
        lowerCAmelCase_   :				Dict								= do_normalize
        lowerCAmelCase_   :				Optional[Any]								= image_mean
        lowerCAmelCase_   :				Tuple								= image_std
        lowerCAmelCase_   :				List[str]								= crop_size





      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[Any]       ):
        return {
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_normalize": self.do_normalize,
            "do_resize": self.do_resize,
            "size": self.size,
            "crop_size": self.crop_size,
        }







@require_torch
@require_vision
class       UpperCamelCase__   (	A__,					unittest.TestCase  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     VivitImageProcessor if is_vision_available() else None



      def      SCREAMING_SNAKE_CASE__ (      self				:      Union[str, Any]       ):
        lowerCAmelCase_   :				str								= VivitImageProcessingTester(self       )



      @property
      def      SCREAMING_SNAKE_CASE__ (      self				:      Union[str, Any]       ):
        return self.image_processor_tester.prepare_image_processor_dict()



      def      SCREAMING_SNAKE_CASE__ (      self				:      Union[str, Any]       ):
        lowerCAmelCase_   :				Optional[Any]								= self.image_processing_class(**self.image_processor_dict       )
        self.assertTrue(hasattr(_A    ,			'image_mean'       )       )
        self.assertTrue(hasattr(_A    ,			'image_std'       )       )
        self.assertTrue(hasattr(_A    ,			'do_normalize'       )       )
        self.assertTrue(hasattr(_A    ,			'do_resize'       )       )
        self.assertTrue(hasattr(_A    ,			'do_center_crop'       )       )
        self.assertTrue(hasattr(_A    ,			'size'       )       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      str       ):
        lowerCAmelCase_   :				Dict								= self.image_processing_class.from_dict(self.image_processor_dict       )
        self.assertEqual(image_processor.size    ,			{'shortest_edge': 1_8}       )
        self.assertEqual(image_processor.crop_size    ,			{'height': 1_8, 'width': 1_8}       )

        lowerCAmelCase_   :				List[Any]								= self.image_processing_class.from_dict(self.image_processor_dict    ,			size=4_2    ,			crop_size=8_4       )
        self.assertEqual(image_processor.size    ,			{'shortest_edge': 4_2}       )
        self.assertEqual(image_processor.crop_size    ,			{'height': 8_4, 'width': 8_4}       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Dict       ):
        lowerCAmelCase_   :				List[str]								= self.image_processing_class(**self.image_processor_dict       )
        # create random PIL videos
        lowerCAmelCase_   :				List[str]								= prepare_video_inputs(self.image_processor_tester    ,			equal_resolution=_A       )
        for video in video_inputs:
          self.assertIsInstance(_A    ,			_A       )
          self.assertIsInstance(video[0]    ,			Image.Image       )

        # Test not batched input
        lowerCAmelCase_   :				int								= image_processing(video_inputs[0]    ,			return_tensors='pt'       ).pixel_values
        self.assertEqual(
            encoded_videos.shape    ,			(
                1,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['height'],
                self.image_processor_tester.crop_size['width'],
            )    ,			)

        # Test batched
        lowerCAmelCase_   :				Tuple								= image_processing(_A    ,			return_tensors='pt'       ).pixel_values
        self.assertEqual(
            encoded_videos.shape    ,			(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['height'],
                self.image_processor_tester.crop_size['width'],
            )    ,			)



      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[Any]       ):
        lowerCAmelCase_   :				List[str]								= self.image_processing_class(**self.image_processor_dict       )
        # create random numpy tensors
        lowerCAmelCase_   :				str								= prepare_video_inputs(self.image_processor_tester    ,			equal_resolution=_A    ,			numpify=_A       )
        for video in video_inputs:
          self.assertIsInstance(_A    ,			_A       )
          self.assertIsInstance(video[0]    ,			np.ndarray       )

        # Test not batched input
        lowerCAmelCase_   :				Optional[int]								= image_processing(video_inputs[0]    ,			return_tensors='pt'       ).pixel_values
        self.assertEqual(
            encoded_videos.shape    ,			(
                1,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['height'],
                self.image_processor_tester.crop_size['width'],
            )    ,			)

        # Test batched
        lowerCAmelCase_   :				List[str]								= image_processing(_A    ,			return_tensors='pt'       ).pixel_values
        self.assertEqual(
            encoded_videos.shape    ,			(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['height'],
                self.image_processor_tester.crop_size['width'],
            )    ,			)





      def      SCREAMING_SNAKE_CASE__ (      self				:      Tuple       ):
        lowerCAmelCase_   :				List[str]								= self.image_processing_class(**self.image_processor_dict       )
        # create random PyTorch tensors
        lowerCAmelCase_   :				Dict								= prepare_video_inputs(self.image_processor_tester    ,			equal_resolution=_A    ,			torchify=_A       )
        for video in video_inputs:
          self.assertIsInstance(_A    ,			_A       )
          self.assertIsInstance(video[0]    ,			torch.Tensor       )

        # Test not batched input
        lowerCAmelCase_   :				List[str]								= image_processing(video_inputs[0]    ,			return_tensors='pt'       ).pixel_values
        self.assertEqual(
            encoded_videos.shape    ,			(
                1,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['height'],
                self.image_processor_tester.crop_size['width'],
            )    ,			)

        # Test batched
        lowerCAmelCase_   :				Optional[int]								= image_processing(_A    ,			return_tensors='pt'       ).pixel_values
        self.assertEqual(
            encoded_videos.shape    ,			(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['height'],
                self.image_processor_tester.crop_size['width'],
            )    ,			)






from __future__ import annotations

from math import pi, sqrt




def       _snake_case	(   lowerCAmelCase							:   float   , lowerCAmelCase							:   float	):
		"""simple docstring"""







		if inductance <= 0:
				raise ValueError("Inductance cannot be 0 or negative"	)

		elif capacitance <= 0:
				raise ValueError("Capacitance cannot be 0 or negative"	)

		else:
				return (
				    "Resonant frequency",
				    float(1 / (2 * pi * (sqrt(inductance * capacitance	)))	),
				)


if __name__ == "__main__":
		import doctest

		doctest.testmod()
