






'''simple docstring'''





def __UpperCAmelCase   (					A					:			list[int]			,       A					:			int		)    ->   bool:
			UpperCAmelCase_      :       Union[str, Any]          =       len(A		)
			UpperCAmelCase_      :       Tuple          =       [[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		):
						UpperCAmelCase_      :       Optional[Any]          =       True

			# sum is not zero and set is empty then false
			for i in range(1			,       required_sum + 1		):
						UpperCAmelCase_      :       Union[str, Any]          =       False

			for i in range(1			,       arr_len + 1		):
						for j in range(1			,       required_sum + 1		):
									if arr[i - 1] > j:
												UpperCAmelCase_      :       List[Any]          =       subset[i - 1][j]
									if arr[i - 1] <= j:
												UpperCAmelCase_      :       Any          =       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()










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


class  snake_case__      (					unittest.TestCase):




					def __init__(  self  :		Optional[Any]				, _A  :		int				, _A  :		List[Any]=7				, _A  :		Tuple=3				, _A  :		int=18				, _A  :		Union[str, Any]=30				, _A  :		Any=4_00				, _A  :		List[Any]=True				, _A  :		Optional[int]=None				, _A  :		Optional[Any]=True				, _A  :		Union[str, Any]=None				, )    ->							Optional[int]:
								UpperCAmelCase_      :       Optional[Any]          =       size if size is not None else {'''shortest_edge''': 20}
								UpperCAmelCase_      :       Dict          =       crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
								UpperCAmelCase_      :       List[Any]          =       parent
								UpperCAmelCase_      :       List[Any]          =       batch_size
								UpperCAmelCase_      :       Optional[Any]          =       num_channels
								UpperCAmelCase_      :       Optional[Any]          =       image_size
								UpperCAmelCase_      :       Union[str, Any]          =       min_resolution
								UpperCAmelCase_      :       List[str]          =       max_resolution
								UpperCAmelCase_      :       Union[str, Any]          =       do_resize
								UpperCAmelCase_      :       Any          =       size
								UpperCAmelCase_      :       Union[str, Any]          =       do_center_crop
								UpperCAmelCase_      :       Any          =       crop_size





					def 		A      (  self  :		List[Any]      )    ->							List[Any]:
								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_center_crop": self.do_center_crop,
								    "crop_size": self.crop_size,
								}






@require_torch
@require_vision
class  snake_case__      (					UpperCamelCase     ,				unittest.TestCase):
					a_        =					MobileNetVaImageProcessor if is_vision_available() else None




					def 		A      (  self  :		List[Any]      )    ->							List[str]:
								UpperCAmelCase_      :       Dict          =       MobileNetVaImageProcessingTester(self      )




					@property
					def 		A      (  self  :		Optional[Any]      )    ->							Any:
								return self.image_processor_tester.prepare_image_processor_dict()




					def 		A      (  self  :		List[str]      )    ->							Dict:
								UpperCAmelCase_      :       int          =       self.image_processing_class(**self.image_processor_dict      )
								self.assertTrue(hasattr(_A				, '''do_resize'''      )      )
								self.assertTrue(hasattr(_A				, '''size'''      )      )
								self.assertTrue(hasattr(_A				, '''do_center_crop'''      )      )
								self.assertTrue(hasattr(_A				, '''crop_size'''      )      )




					def 		A      (  self  :		Tuple      )    ->							Optional[int]:
								UpperCAmelCase_      :       Any          =       self.image_processing_class.from_dict(self.image_processor_dict      )
								self.assertEqual(image_processor.size				, {'''shortest_edge''': 20}      )
								self.assertEqual(image_processor.crop_size				, {'''height''': 18, '''width''': 18}      )

								UpperCAmelCase_      :       List[str]          =       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 		A      (  self  :		int      )    ->							List[str]:
								pass




					def 		A      (  self  :		List[Any]      )    ->							Optional[Any]:
								# Initialize image_processing
								UpperCAmelCase_      :       List[Any]          =       self.image_processing_class(**self.image_processor_dict      )
								# create random PIL images
								UpperCAmelCase_      :       Optional[int]          =       prepare_image_inputs(self.image_processor_tester				, equal_resolution=_A      )
								for image in image_inputs:
											self.assertIsInstance(_A				, Image.Image      )

								# Test not batched input
								UpperCAmelCase_      :       Union[str, Any]          =       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
								UpperCAmelCase_      :       List[Any]          =       image_processing(_A				, 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      (  self  :		str      )    ->							List[str]:
								# Initialize image_processing
								UpperCAmelCase_      :       Tuple          =       self.image_processing_class(**self.image_processor_dict      )
								# create random numpy tensors
								UpperCAmelCase_      :       Any          =       prepare_image_inputs(self.image_processor_tester				, equal_resolution=_A				, numpify=_A      )
								for image in image_inputs:
											self.assertIsInstance(_A				, np.ndarray      )

								# Test not batched input
								UpperCAmelCase_      :       str          =       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
								UpperCAmelCase_      :       List[Any]          =       image_processing(_A				, 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      (  self  :		Optional[int]      )    ->							Dict:
								# Initialize image_processing
								UpperCAmelCase_      :       Dict          =       self.image_processing_class(**self.image_processor_dict      )
								# create random PyTorch tensors
								UpperCAmelCase_      :       Union[str, Any]          =       prepare_image_inputs(self.image_processor_tester				, equal_resolution=_A				, torchify=_A      )
								for image in image_inputs:
											self.assertIsInstance(_A				, torch.Tensor      )

								# Test not batched input
								UpperCAmelCase_      :       Any          =       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
								UpperCAmelCase_      :       List[str]          =       image_processing(_A				, 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'''],
								    )				, )


