
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 DeiTImageProcessor







class 	A_       (      unittest.TestCase       ):




 '''simple docstring'''


 def __init__(	self		,   snake_case		,   snake_case=7		,   snake_case=3		,   snake_case=18		,   snake_case=30		,   snake_case=400		,   snake_case=True		,   snake_case=None		,   snake_case=True		,   snake_case=None		,   snake_case=True		,   snake_case=[0.5, 0.5, 0.5]		,   snake_case=[0.5, 0.5, 0.5]		,   ):
  lowercase					  =   size if size is not None else {'height': 20, 'width': 20}
  lowercase					  =   crop_size if crop_size is not None else {'height': 18, 'width': 18}

  lowercase					  =   parent
  lowercase					  =   batch_size
  lowercase					  =   num_channels
  lowercase					  =   image_size
  lowercase					  =   min_resolution
  lowercase					  =   max_resolution
  lowercase					  =   do_resize
  lowercase					  =   size
  lowercase					  =   do_center_crop
  lowercase					  =   crop_size
  lowercase					  =   do_normalize
  lowercase					  =   image_mean
  lowercase					  =   image_std





 def      SCREAMING_SNAKE_CASE__						(	self	):
  return {
      "do_resize": self.do_resize,
      "size": self.size,
      "do_center_crop": self.do_center_crop,
      "crop_size": self.crop_size,
      "do_normalize": self.do_normalize,
      "image_mean": self.image_mean,
      "image_std": self.image_std,
  }







@require_torch
@require_vision
class 	A_       (      SCREAMING_SNAKE_CASE__				,     unittest.TestCase       ):




 '''simple docstring'''


 _UpperCamelCase					:					Tuple										=	DeiTImageProcessor if is_vision_available() else None
 _UpperCamelCase					:					int										=	True





 def      SCREAMING_SNAKE_CASE__						(	self	):
  lowercase					  =   DeiTImageProcessingTester(self	)





 @property
 def      SCREAMING_SNAKE_CASE__						(	self	):
  return self.image_processor_tester.prepare_image_processor_dict()





 def      SCREAMING_SNAKE_CASE__						(	self	):
  lowercase					  =   self.image_processing_class(**self.image_processor_dict	)
  self.assertTrue(hasattr(snake_case		,   'do_resize'	)	)
  self.assertTrue(hasattr(snake_case		,   'size'	)	)
  self.assertTrue(hasattr(snake_case		,   'do_center_crop'	)	)
  self.assertTrue(hasattr(snake_case		,   'center_crop'	)	)
  self.assertTrue(hasattr(snake_case		,   'do_normalize'	)	)
  self.assertTrue(hasattr(snake_case		,   'image_mean'	)	)
  self.assertTrue(hasattr(snake_case		,   'image_std'	)	)





 def      SCREAMING_SNAKE_CASE__						(	self	):
  lowercase					  =   self.image_processing_class.from_dict(self.image_processor_dict	)
  self.assertEqual(image_processor.size		,   {'height': 20, 'width': 20}	)
  self.assertEqual(image_processor.crop_size		,   {'height': 18, 'width': 18}	)

  lowercase					  =   self.image_processing_class.from_dict(self.image_processor_dict		,   size=42		,   crop_size=84	)
  self.assertEqual(image_processor.size		,   {'height': 42, 'width': 42}	)
  self.assertEqual(image_processor.crop_size		,   {'height': 84, 'width': 84}	)





 def      SCREAMING_SNAKE_CASE__						(	self	):
  pass





 def      SCREAMING_SNAKE_CASE__						(	self	):
  lowercase					  =   self.image_processing_class(**self.image_processor_dict	)
  # create random PIL images
  lowercase					  =   prepare_image_inputs(self.image_processor_tester		,   equal_resolution=snake_case	)
  for image in image_inputs:
   self.assertIsInstance(snake_case		,   Image.Image	)

  # Test not batched input
  lowercase					  =   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
  lowercase					  =   image_processing(snake_case		,   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      SCREAMING_SNAKE_CASE__						(	self	):
  lowercase					  =   self.image_processing_class(**self.image_processor_dict	)
  # create random numpy tensors
  lowercase					  =   prepare_image_inputs(self.image_processor_tester		,   equal_resolution=snake_case		,   numpify=snake_case	)
  for image in image_inputs:
   self.assertIsInstance(snake_case		,   np.ndarray	)

  # Test not batched input
  lowercase					  =   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
  lowercase					  =   image_processing(snake_case		,   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      SCREAMING_SNAKE_CASE__						(	self	):
  lowercase					  =   self.image_processing_class(**self.image_processor_dict	)
  # create random PyTorch tensors
  lowercase					  =   prepare_image_inputs(self.image_processor_tester		,   equal_resolution=snake_case		,   torchify=snake_case	)
  for image in image_inputs:
   self.assertIsInstance(snake_case		,   torch.Tensor	)

  # Test not batched input
  lowercase					  =   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
  lowercase					  =   image_processing(snake_case		,   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'],
      )		,   )



import unittest
from timeit import timeit






def 							UpperCAmelCase_		(							__SCREAMING_SNAKE_CASE			,							__SCREAMING_SNAKE_CASE							):
	lowercase					  =   first_num if first_num >= second_num else second_num
	lowercase					  =   max_num
	while (common_mult % first_num > 0) or (common_mult % second_num > 0):
		common_mult += max_num
	return common_mult






def 							UpperCAmelCase_		(							__SCREAMING_SNAKE_CASE			,							__SCREAMING_SNAKE_CASE							):
	return b if a == 0 else greatest_common_divisor(b % a			,							__SCREAMING_SNAKE_CASE							)






def 							UpperCAmelCase_		(							__SCREAMING_SNAKE_CASE			,							__SCREAMING_SNAKE_CASE							):
	return first_num // greatest_common_divisor(__SCREAMING_SNAKE_CASE			,							__SCREAMING_SNAKE_CASE							) * second_num






def 							UpperCAmelCase_		(							):
	lowercase					  =   (
	    'from __main__ import least_common_multiple_slow, least_common_multiple_fast'
	)
	print(
	    'least_common_multiple_slow():'			,							timeit('least_common_multiple_slow(1000, 999)'			,							setup=__SCREAMING_SNAKE_CASE							)			,							)
	print(
	    'least_common_multiple_fast():'			,							timeit('least_common_multiple_fast(1000, 999)'			,							setup=__SCREAMING_SNAKE_CASE							)			,							)







class 	A_       (      unittest.TestCase       ):




	'''simple docstring'''


	_UpperCamelCase					:					Any										=	(
	    (10, 20),
	    (13, 15),
	    (4, 31),
	    (10, 42),
	    (43, 34),
	    (5, 12),
	    (12, 25),
	    (10, 25),
	    (6, 9),
	)
	_UpperCamelCase					:					int										=	(20, 195, 124, 210, 1462, 60, 300, 50, 18)





	def      SCREAMING_SNAKE_CASE__						(	self	):
		for i, (first_num, second_num) in enumerate(self.test_inputs	):
			lowercase					  =   least_common_multiple_slow(snake_case		,   snake_case	)
			lowercase					  =   least_common_multiple_fast(snake_case		,   snake_case	)
			with self.subTest(i=snake_case	):
				self.assertEqual(snake_case		,   self.expected_results[i]	)
				self.assertEqual(snake_case		,   self.expected_results[i]	)


if __name__ == "__main__":
	benchmark()
	unittest.main()

