
'''simple docstring'''





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:
      SCREAMING_SNAKE_CASE    =     SCREAMING_SNAKE_CASE    =     SCREAMING_SNAKE_CASE    =     SCREAMING_SNAKE_CASE    =     None






class        UpperCAmelCase_       (						unittest.TestCase							):

 '''simple docstring'''







 def __init__(				self		:     List[Any] ,							snake_case__		:     Optional[int] ,							snake_case__		:     List[str]=7 ,							snake_case__		:     Union[str, Any]=3 ,							snake_case__		:     int=30 ,							snake_case__		:     Optional[int]=4_00 ,							snake_case__		:     Any=True ,							snake_case__		:     Optional[Any]=None ,							snake_case__		:     List[Any]=True ,							snake_case__		:     Dict=None ,							snake_case__		:     Tuple=None ,							snake_case__		:     Union[str, Any]=True ,							snake_case__		:     Tuple=1 / 2_55 ,							snake_case__		:     Any=True ,							snake_case__		:     Optional[Any]=FLAVA_IMAGE_MEAN ,							snake_case__		:     Union[str, Any]=FLAVA_IMAGE_STD ,							snake_case__		:     Optional[int]=14 ,							snake_case__		:     Any=75 ,							snake_case__		:     Dict=None ,							snake_case__		:     Optional[int]=16 ,							snake_case__		:     Tuple=0.3 ,							snake_case__		:     int=None ,							snake_case__		:     str=True ,							snake_case__		:     Tuple=None ,							snake_case__		:     Union[str, Any]=None ,							snake_case__		:     Dict=True ,							snake_case__		:     Union[str, Any]=None ,							snake_case__		:     List[Any]=True ,							snake_case__		:     Dict=True ,							snake_case__		:     Tuple=FLAVA_CODEBOOK_MEAN ,							snake_case__		:     Optional[Any]=FLAVA_CODEBOOK_STD ,							):



   '''simple docstring'''




   UpperCAmelCase__			:				List[Any]												=       size if size is not None else {"height": 2_24, "width": 2_24}
   UpperCAmelCase__			:				Dict												=       crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
   UpperCAmelCase__			:				Optional[int]												=       codebook_size if codebook_size is not None else {"height": 1_12, "width": 1_12}
   UpperCAmelCase__			:				List[str]												=       codebook_crop_size if codebook_crop_size is not None else {"height": 1_12, "width": 1_12}

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

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

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







 def        UpperCamelCase     (				self		:     int   ):



   '''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        UpperCamelCase     (				self		:     Optional[int]   ):



   '''simple docstring'''




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







 def        UpperCamelCase     (				self		:     Dict   ):



   '''simple docstring'''




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







 def        UpperCamelCase     (				self		:     int   ):



   '''simple docstring'''




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






@require_torch
@require_vision
class        UpperCAmelCase_       (						A				,							unittest.TestCase							):

 '''simple docstring'''
 lowercase_				:						Dict				=       FlavaImageProcessor if is_vision_available() else None
 lowercase_				:						Tuple				=       None







 def        UpperCamelCase     (				self		:     List[str]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Any												=       FlavaImageProcessingTester(self   )







 @property
 def        UpperCamelCase     (				self		:     Union[str, Any]   ):



   '''simple docstring'''




   return self.image_processor_tester.prepare_image_processor_dict()







 def        UpperCamelCase     (				self		:     Optional[int]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Dict												=       self.image_processing_class(**self.image_processor_dict   )
   self.assertTrue(hasattr(snake_case__ ,							"image_mean"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"image_std"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"do_normalize"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"do_resize"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"resample"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"crop_size"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"do_center_crop"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"do_rescale"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"rescale_factor"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"masking_generator"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"codebook_do_resize"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"codebook_size"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"codebook_resample"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"codebook_do_center_crop"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"codebook_crop_size"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"codebook_do_map_pixels"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"codebook_do_normalize"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"codebook_image_mean"   )   )
   self.assertTrue(hasattr(snake_case__ ,							"codebook_image_std"   )   )







 def        UpperCamelCase     (				self		:     List[Any]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				int												=       self.image_processing_class.from_dict(self.image_processor_dict   )
   self.assertEqual(image_processor.size ,							{"height": 2_24, "width": 2_24}   )
   self.assertEqual(image_processor.crop_size ,							{"height": 2_24, "width": 2_24}   )
   self.assertEqual(image_processor.codebook_size ,							{"height": 1_12, "width": 1_12}   )
   self.assertEqual(image_processor.codebook_crop_size ,							{"height": 1_12, "width": 1_12}   )

   UpperCAmelCase__			:				Optional[int]												=       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        UpperCamelCase     (				self		:     int   ):



   '''simple docstring'''




   pass







 def        UpperCamelCase     (				self		:     List[str]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Dict												=       self.image_processing_class(**self.image_processor_dict   )
   # create random PIL images
   UpperCAmelCase__			:				Optional[int]												=       prepare_image_inputs(self.image_processor_tester ,							equal_resolution=snake_case__   )
   for image in image_inputs:
     self.assertIsInstance(snake_case__ ,							PIL.Image.Image   )

   # Test not batched input
   UpperCAmelCase__			:				List[Any]												=       image_processing(image_inputs[0] ,							return_tensors="pt"   )

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

   UpperCAmelCase__			:				List[str]												=       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
   UpperCAmelCase__			:				str												=       image_processing(snake_case__ ,							return_tensors="pt"   )
   UpperCAmelCase__			:				List[str]												=       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        UpperCamelCase     (				self		:     Tuple ,							snake_case__		:     Union[str, Any] ,							snake_case__		:     Optional[int]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Optional[int]												=       self.image_processing_class(**self.image_processor_dict   )
   # create random tensors
   UpperCAmelCase__			:				Any												=       prepare_image_inputs(self.image_processor_tester ,							equal_resolution=snake_case__ ,							**snake_case__   )
   for image in image_inputs:
     self.assertIsInstance(snake_case__ ,							snake_case__   )

   # Test not batched input
   UpperCAmelCase__			:				Any												=       image_processing(image_inputs[0] ,							return_tensors="pt"   )

   UpperCAmelCase__			:				Optional[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) ,							)

   UpperCAmelCase__			:				int												=       image_processing(snake_case__ ,							return_image_mask=snake_case__ ,							return_tensors="pt"   )

   UpperCAmelCase__			:				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,
       ) ,							)

   UpperCAmelCase__			:				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
   UpperCAmelCase__			:				Optional[Any]												=       image_processing(snake_case__ ,							return_tensors="pt"   ).pixel_values

   UpperCAmelCase__			:				Optional[int]												=       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
   UpperCAmelCase__			:				Tuple												=       image_processing(snake_case__ ,							return_image_mask=snake_case__ ,							return_tensors="pt"   )

   UpperCAmelCase__			:				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,
       ) ,							)

   UpperCAmelCase__			:				List[str]												=       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        UpperCamelCase     (				self		:     Tuple   ):



   '''simple docstring'''




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







 def        UpperCamelCase     (				self		:     List[Any]   ):



   '''simple docstring'''




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







 def        UpperCamelCase     (				self		:     List[str]   ):



   '''simple docstring'''




   random.seed(12_34   )
   UpperCAmelCase__			:				Dict												=       self.image_processing_class(**self.image_processor_dict   )
   UpperCAmelCase__			:				List[Any]												=       prepare_image_inputs(self.image_processor_tester ,							equal_resolution=snake_case__ ,							torchify=snake_case__   )

   # Test not batched input
   UpperCAmelCase__			:				Any												=       image_processing(image_inputs[0] ,							return_image_mask=snake_case__ ,							return_tensors="pt"   )
   self.assertEqual(encoded_images.bool_masked_pos.sum().item() ,							75   )







 def        UpperCamelCase     (				self		:     Optional[int]   ):



   '''simple docstring'''




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

   # Test not batched input
   UpperCAmelCase__			:				List[str]												=       image_processing(image_inputs[0] ,							return_codebook_pixels=snake_case__ ,							return_tensors="pt"   )
   UpperCAmelCase__			:				Optional[Any]												=       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
   UpperCAmelCase__			:				Union[str, Any]												=       image_processing(snake_case__ ,							return_codebook_pixels=snake_case__ ,							return_tensors="pt"   )
   UpperCAmelCase__			:				Tuple												=       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,
       ) ,							)





'''simple docstring'''





from doctest import testmod
from math import sqrt







def snake_case_    (				lowercase__		):
  UpperCAmelCase__			:				list[int]												=       []
  if num < 1:
    return facs
  facs.append(1		)
  if num == 1:
    return facs
  facs.append(lowercase__		)
  for i in range(2      ,					int(sqrt(lowercase__		)		) + 1		):
    if num % i == 0:  # If i is a factor of num
      facs.append(lowercase__		)
      UpperCAmelCase__			:				Tuple												=       num // i  # num//i is the other factor of num
      if d != i:  # If d and i are distinct
        facs.append(lowercase__		)  # we have found another factor
  facs.sort()
  return facs


if __name__ == "__main__":
      testmod(name="""factors_of_a_number""", verbose=True)



