




import random
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():
				import PIL

				from transformers import FlavaImageProcessor
				from transformers.image_utils import PILImageResampling
				from transformers.models.flava.image_processing_flava import (
				    FLAVA_CODEBOOK_MEAN,
				    FLAVA_CODEBOOK_STD,
				    FLAVA_IMAGE_MEAN,
				    FLAVA_IMAGE_STD,
				)
else:
				lowercase_		=							lowercase_		=							lowercase_		=							lowercase_		=							None





class 		A__				(   unittest.TestCase ):






	def __init__(	self				,     lowerCamelCase				,     lowerCamelCase=7				,     lowerCamelCase=3				,     lowerCamelCase=30				,     lowerCamelCase=400				,     lowerCamelCase=True				,     lowerCamelCase=None				,     lowerCamelCase=True				,     lowerCamelCase=None				,     lowerCamelCase=None				,     lowerCamelCase=True				,     lowerCamelCase=1 / 255				,     lowerCamelCase=True				,     lowerCamelCase=FLAVA_IMAGE_MEAN				,     lowerCamelCase=FLAVA_IMAGE_STD				,     lowerCamelCase=14				,     lowerCamelCase=75				,     lowerCamelCase=None				,     lowerCamelCase=16				,     lowerCamelCase=0.3				,     lowerCamelCase=None				,     lowerCamelCase=True				,     lowerCamelCase=None				,     lowerCamelCase=None				,     lowerCamelCase=True				,     lowerCamelCase=None				,     lowerCamelCase=True				,     lowerCamelCase=True				,     lowerCamelCase=FLAVA_CODEBOOK_MEAN				,     lowerCamelCase=FLAVA_CODEBOOK_STD				,     )      ->   str:




						"""simple docstring"""






						__magic_name__					:							Dict		   =							size if size is not None else {'''height''': 224, '''width''': 224}
						__magic_name__					:							int		   =							crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
						__magic_name__					:							Optional[int]		   =							codebook_size if codebook_size is not None else {'''height''': 112, '''width''': 112}
						__magic_name__					:							List[str]		   =							codebook_crop_size if codebook_crop_size is not None else {'''height''': 112, '''width''': 112}

						__magic_name__					:							Union[str, Any]		   =							parent
						__magic_name__					:							Dict		   =							batch_size
						__magic_name__					:							str		   =							num_channels
						__magic_name__					:							Optional[int]		   =							do_resize
						__magic_name__					:							Any		   =							do_rescale
						__magic_name__					:							Tuple		   =							rescale_factor
						__magic_name__					:							Any		   =							min_resolution
						__magic_name__					:							Tuple		   =							max_resolution
						__magic_name__					:							str		   =							size
						__magic_name__					:							Tuple		   =							resample if resample is not None else PILImageResampling.BICUBIC
						__magic_name__					:							Tuple		   =							do_normalize
						__magic_name__					:							Optional[int]		   =							image_mean
						__magic_name__					:							List[str]		   =							image_std
						__magic_name__					:							Tuple		   =							do_center_crop
						__magic_name__					:							Optional[int]		   =							crop_size

						__magic_name__					:							List[str]		   =							input_size_patches
						__magic_name__					:							Optional[int]		   =							total_mask_patches
						__magic_name__					:							List[Any]		   =							mask_group_max_patches
						__magic_name__					:							int		   =							mask_group_min_patches
						__magic_name__					:							List[Any]		   =							mask_group_min_aspect_ratio
						__magic_name__					:							Union[str, Any]		   =							mask_group_max_aspect_ratio

						__magic_name__					:							Any		   =							codebook_do_resize
						__magic_name__					:							Optional[int]		   =							codebook_size
						__magic_name__					:							List[Any]		   =							codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
						__magic_name__					:							Tuple		   =							codebook_do_center_crop
						__magic_name__					:							str		   =							codebook_crop_size
						__magic_name__					:							int		   =							codebook_do_map_pixels
						__magic_name__					:							Union[str, Any]		   =							codebook_do_normalize
						__magic_name__					:							Any		   =							codebook_image_mean
						__magic_name__					:							Union[str, Any]		   =							codebook_image_std






	def  lowercase      (	self						)      ->   str:




						"""simple docstring"""






						return {
						    "image_mean": self.image_mean,
						    "image_std": self.image_std,
						    "do_normalize": self.do_normalize,
						    "do_resize": self.do_resize,
						    "size": self.size,
						    "resample": self.resample,
						    "do_rescale": self.do_rescale,
						    "rescale_factor": self.rescale_factor,
						    "do_center_crop": self.do_center_crop,
						    "crop_size": self.crop_size,
						    "input_size_patches": self.input_size_patches,
						    "total_mask_patches": self.total_mask_patches,
						    "mask_group_max_patches": self.mask_group_max_patches,
						    "mask_group_min_patches": self.mask_group_min_patches,
						    "mask_group_min_aspect_ratio": self.mask_group_min_aspect_ratio,
						    "mask_group_max_aspect_ratio": self.mask_group_min_aspect_ratio,
						    "codebook_do_resize": self.codebook_do_resize,
						    "codebook_size": self.codebook_size,
						    "codebook_resample": self.codebook_resample,
						    "codebook_do_center_crop": self.codebook_do_center_crop,
						    "codebook_crop_size": self.codebook_crop_size,
						    "codebook_do_map_pixels": self.codebook_do_map_pixels,
						    "codebook_do_normalize": self.codebook_do_normalize,
						    "codebook_image_mean": self.codebook_image_mean,
						    "codebook_image_std": self.codebook_image_std,
						}






	def  lowercase      (	self						)      ->   int:




						"""simple docstring"""






						return (self.size["height"], self.size["width"])






	def  lowercase      (	self						)      ->   Dict:




						"""simple docstring"""






						return (
						    (self.input_size_patches, self.input_size_patches)
						    if not isinstance(self.input_size_patches				,     lowerCamelCase						)
						    else self.input_size_patches
						)






	def  lowercase      (	self						)      ->   str:




						"""simple docstring"""






						return (self.codebook_size["height"], self.codebook_size["width"])





@require_torch
@require_vision
class 		A__				(   __SCREAMING_SNAKE_CASE		,     unittest.TestCase ):
	lowerCamelCase__		: Any				    =FlavaImageProcessor if is_vision_available() else None
	lowerCamelCase__		: List[Any]				    =None






	def  lowercase      (	self						)      ->   Tuple:




						"""simple docstring"""






						__magic_name__					:							List[str]		   =							FlavaImageProcessingTester(self						)






	@property
	def  lowercase      (	self						)      ->   Union[str, Any]:




						"""simple docstring"""






						return self.image_processor_tester.prepare_image_processor_dict()






	def  lowercase      (	self						)      ->   int:




						"""simple docstring"""






						__magic_name__					:							str		   =							self.image_processing_class(**self.image_processor_dict						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''image_mean'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''image_std'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''do_normalize'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''do_resize'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''resample'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''crop_size'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''do_center_crop'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''do_rescale'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''rescale_factor'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''masking_generator'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''codebook_do_resize'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''codebook_size'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''codebook_resample'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''codebook_do_center_crop'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''codebook_crop_size'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''codebook_do_map_pixels'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''codebook_do_normalize'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''codebook_image_mean'''						)						)
						self.assertTrue(hasattr(lowerCamelCase				,     '''codebook_image_std'''						)						)






	def  lowercase      (	self						)      ->   Any:




						"""simple docstring"""






						__magic_name__					:							Tuple		   =							self.image_processing_class.from_dict(self.image_processor_dict						)
						self.assertEqual(image_processor.size				,     {'''height''': 224, '''width''': 224}						)
						self.assertEqual(image_processor.crop_size				,     {'''height''': 224, '''width''': 224}						)
						self.assertEqual(image_processor.codebook_size				,     {'''height''': 112, '''width''': 112}						)
						self.assertEqual(image_processor.codebook_crop_size				,     {'''height''': 112, '''width''': 112}						)

						__magic_name__					:							Union[str, Any]		   =							self.image_processing_class.from_dict(
						    self.image_processor_dict				,     size=42				,     crop_size=84				,     codebook_size=33				,     codebook_crop_size=66						)
						self.assertEqual(image_processor.size				,     {'''height''': 42, '''width''': 42}						)
						self.assertEqual(image_processor.crop_size				,     {'''height''': 84, '''width''': 84}						)
						self.assertEqual(image_processor.codebook_size				,     {'''height''': 33, '''width''': 33}						)
						self.assertEqual(image_processor.codebook_crop_size				,     {'''height''': 66, '''width''': 66}						)






	def  lowercase      (	self						)      ->   Union[str, Any]:




						"""simple docstring"""






						pass






	def  lowercase      (	self						)      ->   List[Any]:




						"""simple docstring"""






						__magic_name__					:							str		   =							self.image_processing_class(**self.image_processor_dict						)
						# create random PIL images
						__magic_name__					:							Union[str, Any]		   =							prepare_image_inputs(self.image_processor_tester				,     equal_resolution=lowerCamelCase						)
						for image in image_inputs:
											self.assertIsInstance(lowerCamelCase				,     PIL.Image.Image						)

						# Test not batched input
						__magic_name__					:							Optional[int]		   =							image_processing(image_inputs[0]				,     return_tensors='''pt'''						)

						# Test no bool masked pos
						self.assertFalse('''bool_masked_pos''' in encoded_images						)

						__magic_name__   , __magic_name__					:							Dict		   =							self.image_processor_tester.get_expected_image_size()

						self.assertEqual(
						    encoded_images.pixel_values.shape				,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)				,     )

						# Test batched
						__magic_name__					:							Optional[Any]		   =							image_processing(lowerCamelCase				,     return_tensors='''pt'''						)
						__magic_name__   , __magic_name__					:							Dict		   =							self.image_processor_tester.get_expected_image_size()

						# Test no bool masked pos
						self.assertFalse('''bool_masked_pos''' in encoded_images						)

						self.assertEqual(
						    encoded_images.pixel_values.shape				,     (
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        expected_height,
						        expected_width,
						    )				,     )






	def  lowercase      (	self				,     lowerCamelCase				,     lowerCamelCase						)      ->   Tuple:




						"""simple docstring"""






						__magic_name__					:							Dict		   =							self.image_processing_class(**self.image_processor_dict						)
						# create random tensors
						__magic_name__					:							int		   =							prepare_image_inputs(self.image_processor_tester				,     equal_resolution=lowerCamelCase				,     **lowerCamelCase						)
						for image in image_inputs:
											self.assertIsInstance(lowerCamelCase				,     lowerCamelCase						)

						# Test not batched input
						__magic_name__					:							Dict		   =							image_processing(image_inputs[0]				,     return_tensors='''pt'''						)

						__magic_name__   , __magic_name__					:							int		   =							self.image_processor_tester.get_expected_image_size()
						self.assertEqual(
						    encoded_images.pixel_values.shape				,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)				,     )

						__magic_name__					:							List[str]		   =							image_processing(lowerCamelCase				,     return_image_mask=lowerCamelCase				,     return_tensors='''pt'''						)

						__magic_name__   , __magic_name__					:							Dict		   =							self.image_processor_tester.get_expected_image_size()
						self.assertEqual(
						    encoded_images.pixel_values.shape				,     (
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        expected_height,
						        expected_width,
						    )				,     )

						__magic_name__   , __magic_name__					:							int		   =							self.image_processor_tester.get_expected_mask_size()
						self.assertEqual(
						    encoded_images.bool_masked_pos.shape				,     (
						        self.image_processor_tester.batch_size,
						        expected_height,
						        expected_width,
						    )				,     )

						# Test batched
						__magic_name__					:							List[str]		   =							image_processing(lowerCamelCase				,     return_tensors='''pt'''						).pixel_values

						__magic_name__   , __magic_name__					:							Union[str, Any]		   =							self.image_processor_tester.get_expected_image_size()
						self.assertEqual(
						    encoded_images.shape				,     (
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        expected_height,
						        expected_width,
						    )				,     )

						# Test masking
						__magic_name__					:							int		   =							image_processing(lowerCamelCase				,     return_image_mask=lowerCamelCase				,     return_tensors='''pt'''						)

						__magic_name__   , __magic_name__					:							Optional[Any]		   =							self.image_processor_tester.get_expected_image_size()
						self.assertEqual(
						    encoded_images.pixel_values.shape				,     (
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        expected_height,
						        expected_width,
						    )				,     )

						__magic_name__   , __magic_name__					:							Union[str, Any]		   =							self.image_processor_tester.get_expected_mask_size()
						self.assertEqual(
						    encoded_images.bool_masked_pos.shape				,     (
						        self.image_processor_tester.batch_size,
						        expected_height,
						        expected_width,
						    )				,     )






	def  lowercase      (	self						)      ->   List[Any]:




						"""simple docstring"""






						self._test_call_framework(np.ndarray				,     prepare_kwargs={'''numpify''': True}						)






	def  lowercase      (	self						)      ->   Optional[Any]:




						"""simple docstring"""






						self._test_call_framework(torch.Tensor				,     prepare_kwargs={'''torchify''': True}						)






	def  lowercase      (	self						)      ->   Optional[Any]:




						"""simple docstring"""






						random.seed(1234						)
						__magic_name__					:							int		   =							self.image_processing_class(**self.image_processor_dict						)
						__magic_name__					:							Dict		   =							prepare_image_inputs(self.image_processor_tester				,     equal_resolution=lowerCamelCase				,     torchify=lowerCamelCase						)

						# Test not batched input
						__magic_name__					:							Optional[Any]		   =							image_processing(image_inputs[0]				,     return_image_mask=lowerCamelCase				,     return_tensors='''pt'''						)
						self.assertEqual(encoded_images.bool_masked_pos.sum().item()				,     75						)






	def  lowercase      (	self						)      ->   Tuple:




						"""simple docstring"""






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

						# Test not batched input
						__magic_name__					:							Dict		   =							image_processing(image_inputs[0]				,     return_codebook_pixels=lowerCamelCase				,     return_tensors='''pt'''						)
						__magic_name__   , __magic_name__					:							str		   =							self.image_processor_tester.get_expected_codebook_image_size()
						self.assertEqual(
						    encoded_images.codebook_pixel_values.shape				,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)				,     )

						# Test batched
						__magic_name__					:							Optional[int]		   =							image_processing(lowerCamelCase				,     return_codebook_pixels=lowerCamelCase				,     return_tensors='''pt'''						)
						__magic_name__   , __magic_name__					:							Union[str, Any]		   =							self.image_processor_tester.get_expected_codebook_image_size()
						self.assertEqual(
						    encoded_images.codebook_pixel_values.shape				,     (
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        expected_height,
						        expected_width,
						    )				,     )









def 	UpperCAmelCase_    (	__UpperCamelCase,				__UpperCamelCase	):
    SCREAMING_SNAKE_CASE__								=1.0
    for i in range(1,				r + 1	):
        ret *= (n + 1 - i) / i
    return round(__UpperCamelCase	)



def 	UpperCAmelCase_    (	__UpperCamelCase	):
    return choose(8 + n,				__UpperCamelCase	) + choose(9 + n,				__UpperCamelCase	) - 10



def 	UpperCAmelCase_    (	__UpperCamelCase	):
    return sum(non_bouncy_exact(__UpperCamelCase	) for i in range(1,				n + 1	)	)



def 	UpperCAmelCase_    (	__UpperCamelCase = 100	):
    return non_bouncy_upto(__UpperCamelCase	)


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






