

'''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      lowercase_      (unittest.TestCase ):




  """simple docstring"""




  def __init__( self  :	Tuple   ,lowercase__  :	Dict   ,lowercase__  :	Union[str, Any]=7   ,lowercase__  :	List[Any]=3   ,lowercase__  :	List[Any]=3_0   ,lowercase__  :	List[Any]=4_0_0   ,lowercase__  :	List[str]=True   ,lowercase__  :	Tuple=None   ,lowercase__  :	Optional[Any]=0.9   ,lowercase__  :	List[str]=None   ,lowercase__  :	str=True   ,lowercase__  :	Dict=[0.5, 0.5, 0.5]   ,lowercase__  :	Dict=[0.5, 0.5, 0.5]   ,):
   __lowercase				    =					size if size is not None else {'''shortest_edge''': 3_0}
   __lowercase				    =					crop_size if crop_size is not None else {'''height''': 3_0, '''width''': 3_0}
   __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    SCREAMING_SNAKE_CASE ( self  :	str     ):
   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      lowercase_      (lowerCamelCase__							,			unittest.TestCase ):




  """simple docstring"""




  SCREAMING_SNAKE_CASE       :    Optional[Any]							     =     PoolFormerImageProcessor if is_vision_available() else None






  def    SCREAMING_SNAKE_CASE ( self  :	int     ):
   __lowercase				    =					PoolFormerImageProcessingTester(self     )






  @property
  def    SCREAMING_SNAKE_CASE ( self  :	Dict     ):
   return self.image_processor_tester.prepare_image_processor_dict()






  def    SCREAMING_SNAKE_CASE ( self  :	Any     ):
   __lowercase				    =					self.image_processing_class(**self.image_processor_dict     )
   self.assertTrue(hasattr(lowercase__   ,'''do_resize_and_center_crop'''     )     )
   self.assertTrue(hasattr(lowercase__   ,'''size'''     )     )
   self.assertTrue(hasattr(lowercase__   ,'''crop_pct'''     )     )
   self.assertTrue(hasattr(lowercase__   ,'''do_normalize'''     )     )
   self.assertTrue(hasattr(lowercase__   ,'''image_mean'''     )     )
   self.assertTrue(hasattr(lowercase__   ,'''image_std'''     )     )






  def    SCREAMING_SNAKE_CASE ( self  :	Optional[int]     ):
   __lowercase				    =					self.image_processing_class.from_dict(self.image_processor_dict     )
   self.assertEqual(image_processor.size   ,{'''shortest_edge''': 3_0}     )
   self.assertEqual(image_processor.crop_size   ,{'''height''': 3_0, '''width''': 3_0}     )

   __lowercase				    =					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  :	int     ):
   pass






  def    SCREAMING_SNAKE_CASE ( self  :	Optional[Any]     ):
   # Initialize image_processing
   __lowercase				    =					self.image_processing_class(**self.image_processor_dict     )
   # create random PIL images
   __lowercase				    =					prepare_image_inputs(self.image_processor_tester   ,equal_resolution=lowercase__     )
   for image in image_inputs:
    self.assertIsInstance(lowercase__   ,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(lowercase__   ,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    SCREAMING_SNAKE_CASE ( self  :	int     ):
   # Initialize image_processing
   __lowercase				    =					self.image_processing_class(**self.image_processor_dict     )
   # create random numpy tensors
   __lowercase				    =					prepare_image_inputs(self.image_processor_tester   ,equal_resolution=lowercase__   ,numpify=lowercase__     )
   for image in image_inputs:
    self.assertIsInstance(lowercase__   ,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(lowercase__   ,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    SCREAMING_SNAKE_CASE ( self  :	Optional[Any]     ):
   # Initialize image_processing
   __lowercase				    =					self.image_processing_class(**self.image_processor_dict     )
   # create random PyTorch tensors
   __lowercase				    =					prepare_image_inputs(self.image_processor_tester   ,equal_resolution=lowercase__   ,torchify=lowercase__     )
   for image in image_inputs:
    self.assertIsInstance(lowercase__   ,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(lowercase__   ,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     a     (		lowerCamelCase_						,  lowerCamelCase_							):






				'''simple docstring'''
				lowercase__  					=     len(lowerCamelCase_							)
				lowercase__  					=     [[False] * (required_sum + 1) for _ in range(arr_len + 1							)]

				# for each arr value, a sum of zero(0) can be formed by not taking any element
				# hence True/1
				for i in range(arr_len + 1							):
								lowercase__  					=     True

				# sum is not zero and set is empty then false
				for i in range(1						,  required_sum + 1							):
								lowercase__  					=     False

				for i in range(1						,  arr_len + 1							):
								for j in range(1						,  required_sum + 1							):
												if arr[i - 1] > j:
																lowercase__  					=     subset[i - 1][j]
												if arr[i - 1] <= j:
																lowercase__  					=     subset[i - 1][j] or subset[i - 1][j - arr[i - 1]]

				return subset[arr_len][required_sum]


if __name__ == "__main__":
							import doctest

							doctest.testmod()




