





"""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 MobileNetVaImageProcessor

class 		lowercase					(					unittest.TestCase					):





      def __init__(       self      ,						lowercase      ,						lowercase=7      ,						lowercase=3      ,						lowercase=18      ,						lowercase=30      ,						lowercase=400      ,						lowercase=True      ,						lowercase=None      ,						lowercase=True      ,						lowercase=None      ,						)		->     Any:
            lowerCAmelCase  						=       size if size is not None else {"""shortest_edge""": 20}
            lowerCAmelCase  						=       crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
            lowerCAmelCase  						=       parent
            lowerCAmelCase  						=       batch_size
            lowerCAmelCase  						=       num_channels
            lowerCAmelCase  						=       image_size
            lowerCAmelCase  						=       min_resolution
            lowerCAmelCase  						=       max_resolution
            lowerCAmelCase  						=       do_resize
            lowerCAmelCase  						=       size
            lowerCAmelCase  						=       do_center_crop
            lowerCAmelCase  						=       crop_size





      def     _snake_case			(       self )		->     Any:
            return {
                "do_resize": self.do_resize,
                "size": self.size,
                "do_center_crop": self.do_center_crop,
                "crop_size": self.crop_size,
            }







@require_torch
@require_vision
class 		lowercase					(					_UpperCAmelCase     ,  unittest.TestCase					):
      _SCREAMING_SNAKE_CASE					=      MobileNetVaImageProcessor if is_vision_available() else None





      def     _snake_case			(       self )		->     List[str]:
            lowerCAmelCase  						=       MobileNetVaImageProcessingTester(self )





      @property
      def     _snake_case			(       self )		->     List[str]:
            return self.image_processor_tester.prepare_image_processor_dict()





      def     _snake_case			(       self )		->     Dict:
            lowerCAmelCase  						=       self.image_processing_class(**self.image_processor_dict )
            self.assertTrue(hasattr(lowercase      ,						"""do_resize""" ) )
            self.assertTrue(hasattr(lowercase      ,						"""size""" ) )
            self.assertTrue(hasattr(lowercase      ,						"""do_center_crop""" ) )
            self.assertTrue(hasattr(lowercase      ,						"""crop_size""" ) )





      def     _snake_case			(       self )		->     Union[str, Any]:
            lowerCAmelCase  						=       self.image_processing_class.from_dict(self.image_processor_dict )
            self.assertEqual(image_processor.size      ,						{"""shortest_edge""": 20} )
            self.assertEqual(image_processor.crop_size      ,						{"""height""": 18, """width""": 18} )

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





      def     _snake_case			(       self )		->     Dict:
            pass





      def     _snake_case			(       self )		->     Optional[int]:
            # Initialize image_processing
            lowerCAmelCase  						=       self.image_processing_class(**self.image_processor_dict )
            # create random PIL images
            lowerCAmelCase  						=       prepare_image_inputs(self.image_processor_tester      ,						equal_resolution=lowercase )
            for image in image_inputs:
                  self.assertIsInstance(lowercase      ,						Image.Image )

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

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

            # Test not batched input
            lowerCAmelCase  						=       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
            lowerCAmelCase  						=       image_processing(lowercase      ,						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 math






def    lowerCamelCase__				(				__lowerCAmelCase  :  int				):




			"""simple docstring"""


			lowerCAmelCase_						=	0
			lowerCAmelCase_						=	0
			while num > 0:
						lowerCAmelCase_						=	num % 8
						lowerCAmelCase_						=	octal + (remainder * math.floor(math.pow(10    ,							__lowerCAmelCase				)				))
						counter += 1
						lowerCAmelCase_						=	math.floor(num / 8				)  # basically /= 8 without remainder if any
						# This formatting removes trailing '.0' from `octal`.
			return F"""0o{int(__lowerCAmelCase				)}"""






def    lowerCamelCase__				(				):




			"""simple docstring"""


			print("\n2 in octal is:"				)
			print(decimal_to_octal(2				)				)  # = 2
			print("\n8 in octal is:"				)
			print(decimal_to_octal(8				)				)  # = 10
			print("\n65 in octal is:"				)
			print(decimal_to_octal(65				)				)  # = 101
			print("\n216 in octal is:"				)
			print(decimal_to_octal(216				)				)  # = 330
			print("\n512 in octal is:"				)
			print(decimal_to_octal(512				)				)  # = 1000
			print("\n"				)


if __name__ == "__main__":
			main()



