





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




					def __init__(		self				,						lowerCAmelCase_				,						lowerCAmelCase_=7				,						lowerCAmelCase_=3				,						lowerCAmelCase_=18				,						lowerCAmelCase_=30				,						lowerCAmelCase_=400				,						lowerCAmelCase_=True				,						lowerCAmelCase_=None				,						lowerCAmelCase_=True				,						lowerCAmelCase_=None				,						)		->							List[Any]:
										_snake_case									=				size if size is not None else {'shortest_edge': 20}
										_snake_case									=				crop_size if crop_size is not None else {'height': 18, 'width': 18}
										_snake_case									=				parent
										_snake_case									=				batch_size
										_snake_case									=				num_channels
										_snake_case									=				image_size
										_snake_case									=				min_resolution
										_snake_case									=				max_resolution
										_snake_case									=				do_resize
										_snake_case									=				size
										_snake_case									=				do_center_crop
										_snake_case									=				crop_size






					def 	lowerCAmelCase			(		self  )		->							Tuple:
										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 			UpperCamelCase_		(  _lowerCamelCase							,  unittest.TestCase					):
					lowerCAmelCase_							=	MobileNetVaImageProcessor if is_vision_available() else None




					def 	lowerCAmelCase			(		self  )		->							str:
										_snake_case									=				MobileNetVaImageProcessingTester(self  )




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




					def 	lowerCAmelCase			(		self  )		->							List[str]:
										_snake_case									=				self.image_processing_class(**self.image_processor_dict  )
										self.assertTrue(hasattr(lowerCAmelCase_				,						'do_resize'  )  )
										self.assertTrue(hasattr(lowerCAmelCase_				,						'size'  )  )
										self.assertTrue(hasattr(lowerCAmelCase_				,						'do_center_crop'  )  )
										self.assertTrue(hasattr(lowerCAmelCase_				,						'crop_size'  )  )




					def 	lowerCAmelCase			(		self  )		->							int:
										_snake_case									=				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}  )

										_snake_case									=				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 	lowerCAmelCase			(		self  )		->							Tuple:
										pass




					def 	lowerCAmelCase			(		self  )		->							Dict:
										# Initialize image_processing
										_snake_case									=				self.image_processing_class(**self.image_processor_dict  )
										# create random PIL images
										_snake_case									=				prepare_image_inputs(self.image_processor_tester				,						equal_resolution=lowerCAmelCase_  )
										for image in image_inputs:
															self.assertIsInstance(lowerCAmelCase_				,						Image.Image  )

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




					def 	lowerCAmelCase			(		self  )		->							str:
										# Initialize image_processing
										_snake_case									=				self.image_processing_class(**self.image_processor_dict  )
										# create random numpy tensors
										_snake_case									=				prepare_image_inputs(self.image_processor_tester				,						equal_resolution=lowerCAmelCase_				,						numpify=lowerCAmelCase_  )
										for image in image_inputs:
															self.assertIsInstance(lowerCAmelCase_				,						np.ndarray  )

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






					def 	lowerCAmelCase			(		self  )		->							Dict:
										# Initialize image_processing
										_snake_case									=				self.image_processing_class(**self.image_processor_dict  )
										# create random PyTorch tensors
										_snake_case									=				prepare_image_inputs(self.image_processor_tester				,						equal_resolution=lowerCAmelCase_				,						torchify=lowerCAmelCase_  )
										for image in image_inputs:
															self.assertIsInstance(lowerCAmelCase_				,						torch.Tensor  )

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










def 						lowerCamelCase__     (     UpperCamelCase__			:       list[int]       ,    UpperCamelCase__			:       int						)			-> bool:



					'''simple docstring'''




					_snake_case									=				len(UpperCamelCase__						)
					_snake_case									=				[[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						):
										_snake_case									=				True

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

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



