


'''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_image_inputs


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import PoolFormerImageProcessor
class     __lowerCAmelCase		(unittest.TestCase	):





      '''simple docstring'''






      def __init__(self       :       Union[str, Any]  ,		UpperCamelCase       :       Union[str, Any]  ,		UpperCamelCase       :       int=7  ,		UpperCamelCase       :       Optional[int]=3  ,		UpperCamelCase       :       Union[str, Any]=30  ,		UpperCamelCase       :       Optional[int]=400  ,		UpperCamelCase       :       int=True  ,		UpperCamelCase       :       List[Any]=None  ,		UpperCamelCase       :       int=0.9  ,		UpperCamelCase       :       Optional[Any]=None  ,		UpperCamelCase       :       Any=True  ,		UpperCamelCase       :       int=[0.5, 0.5, 0.5]  ,		UpperCamelCase       :       Tuple=[0.5, 0.5, 0.5]  ,		):

             '''simple docstring'''







             lowercase__      =					size if size is not None else {'''shortest_edge''': 30}
             lowercase__      =					crop_size if crop_size is not None else {'''height''': 30, '''width''': 30}
             lowercase__      =					parent
             lowercase__      =					batch_size
             lowercase__      =					num_channels
             lowercase__      =					min_resolution
             lowercase__      =					max_resolution
             lowercase__      =					do_resize_and_center_crop
             lowercase__      =					size
             lowercase__      =					crop_pct
             lowercase__      =					crop_size
             lowercase__      =					do_normalize
             lowercase__      =					image_mean
             lowercase__      =					image_std






      def  UpperCamelCase__						(self       :       List[Any]					):

             '''simple docstring'''







             return {
                 "size": self.size,
                 "do_resize_and_center_crop": self.do_resize_and_center_crop,
                 "crop_pct": self.crop_pct,
                 "crop_size": self.crop_size,
                 "do_normalize": self.do_normalize,
                 "image_mean": self.image_mean,
                 "image_std": self.image_std,
             }






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





      '''simple docstring'''






      lowerCAmelCase__   :	int       =				PoolFormerImageProcessor if is_vision_available() else None



      def  UpperCamelCase__						(self       :       List[Any]					):

             '''simple docstring'''







             lowercase__      =					PoolFormerImageProcessingTester(self					)



      @property
      def  UpperCamelCase__						(self       :       int					):

             '''simple docstring'''







             return self.image_processor_tester.prepare_image_processor_dict()



      def  UpperCamelCase__						(self       :       int					):

             '''simple docstring'''







             lowercase__      =					self.image_processing_class(**self.image_processor_dict					)
             self.assertTrue(hasattr(UpperCamelCase  ,		'''do_resize_and_center_crop'''					)					)
             self.assertTrue(hasattr(UpperCamelCase  ,		'''size'''					)					)
             self.assertTrue(hasattr(UpperCamelCase  ,		'''crop_pct'''					)					)
             self.assertTrue(hasattr(UpperCamelCase  ,		'''do_normalize'''					)					)
             self.assertTrue(hasattr(UpperCamelCase  ,		'''image_mean'''					)					)
             self.assertTrue(hasattr(UpperCamelCase  ,		'''image_std'''					)					)



      def  UpperCamelCase__						(self       :       List[Any]					):

             '''simple docstring'''







             lowercase__      =					self.image_processing_class.from_dict(self.image_processor_dict					)
             self.assertEqual(image_processor.size  ,		{'''shortest_edge''': 30}					)
             self.assertEqual(image_processor.crop_size  ,		{'''height''': 30, '''width''': 30}					)

             lowercase__      =					self.image_processing_class.from_dict(self.image_processor_dict  ,		size=42  ,		crop_size=84					)
             self.assertEqual(image_processor.size  ,		{'''shortest_edge''': 42}					)
             self.assertEqual(image_processor.crop_size  ,		{'''height''': 84, '''width''': 84}					)



      def  UpperCamelCase__						(self       :       List[str]					):

             '''simple docstring'''







             pass



      def  UpperCamelCase__						(self       :       Dict					):

             '''simple docstring'''







             lowercase__      =					self.image_processing_class(**self.image_processor_dict					)
             # create random PIL images
             lowercase__      =					prepare_image_inputs(self.image_processor_tester  ,		equal_resolution=UpperCamelCase					)
             for image in image_inputs:
                    self.assertIsInstance(UpperCamelCase  ,		Image.Image					)

             # Test not batched input
             lowercase__      =					image_processing(image_inputs[0]  ,		return_tensors='''pt'''					).pixel_values

             self.assertEqual(
                 encoded_images.shape  ,		(
                     1,
                     self.image_processor_tester.num_channels,
                     self.image_processor_tester.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)

             # Test batched
             lowercase__      =					image_processing(UpperCamelCase  ,		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.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)



      def  UpperCamelCase__						(self       :       int					):

             '''simple docstring'''







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

             # Test not batched input
             lowercase__      =					image_processing(image_inputs[0]  ,		return_tensors='''pt'''					).pixel_values
             self.assertEqual(
                 encoded_images.shape  ,		(
                     1,
                     self.image_processor_tester.num_channels,
                     self.image_processor_tester.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)

             # Test batched
             lowercase__      =					image_processing(UpperCamelCase  ,		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.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)






      def  UpperCamelCase__						(self       :       Any					):

             '''simple docstring'''







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

             # Test not batched input
             lowercase__      =					image_processing(image_inputs[0]  ,		return_tensors='''pt'''					).pixel_values
             self.assertEqual(
                 encoded_images.shape  ,		(
                     1,
                     self.image_processor_tester.num_channels,
                     self.image_processor_tester.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)

             # Test batched
             lowercase__      =					image_processing(UpperCamelCase  ,		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.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )  ,		)








'''simple docstring'''

def _SCREAMING_SNAKE_CASE (A = 1_000			)			->			int:






       """simple docstring"""







       return sum(2 * a * ((a - 1) // 2) for a in range(3    ,					n + 1			)			)


if __name__ == "__main__":
 print(solution())




