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


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import BlipImageProcessor




class  __lowerCAmelCase	(							unittest.TestCase    ):



 '''simple docstring'''

 def __init__(      self							:		Tuple							,      lowerCamelCase							:		List[Any]							,      lowerCamelCase							:		Optional[Any]=7							,      lowerCamelCase							:		Union[str, Any]=3							,      lowerCamelCase							:		Dict=1_8							,      lowerCamelCase							:		Optional[Any]=3_0							,      lowerCamelCase							:		Tuple=4_0_0							,      lowerCamelCase							:		Tuple=True							,      lowerCamelCase							:		Any=None							,      lowerCamelCase							:		Tuple=True							,      lowerCamelCase							:		Any=False							,      lowerCamelCase							:		Dict=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]							,      lowerCamelCase							:		Optional[int]=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]							,      lowerCamelCase							:		Dict=True							,      )			->				List[Any]:
        _UpperCamelCase  :							Any	    =	size if size is not None else {'height': 2_0, 'width': 2_0}
        _UpperCamelCase  :							Tuple	    =	parent
        _UpperCamelCase  :							List[str]	    =	batch_size
        _UpperCamelCase  :							Optional[Any]	    =	num_channels
        _UpperCamelCase  :							Optional[Any]	    =	image_size
        _UpperCamelCase  :							int	    =	min_resolution
        _UpperCamelCase  :							int	    =	max_resolution
        _UpperCamelCase  :							Tuple	    =	do_resize
        _UpperCamelCase  :							Any	    =	size
        _UpperCamelCase  :							Union[str, Any]	    =	do_normalize
        _UpperCamelCase  :							Optional[Any]	    =	image_mean
        _UpperCamelCase  :							int	    =	image_std
        _UpperCamelCase  :							List[Any]	    =	do_pad
        _UpperCamelCase  :							str	    =	do_convert_rgb

 def        __snake_case       (      self							:		Optional[Any]	)			->				Union[str, Any]:
        return {
            "do_resize": self.do_resize,
            "size": self.size,
            "do_normalize": self.do_normalize,
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_convert_rgb": self.do_convert_rgb,
            "do_pad": self.do_pad,
        }

 def        __snake_case       (      self							:		Union[str, Any]							,      lowerCamelCase							:		Tuple=False							,      lowerCamelCase							:		List[Any]=False							,      lowerCamelCase							:		List[Any]=False	)			->				List[Any]:
        assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

        if equal_resolution:
               _UpperCamelCase  :							List[Any]	    =	[]
               for i in range(self.batch_size	):
                      image_inputs.append(
                          np.random.randint(
                              2_5_5							,      size=(self.num_channels, self.max_resolution, self.max_resolution)							,      dtype=np.uinta	)	)
        else:
               _UpperCamelCase  :							str	    =	[]
               for i in range(self.batch_size	):
                      _UpperCamelCase    ,   _UpperCamelCase  :							Tuple	    =	np.random.choice(np.arange(self.min_resolution							,      self.max_resolution	)							,      2	)
                      image_inputs.append(np.random.randint(2_5_5							,      size=(self.num_channels, width, height)							,      dtype=np.uinta	)	)

        if not numpify and not torchify:
               # PIL expects the channel dimension as last dimension
               _UpperCamelCase  :							Optional[int]	    =	[Image.fromarray(np.moveaxis(lowerCamelCase							,      0							,      -1	)	) for x in image_inputs]

        if torchify:
               _UpperCamelCase  :							Any	    =	[torch.from_numpy(lowerCamelCase	) for x in image_inputs]

        return image_inputs







@require_torch
@require_vision
class  __lowerCAmelCase	(							a_,						unittest.TestCase    ):



 '''simple docstring'''
 _lowerCamelCase    :						Tuple					     =			BlipImageProcessor if is_vision_available() else None

 def        __snake_case       (      self							:		List[Any]	)			->				List[str]:
        _UpperCamelCase  :							Dict	    =	BlipImageProcessingTester(self	)

 @property
 def        __snake_case       (      self							:		int	)			->				str:
        return self.image_processor_tester.prepare_image_processor_dict()

 def        __snake_case       (      self							:		Tuple	)			->				Optional[int]:
        _UpperCamelCase  :							Any	    =	self.image_processing_class(**self.image_processor_dict	)
        self.assertTrue(hasattr(lowerCamelCase							,      'do_resize'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'size'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'do_normalize'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'image_mean'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'image_std'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'do_convert_rgb'	)	)

 def        __snake_case       (      self							:		str	)			->				Optional[Any]:
        pass

 def        __snake_case       (      self							:		Optional[int]	)			->				Optional[Any]:
        # Initialize image_processor
        _UpperCamelCase  :							int	    =	self.image_processing_class(**self.image_processor_dict	)
        # create random PIL images
        _UpperCamelCase  :							Union[str, Any]	    =	self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase	)
        for image in image_inputs:
               self.assertIsInstance(lowerCamelCase							,      Image.Image	)

        # Test not batched input
        _UpperCamelCase  :							Union[str, Any]	    =	image_processor(image_inputs[0]							,      return_tensors='pt'	).pixel_values
        self.assertEqual(
            encoded_images.shape							,      (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size['height'],
                self.image_processor_tester.size['width'],
            )							,      )

        # Test batched
        _UpperCamelCase  :							List[Any]	    =	image_processor(lowerCamelCase							,      return_tensors='pt'	).pixel_values
        self.assertEqual(
            encoded_images.shape							,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size['height'],
                self.image_processor_tester.size['width'],
            )							,      )

 def        __snake_case       (      self							:		str	)			->				Union[str, Any]:
        # Initialize image_processor
        _UpperCamelCase  :							Optional[int]	    =	self.image_processing_class(**self.image_processor_dict	)
        # create random numpy tensors
        _UpperCamelCase  :							List[Any]	    =	self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase							,      numpify=lowerCamelCase	)
        for image in image_inputs:
               self.assertIsInstance(lowerCamelCase							,      np.ndarray	)

        # Test not batched input
        _UpperCamelCase  :							str	    =	image_processor(image_inputs[0]							,      return_tensors='pt'	).pixel_values
        self.assertEqual(
            encoded_images.shape							,      (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size['height'],
                self.image_processor_tester.size['width'],
            )							,      )

        # Test batched
        _UpperCamelCase  :							Tuple	    =	image_processor(lowerCamelCase							,      return_tensors='pt'	).pixel_values
        self.assertEqual(
            encoded_images.shape							,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size['height'],
                self.image_processor_tester.size['width'],
            )							,      )

 def        __snake_case       (      self							:		str	)			->				List[str]:
        # Initialize image_processor
        _UpperCamelCase  :							Optional[Any]	    =	self.image_processing_class(**self.image_processor_dict	)
        # create random PyTorch tensors
        _UpperCamelCase  :							int	    =	self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase							,      torchify=lowerCamelCase	)
        for image in image_inputs:
               self.assertIsInstance(lowerCamelCase							,      torch.Tensor	)

        # Test not batched input
        _UpperCamelCase  :							Optional[int]	    =	image_processor(image_inputs[0]							,      return_tensors='pt'	).pixel_values
        self.assertEqual(
            encoded_images.shape							,      (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size['height'],
                self.image_processor_tester.size['width'],
            )							,      )

        # Test batched
        _UpperCamelCase  :							Any	    =	image_processor(lowerCamelCase							,      return_tensors='pt'	).pixel_values
        self.assertEqual(
            encoded_images.shape							,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size['height'],
                self.image_processor_tester.size['width'],
            )							,      )







@require_torch
@require_vision
class  __lowerCAmelCase	(							a_,						unittest.TestCase    ):



 '''simple docstring'''
 _lowerCamelCase    :						Optional[Any]					     =			BlipImageProcessor if is_vision_available() else None

 def        __snake_case       (      self							:		Tuple	)			->				Optional[int]:
        _UpperCamelCase  :							Any	    =	BlipImageProcessingTester(self							,      num_channels=4	)
        _UpperCamelCase  :							Tuple	    =	3

 @property
 def        __snake_case       (      self							:		Union[str, Any]	)			->				int:
        return self.image_processor_tester.prepare_image_processor_dict()

 def        __snake_case       (      self							:		Optional[int]	)			->				Optional[Any]:
        _UpperCamelCase  :							Dict	    =	self.image_processing_class(**self.image_processor_dict	)
        self.assertTrue(hasattr(lowerCamelCase							,      'do_resize'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'size'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'do_normalize'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'image_mean'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'image_std'	)	)
        self.assertTrue(hasattr(lowerCamelCase							,      'do_convert_rgb'	)	)

 def        __snake_case       (      self							:		Tuple	)			->				Any:
        pass

 def        __snake_case       (      self							:		Optional[int]	)			->				Union[str, Any]:
        # Initialize image_processor
        _UpperCamelCase  :							Any	    =	self.image_processing_class(**self.image_processor_dict	)
        # create random PIL images
        _UpperCamelCase  :							str	    =	self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase	)
        for image in image_inputs:
               self.assertIsInstance(lowerCamelCase							,      Image.Image	)

        # Test not batched input
        _UpperCamelCase  :							int	    =	image_processor(image_inputs[0]							,      return_tensors='pt'	).pixel_values
        self.assertEqual(
            encoded_images.shape							,      (
                1,
                self.expected_encoded_image_num_channels,
                self.image_processor_tester.size['height'],
                self.image_processor_tester.size['width'],
            )							,      )

        # Test batched
        _UpperCamelCase  :							List[str]	    =	image_processor(lowerCamelCase							,      return_tensors='pt'	).pixel_values
        self.assertEqual(
            encoded_images.shape							,      (
                self.image_processor_tester.batch_size,
                self.expected_encoded_image_num_channels,
                self.image_processor_tester.size['height'],
                self.image_processor_tester.size['width'],
            )							,      )




def SCREAMING_SNAKE_CASE					(  lowercase_:						int					):
       return n * (2 * n - 1)


def SCREAMING_SNAKE_CASE					(  lowercase_:						int					):
       _UpperCamelCase  :							str	    =	(1 + 24 * n) ** 0.5
       return ((1 + root) / 6) % 1 == 0


def SCREAMING_SNAKE_CASE					(  lowercase_:						int = 144					):
       _UpperCamelCase  :							Optional[Any]	    =	start
       _UpperCamelCase  :							List[str]	    =	hexagonal_num(lowercase_					)
       while not is_pentagonal(lowercase_					):
              n += 1
              _UpperCamelCase  :							Optional[int]	    =	hexagonal_num(lowercase_					)
       return num


if __name__ == "__main__":
 print(f'''{solution()} = ''')



