






"""simple docstring"""







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 ConvNextImageProcessor





class      UpperCamelCase_       (				unittest.TestCase     ):



  def __init__(					self       ,						snake_case__       ,						snake_case__=7       ,						snake_case__=3       ,						snake_case__=18       ,						snake_case__=30       ,						snake_case__=4_00       ,						snake_case__=True       ,						snake_case__=None       ,						snake_case__=0.875       ,						snake_case__=True       ,						snake_case__=[0.5, 0.5, 0.5]       ,						snake_case__=[0.5, 0.5, 0.5]       ,						)	->	Optional[int]:



         """simple docstring"""





         UpperCAmelCase					=	size if size is not None else {"""shortest_edge""": 20}
         UpperCAmelCase					=	parent
         UpperCAmelCase					=	batch_size
         UpperCAmelCase					=	num_channels
         UpperCAmelCase					=	image_size
         UpperCAmelCase					=	min_resolution
         UpperCAmelCase					=	max_resolution
         UpperCAmelCase					=	do_resize
         UpperCAmelCase					=	size
         UpperCAmelCase					=	crop_pct
         UpperCAmelCase					=	do_normalize
         UpperCAmelCase					=	image_mean
         UpperCAmelCase					=	image_std



  def 						UpperCamelCase_ (					self )	->	Dict:



         """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,
             "crop_pct": self.crop_pct,
         }





@require_torch
@require_vision
class      UpperCamelCase_       (				a_      ,    unittest.TestCase     ):
  _A				:    List[str] =		ConvNextImageProcessor if is_vision_available() else None



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



         """simple docstring"""





         UpperCAmelCase					=	ConvNextImageProcessingTester(self )



  @property
  def 						UpperCamelCase_ (					self )	->	Optional[int]:



         """simple docstring"""





         return self.image_processor_tester.prepare_image_processor_dict()



  def 						UpperCamelCase_ (					self )	->	Optional[int]:



         """simple docstring"""





         UpperCAmelCase					=	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__       ,						"""crop_pct""" ) )
         self.assertTrue(hasattr(snake_case__       ,						"""do_normalize""" ) )
         self.assertTrue(hasattr(snake_case__       ,						"""image_mean""" ) )
         self.assertTrue(hasattr(snake_case__       ,						"""image_std""" ) )



  def 						UpperCamelCase_ (					self )	->	Tuple:



         """simple docstring"""





         UpperCAmelCase					=	self.image_processing_class.from_dict(self.image_processor_dict )
         self.assertEqual(image_processor.size       ,						{"""shortest_edge""": 20} )

         UpperCAmelCase					=	self.image_processing_class.from_dict(self.image_processor_dict       ,						size=42 )
         self.assertEqual(image_processor.size       ,						{"""shortest_edge""": 42} )



  def 						UpperCamelCase_ (					self )	->	Dict:



         """simple docstring"""





         pass



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



         """simple docstring"""





         UpperCAmelCase					=	self.image_processing_class(**self.image_processor_dict )
         # create random PIL images
         UpperCAmelCase					=	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
         UpperCAmelCase					=	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.size["""shortest_edge"""],
                 self.image_processor_tester.size["""shortest_edge"""],
             )       ,						)

         # Test batched
         UpperCAmelCase					=	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.size["""shortest_edge"""],
                 self.image_processor_tester.size["""shortest_edge"""],
             )       ,						)



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



         """simple docstring"""





         UpperCAmelCase					=	self.image_processing_class(**self.image_processor_dict )
         # create random numpy tensors
         UpperCAmelCase					=	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
         UpperCAmelCase					=	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.size["""shortest_edge"""],
                 self.image_processor_tester.size["""shortest_edge"""],
             )       ,						)

         # Test batched
         UpperCAmelCase					=	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.size["""shortest_edge"""],
                 self.image_processor_tester.size["""shortest_edge"""],
             )       ,						)



  def 						UpperCamelCase_ (					self )	->	Dict:



         """simple docstring"""





         UpperCAmelCase					=	self.image_processing_class(**self.image_processor_dict )
         # create random PyTorch tensors
         UpperCAmelCase					=	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
         UpperCAmelCase					=	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.size["""shortest_edge"""],
                 self.image_processor_tester.size["""shortest_edge"""],
             )       ,						)

         # Test batched
         UpperCAmelCase					=	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.size["""shortest_edge"""],
                 self.image_processor_tester.size["""shortest_edge"""],
             )       ,						)








"""simple docstring"""







import unittest
from timeit import timeit






def 					_lowerCAmelCase				(					lowerCAmelCase		,					lowerCAmelCase						):







       '''simple docstring'''
       UpperCAmelCase					=	first_num if first_num >= second_num else second_num
       UpperCAmelCase					=	max_num
       while (common_mult % first_num > 0) or (common_mult % second_num > 0):
              common_mult += max_num
       return common_mult






def 					_lowerCAmelCase				(					lowerCAmelCase		,					lowerCAmelCase						):







       '''simple docstring'''
       return b if a == 0 else greatest_common_divisor(b % a		,					lowerCAmelCase						)






def 					_lowerCAmelCase				(					lowerCAmelCase		,					lowerCAmelCase						):







       '''simple docstring'''
       return first_num // greatest_common_divisor(lowerCAmelCase		,					lowerCAmelCase						) * second_num






def 					_lowerCAmelCase				(					):







       '''simple docstring'''
       UpperCAmelCase					=	(
           """from __main__ import least_common_multiple_slow, least_common_multiple_fast"""
       )
       print(
           """least_common_multiple_slow():"""		,					timeit("""least_common_multiple_slow(1000, 999)"""		,					setup=lowerCAmelCase						)		,					)
       print(
           """least_common_multiple_fast():"""		,					timeit("""least_common_multiple_fast(1000, 999)"""		,					setup=lowerCAmelCase						)		,					)





class      UpperCamelCase_       (				unittest.TestCase     ):
  _A				:    List[str] =		(
      (10, 20),
      (13, 15),
      (4, 31),
      (10, 42),
      (43, 34),
      (5, 12),
      (12, 25),
      (10, 25),
      (6, 9),
  )
  _A				:    int =		(20, 195, 124, 210, 1462, 60, 300, 50, 18)



  def 						UpperCamelCase_ (					self )	->	Any:



         """simple docstring"""





         for i, (first_num, second_num) in enumerate(self.test_inputs ):
                UpperCAmelCase					=	least_common_multiple_slow(snake_case__       ,						snake_case__ )
                UpperCAmelCase					=	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()
