

'''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     a			(				unittest.TestCase       ):






      """simple docstring"""




      def __init__(							self					:      Optional[int]			,			snake_case_					:      Tuple			,			snake_case_					:      List[str]=7			,			snake_case_					:      Optional[int]=3			,			snake_case_					:      Union[str, Any]=1_8			,			snake_case_					:      Any=3_0			,			snake_case_					:      List[str]=4_0_0			,			snake_case_					:      int=True			,			snake_case_					:      Optional[int]=None			,			snake_case_					:      str=True			,			snake_case_					:      Union[str, Any]=None			,			):



        '''simple docstring'''



        snake_case__						:       Optional[Any]       						=  size if size is not None else {"shortest_edge": 2_0}
        snake_case__						:       List[str]       						=  crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}
        snake_case__						:       Union[str, Any]       						=  parent
        snake_case__						:       Union[str, Any]       						=  batch_size
        snake_case__						:       Optional[Any]       						=  num_channels
        snake_case__						:       List[str]       						=  image_size
        snake_case__						:       List[str]       						=  min_resolution
        snake_case__						:       Tuple       						=  max_resolution
        snake_case__						:       Optional[Any]       						=  do_resize
        snake_case__						:       Any       						=  size
        snake_case__						:       Dict       						=  do_center_crop
        snake_case__						:       int       						=  crop_size







      def       __magic_name__							(							self					:      List[Any]  ):



        '''simple docstring'''



        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     a			(				_A			,			unittest.TestCase       ):






      """simple docstring"""




      __UpperCAmelCase			     =    MobileNetVaImageProcessor if is_vision_available() else None







      def       __magic_name__							(							self					:      int  ):



        '''simple docstring'''



        snake_case__						:       List[Any]       						=  MobileNetVaImageProcessingTester(self  )







      @property
      def       __magic_name__							(							self					:      Any  ):



        '''simple docstring'''



        return self.image_processor_tester.prepare_image_processor_dict()







      def       __magic_name__							(							self					:      List[Any]  ):



        '''simple docstring'''



        snake_case__						:       List[str]       						=  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_			,			'''crop_size'''  )  )







      def       __magic_name__							(							self					:      Tuple  ):



        '''simple docstring'''



        snake_case__						:       List[str]       						=  self.image_processing_class.from_dict(self.image_processor_dict  )
        self.assertEqual(image_processor.size			,			{'''shortest_edge''': 2_0}  )
        self.assertEqual(image_processor.crop_size			,			{'''height''': 1_8, '''width''': 1_8}  )

        snake_case__						:       Optional[int]       						=  self.image_processing_class.from_dict(self.image_processor_dict			,			size=4_2			,			crop_size=8_4  )
        self.assertEqual(image_processor.size			,			{'''shortest_edge''': 4_2}  )
        self.assertEqual(image_processor.crop_size			,			{'''height''': 8_4, '''width''': 8_4}  )







      def       __magic_name__							(							self					:      Any  ):



        '''simple docstring'''



        pass







      def       __magic_name__							(							self					:      Any  ):



        '''simple docstring'''



        snake_case__						:       Tuple       						=  self.image_processing_class(**self.image_processor_dict  )
        # create random PIL images
        snake_case__						:       int       						=  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
        snake_case__						:       Optional[Any]       						=  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
        snake_case__						:       Union[str, Any]       						=  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       __magic_name__							(							self					:      Any  ):



        '''simple docstring'''



        snake_case__						:       Union[str, Any]       						=  self.image_processing_class(**self.image_processor_dict  )
        # create random numpy tensors
        snake_case__						:       Optional[Any]       						=  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
        snake_case__						:       Dict       						=  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
        snake_case__						:       List[Any]       						=  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       __magic_name__							(							self					:      int  ):



        '''simple docstring'''



        snake_case__						:       Tuple       						=  self.image_processing_class(**self.image_processor_dict  )
        # create random PyTorch tensors
        snake_case__						:       Union[str, Any]       						=  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
        snake_case__						:       Any       						=  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
        snake_case__						:       List[Any]       						=  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'''],
            )			,			)






'''simple docstring'''


def 	_a       (				__lowerCAmelCase		:      float   ,							__lowerCAmelCase		:      float   ,							__lowerCAmelCase		:      int     ):

		"""simple docstring"""

		if principal <= 0:
				raise Exception('''Principal borrowed must be > 0'''     )
		if rate_per_annum < 0:
				raise Exception('''Rate of interest must be >= 0'''     )
		if years_to_repay <= 0 or not isinstance(__lowerCAmelCase   ,							__lowerCAmelCase     ):
				raise Exception('''Years to repay must be an integer > 0'''     )

		# Yearly rate is divided by 12 to get monthly rate
		snake_case__						:       int       						=  rate_per_annum / 12

		# Years to repay is multiplied by 12 to get number of payments as payment is monthly
		snake_case__						:       Tuple       						=  years_to_repay * 12

		return (
		    principal
		    * rate_per_month
		    * (1 + rate_per_month) ** number_of_payments
		    / ((1 + rate_per_month) ** number_of_payments - 1)
		)


if __name__ == "__main__":
					import doctest

					doctest.testmod()



