

"""simple docstring"""




import json
import os
import tempfile

from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available


if is_torch_available():
      import numpy as np
      import torch

if is_vision_available():
      from PIL import Image
def 					lowerCAmelCase  (   __UpperCamelCase							,      __UpperCamelCase=False							,      __UpperCamelCase=False							,      __UpperCamelCase=False ):
 '''simple docstring'''





 assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

 UpperCAmelCase__   :					Tuple   				=   []
 for i in range(image_processor_tester.batch_size ):
  if equal_resolution:
   UpperCAmelCase__   :					Any   				=   image_processor_tester.max_resolution
  else:
   # To avoid getting image width/height 0
   UpperCAmelCase__   :					int   				=   image_processor_tester.min_resolution
   if getattr(__UpperCamelCase							,      """size_divisor"""							,      __UpperCamelCase ):
    # If `size_divisor` is defined, the image needs to have width/size >= `size_divisor`
    UpperCAmelCase__   :					List[Any]   				=   max(image_processor_tester.size_divisor							,      __UpperCamelCase )
   UpperCAmelCase__				, UpperCAmelCase__   :					Tuple   				=   np.random.choice(np.arange(__UpperCamelCase							,      image_processor_tester.max_resolution )							,      2 )
  image_inputs.append(
      np.random.randint(255							,      size=(image_processor_tester.num_channels, width, height)							,      dtype=np.uinta ) )

 if not numpify and not torchify:
  # PIL expects the channel dimension as last dimension
  UpperCAmelCase__   :					Tuple   				=   [Image.fromarray(np.moveaxis(__UpperCamelCase							,      0							,      -1 ) ) for image in image_inputs]

 if torchify:
  UpperCAmelCase__   :					Optional[int]   				=   [torch.from_numpy(__UpperCamelCase ) for image in image_inputs]

 return image_inputs
def 					lowerCAmelCase  (   __UpperCamelCase							,      __UpperCamelCase=10							,      __UpperCamelCase=10							,      __UpperCamelCase=False							,      __UpperCamelCase=False ):
 '''simple docstring'''





 UpperCAmelCase__   :					Dict   				=   []
 for i in range(image_processor_tester.num_frames ):
  video.append(np.random.randint(255							,      size=(image_processor_tester.num_channels, width, height)							,      dtype=np.uinta ) )

 if not numpify and not torchify:
  # PIL expects the channel dimension as last dimension
  UpperCAmelCase__   :					Union[str, Any]   				=   [Image.fromarray(np.moveaxis(__UpperCamelCase							,      0							,      -1 ) ) for frame in video]

 if torchify:
  UpperCAmelCase__   :					str   				=   [torch.from_numpy(__UpperCamelCase ) for frame in video]

 return video
def 					lowerCAmelCase  (   __UpperCamelCase							,      __UpperCamelCase=False							,      __UpperCamelCase=False							,      __UpperCamelCase=False ):
 '''simple docstring'''





 assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

 UpperCAmelCase__   :					List[Any]   				=   []
 for i in range(image_processor_tester.batch_size ):
  if equal_resolution:
   UpperCAmelCase__   :					Tuple   				=   image_processor_tester.max_resolution
  else:
   UpperCAmelCase__				, UpperCAmelCase__   :					str   				=   np.random.choice(
       np.arange(image_processor_tester.min_resolution							,      image_processor_tester.max_resolution )							,      2 )
   UpperCAmelCase__   :					List[str]   				=   prepare_video(
       image_processor_tester=__UpperCamelCase							,      width=__UpperCamelCase							,      height=__UpperCamelCase							,      numpify=__UpperCamelCase							,      torchify=__UpperCamelCase							,      )
  video_inputs.append(__UpperCamelCase )

 return video_inputs







class        __lowercase     :
  snake_case_			    =    None

  def 				__lowercase    (					self						:     Union[str, Any]      ):






   '''simple docstring'''
   UpperCAmelCase__   :					int   				=   self.image_processing_class(**self.image_processor_dict      )
   UpperCAmelCase__   :					Optional[Any]   				=   json.loads(image_processor.to_json_string()      )
   for key, value in self.image_processor_dict.items():
    self.assertEqual(obj[key]   ,A      )

  def 				__lowercase    (					self						:     Any      ):






   '''simple docstring'''
   UpperCAmelCase__   :					List[Any]   				=   self.image_processing_class(**self.image_processor_dict      )

   with tempfile.TemporaryDirectory() as tmpdirname:
    UpperCAmelCase__   :					Union[str, Any]   				=   os.path.join(A   ,"""image_processor.json"""      )
    image_processor_first.to_json_file(A      )
    UpperCAmelCase__   :					Dict   				=   self.image_processing_class.from_json_file(A      )

   self.assertEqual(image_processor_second.to_dict()   ,image_processor_first.to_dict()      )

  def 				__lowercase    (					self						:     Dict      ):






   '''simple docstring'''
   UpperCAmelCase__   :					Optional[int]   				=   self.image_processing_class(**self.image_processor_dict      )

   with tempfile.TemporaryDirectory() as tmpdirname:
    UpperCAmelCase__   :					Any   				=   image_processor_first.save_pretrained(A      )[0]
    check_json_file_has_correct_format(A      )
    UpperCAmelCase__   :					Tuple   				=   self.image_processing_class.from_pretrained(A      )

   self.assertEqual(image_processor_second.to_dict()   ,image_processor_first.to_dict()      )

  def 				__lowercase    (					self						:     List[Any]      ):






   '''simple docstring'''
   UpperCAmelCase__   :					List[Any]   				=   self.image_processing_class()
   self.assertIsNotNone(A      )




  @require_torch
  @require_vision
  def 				__lowercase    (					self						:     str      ):






   '''simple docstring'''
   if self.test_cast_dtype is not None:
    # Initialize image_processor
    UpperCAmelCase__   :					Optional[Any]   				=   self.image_processing_class(**self.image_processor_dict      )

    # create random PyTorch tensors
    UpperCAmelCase__   :					Tuple   				=   prepare_image_inputs(self.image_processor_tester   ,equal_resolution=A   ,torchify=A      )

    UpperCAmelCase__   :					str   				=   image_processor(A   ,return_tensors="""pt"""      )
    # for layoutLM compatiblity
    self.assertEqual(encoding.pixel_values.device   ,torch.device("""cpu"""      )      )
    self.assertEqual(encoding.pixel_values.dtype   ,torch.floataa      )

    UpperCAmelCase__   :					Optional[int]   				=   image_processor(A   ,return_tensors="""pt"""      ).to(torch.floataa      )
    self.assertEqual(encoding.pixel_values.device   ,torch.device("""cpu"""      )      )
    self.assertEqual(encoding.pixel_values.dtype   ,torch.floataa      )

    UpperCAmelCase__   :					Optional[Any]   				=   image_processor(A   ,return_tensors="""pt"""      ).to("""cpu"""   ,torch.bfloataa      )
    self.assertEqual(encoding.pixel_values.device   ,torch.device("""cpu"""      )      )
    self.assertEqual(encoding.pixel_values.dtype   ,torch.bfloataa      )

    with self.assertRaises(A      ):
     UpperCAmelCase__   :					Optional[int]   				=   image_processor(A   ,return_tensors="""pt"""      ).to(torch.bfloataa   ,"""cpu"""      )

    # Try with text + image feature
    UpperCAmelCase__   :					List[str]   				=   image_processor(A   ,return_tensors="""pt"""      )
    encoding.update({"""input_ids""": torch.LongTensor([[1, 2, 3], [4, 5, 6]]      )}      )
    UpperCAmelCase__   :					Optional[Any]   				=   encoding.to(torch.floataa      )

    self.assertEqual(encoding.pixel_values.device   ,torch.device("""cpu"""      )      )
    self.assertEqual(encoding.pixel_values.dtype   ,torch.floataa      )
    self.assertEqual(encoding.input_ids.dtype   ,torch.long      )








"""simple docstring"""




from math import factorial
def 					lowerCAmelCase  (   __UpperCamelCase							,      __UpperCamelCase ):
 '''simple docstring'''





 return factorial(__UpperCamelCase ) / (factorial(__UpperCamelCase ) * factorial(n - r ))
def 					lowerCAmelCase  (   ):
 '''simple docstring'''





 UpperCAmelCase__   :					Any   				=   0

 for i in range(1							,      101 ):
  for j in range(1							,      i + 1 ):
   if combinations(__UpperCamelCase							,      __UpperCamelCase ) > 1e6:
    total += 1
 return total


if __name__ == "__main__":
      print(solution())





