



'''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 			UpperCAmelCase_							(		lowercase__							,						lowercase__=False							,						lowercase__=False							,						lowercase__=False							):


     '''simple docstring'''







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

     a_									=[]
     for i in range(image_processor_tester.batch_size							):
          if equal_resolution:
               a_									=a_									=image_processor_tester.max_resolution
          else:
               # To avoid getting image width/height 0
               a_									=image_processor_tester.min_resolution
               if getattr(lowercase__							,						"size_divisor"							,						lowercase__							):
                    # If `size_divisor` is defined, the image needs to have width/size >= `size_divisor`
                    a_									=max(image_processor_tester.size_divisor							,						lowercase__							)
               a_		,    a_									=np.random.choice(np.arange(lowercase__							,						image_processor_tester.max_resolution							)							,						2							)
          image_inputs.append(
              np.random.randint(2_5_5							,						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
          a_									=[Image.fromarray(np.moveaxis(lowercase__							,						0							,						-1							)							) for image in image_inputs]

     if torchify:
          a_									=[torch.from_numpy(lowercase__							) for image in image_inputs]

     return image_inputs






def 			UpperCAmelCase_							(		lowercase__							,						lowercase__=1_0							,						lowercase__=1_0							,						lowercase__=False							,						lowercase__=False							):


     '''simple docstring'''







     a_									=[]
     for i in range(image_processor_tester.num_frames							):
          video.append(np.random.randint(2_5_5							,						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
          a_									=[Image.fromarray(np.moveaxis(lowercase__							,						0							,						-1							)							) for frame in video]

     if torchify:
          a_									=[torch.from_numpy(lowercase__							) for frame in video]

     return video






def 			UpperCAmelCase_							(		lowercase__							,						lowercase__=False							,						lowercase__=False							,						lowercase__=False							):


     '''simple docstring'''







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

     a_									=[]
     for i in range(image_processor_tester.batch_size							):
          if equal_resolution:
               a_									=a_									=image_processor_tester.max_resolution
          else:
               a_		,    a_									=np.random.choice(
                   np.arange(image_processor_tester.min_resolution							,						image_processor_tester.max_resolution							)							,						2							)
               a_									=prepare_video(
                   image_processor_tester=lowercase__							,						width=lowercase__							,						height=lowercase__							,						numpify=lowercase__							,						torchify=lowercase__							,						)
          video_inputs.append(lowercase__							)

     return video_inputs







class 						UpperCAmelCase						:


 '''simple docstring'''




 __magic_name__       :			List[str]	=   None




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



      """simple docstring"""







      a_									=self.image_processing_class(**self.image_processor_dict)
      a_									=json.loads(image_processor.to_json_string())
      for key, value in self.image_processor_dict.items():
           self.assertEqual(obj[key]				,	lowerCAmelCase_)




 def    lowercase_	( self)			->   Any:



      """simple docstring"""







      a_									=self.image_processing_class(**self.image_processor_dict)

      with tempfile.TemporaryDirectory() as tmpdirname:
           a_									=os.path.join(lowerCAmelCase_				,	"image_processor.json")
           image_processor_first.to_json_file(lowerCAmelCase_)
           a_									=self.image_processing_class.from_json_file(lowerCAmelCase_)

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




 def    lowercase_	( self)			->   Any:



      """simple docstring"""







      a_									=self.image_processing_class(**self.image_processor_dict)

      with tempfile.TemporaryDirectory() as tmpdirname:
           a_									=image_processor_first.save_pretrained(lowerCAmelCase_)[0]
           check_json_file_has_correct_format(lowerCAmelCase_)
           a_									=self.image_processing_class.from_pretrained(lowerCAmelCase_)

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




 def    lowercase_	( self)			->   Tuple:



      """simple docstring"""







      a_									=self.image_processing_class()
      self.assertIsNotNone(lowerCAmelCase_)




 @require_torch
 @require_vision
 def    lowercase_	( self)			->   str:



      """simple docstring"""







      if self.test_cast_dtype is not None:
           # Initialize image_processor
           a_									=self.image_processing_class(**self.image_processor_dict)

           # create random PyTorch tensors
           a_									=prepare_image_inputs(self.image_processor_tester				,	equal_resolution=lowerCAmelCase_				,	torchify=lowerCAmelCase_)

           a_									=image_processor(lowerCAmelCase_				,	return_tensors="pt")
           # for layoutLM compatiblity
           self.assertEqual(encoding.pixel_values.device				,	torch.device("cpu"))
           self.assertEqual(encoding.pixel_values.dtype				,	torch.floataa)

           a_									=image_processor(lowerCAmelCase_				,	return_tensors="pt").to(torch.floataa)
           self.assertEqual(encoding.pixel_values.device				,	torch.device("cpu"))
           self.assertEqual(encoding.pixel_values.dtype				,	torch.floataa)

           a_									=image_processor(lowerCAmelCase_				,	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(lowerCAmelCase_):
                a_									=image_processor(lowerCAmelCase_				,	return_tensors="pt").to(torch.bfloataa				,	"cpu")

           # Try with text + image feature
           a_									=image_processor(lowerCAmelCase_				,	return_tensors="pt")
           encoding.update({"input_ids": torch.LongTensor([[1, 2, 3], [4, 5, 6]])})
           a_									=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'''


lowercase											=      (1, 153, 370, 371, 1_634, 24_678_051, 115_132_219_018_763_992_565_095_597_973_971_522_401)
lowercase											=      (-153, -1, 0, 1.2, 200, "A", [], {}, None)






def 			UpperCAmelCase_							(		lowercase__							):


     '''simple docstring'''







     if not isinstance(lowercase__							,						lowercase__							) or n < 1:
          return False

     # Initialization of sum and number of digits.
     a_									=0
     a_									=0
     a_									=n
     # Calculation of digits of the number
     while temp > 0:
          number_of_digits += 1
          temp //= 1_0
     # Dividing number into separate digits and find Armstrong number
     a_									=n
     while temp > 0:
          a_									=temp % 1_0
          total += rem**number_of_digits
          temp //= 1_0
     return n == total






def 			UpperCAmelCase_							(		lowercase__							):


     '''simple docstring'''







     if not isinstance(lowercase__							,						lowercase__							) or n < 1:
          return False

     # Init a "histogram" of the digits
     a_									=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
     a_									=0
     a_									=0
     a_									=n
     while temp > 0:
          a_		,    a_									=divmod(lowercase__							,						1_0							)
          digit_histogram[rem] += 1
          digit_total += 1

     for cnt, i in zip(lowercase__							,						range(len(lowercase__							)							)							):
          total += cnt * i**digit_total

     return n == total






def 			UpperCAmelCase_							(		lowercase__							):


     '''simple docstring'''







     if not isinstance(lowercase__							,						lowercase__							) or n < 1:
          return False
     a_									=len(str(lowercase__							)							)  # the power that all digits will be raised to
     # check if sum of each digit multiplied expo times is equal to number
     return n == sum(int(lowercase__							) ** expo for i in str(lowercase__							)							)






def 			UpperCAmelCase_							(		):


     '''simple docstring'''







     a_									=int(input("Enter an integer to see if it is an Armstrong number: "							).strip()							)
     print(F"""{num} is {'' if armstrong_number(lowercase__							) else 'not '}an Armstrong number."""							)
     print(F"""{num} is {'' if narcissistic_number(lowercase__							) else 'not '}an Armstrong number."""							)
     print(F"""{num} is {'' if pluperfect_number(lowercase__							) else 'not '}an Armstrong number."""							)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  main()


