





"""simple docstring"""




import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor




class 			_a						(				unittest.TestCase    ):






				def __init__(			self		:   Dict,			lowerCAmelCase__		:   Tuple,			lowerCAmelCase__		:   List[Any]=7,			lowerCAmelCase__		:   List[str]=3,			lowerCAmelCase__		:   Tuple=1_8,			lowerCAmelCase__		:   List[Any]=3_0,			lowerCAmelCase__		:   int=4_0_0,			lowerCAmelCase__		:   int=True,			lowerCAmelCase__		:   List[Any]=None,			lowerCAmelCase__		:   int=True,			lowerCAmelCase__		:   Optional[Any]=False,			lowerCAmelCase__		:   int=True,			lowerCAmelCase__		:   List[Any]=True,			lowerCAmelCase__		:   Any=[0.5, 0.5, 0.5],			lowerCAmelCase__		:   List[str]=[0.5, 0.5, 0.5],			)     ->				Tuple:




										'''simple docstring'''



										_UpperCamelCase      : List[Any]         =   parent
										_UpperCamelCase      : Optional[Any]         =   batch_size
										_UpperCamelCase      : int         =   num_channels
										_UpperCamelCase      : str         =   image_size
										_UpperCamelCase      : str         =   min_resolution
										_UpperCamelCase      : Union[str, Any]         =   max_resolution
										_UpperCamelCase      : Dict         =   do_resize
										_UpperCamelCase      : List[Any]         =   size if size is not None else {'''height''': 1_8, '''width''': 2_0}
										_UpperCamelCase      : Optional[int]         =   do_thumbnail
										_UpperCamelCase      : Tuple         =   do_align_axis
										_UpperCamelCase      : Any         =   do_pad
										_UpperCamelCase      : Any         =   do_normalize
										_UpperCamelCase      : Dict         =   image_mean
										_UpperCamelCase      : Optional[int]         =   image_std






				def     snake_case     (			self		:   Tuple							)     ->				List[Any]:




										'''simple docstring'''



										return {
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "do_thumbnail": self.do_thumbnail,
										    "do_align_long_axis": self.do_align_axis,
										    "do_pad": self.do_pad,
										    "do_normalize": self.do_normalize,
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										}




@require_torch
@require_vision
class 			_a						(				_lowerCAmelCase     ,    unittest.TestCase    ):
				UpperCamelCase								=   DonutImageProcessor if is_vision_available() else None






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




										'''simple docstring'''



										_UpperCamelCase      : Tuple         =   DonutImageProcessingTester(self							)






				@property
				def     snake_case     (			self		:   int							)     ->				str:




										'''simple docstring'''



										return self.image_processor_tester.prepare_image_processor_dict()






				def     snake_case     (			self		:   Optional[int]							)     ->				str:




										'''simple docstring'''



										_UpperCamelCase      : str         =   self.image_processing_class(**self.image_processor_dict							)
										self.assertTrue(hasattr(lowerCAmelCase__,			'''do_resize'''							)							)
										self.assertTrue(hasattr(lowerCAmelCase__,			'''size'''							)							)
										self.assertTrue(hasattr(lowerCAmelCase__,			'''do_thumbnail'''							)							)
										self.assertTrue(hasattr(lowerCAmelCase__,			'''do_align_long_axis'''							)							)
										self.assertTrue(hasattr(lowerCAmelCase__,			'''do_pad'''							)							)
										self.assertTrue(hasattr(lowerCAmelCase__,			'''do_normalize'''							)							)
										self.assertTrue(hasattr(lowerCAmelCase__,			'''image_mean'''							)							)
										self.assertTrue(hasattr(lowerCAmelCase__,			'''image_std'''							)							)






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




										'''simple docstring'''



										_UpperCamelCase      : Dict         =   self.image_processing_class.from_dict(self.image_processor_dict							)
										self.assertEqual(image_processor.size,			{'''height''': 1_8, '''width''': 2_0}							)

										_UpperCamelCase      : Union[str, Any]         =   self.image_processing_class.from_dict(self.image_processor_dict,			size=4_2							)
										self.assertEqual(image_processor.size,			{'''height''': 4_2, '''width''': 4_2}							)

										# Previous config had dimensions in (width, height) order
										_UpperCamelCase      : Optional[int]         =   self.image_processing_class.from_dict(self.image_processor_dict,			size=(4_2, 8_4)							)
										self.assertEqual(image_processor.size,			{'''height''': 8_4, '''width''': 4_2}							)






				def     snake_case     (			self		:   List[str]							)     ->				Optional[Any]:




										'''simple docstring'''



										pass






				@is_flaky()
				def     snake_case     (			self		:   Any							)     ->				int:




										'''simple docstring'''



										_UpperCamelCase      : Dict         =   self.image_processing_class(**self.image_processor_dict							)
										# create random PIL images
										_UpperCamelCase      : str         =   prepare_image_inputs(self.image_processor_tester,			equal_resolution=lowerCAmelCase__							)
										for image in image_inputs:
																self.assertIsInstance(lowerCAmelCase__,			Image.Image							)

										# Test not batched input
										_UpperCamelCase      : Optional[int]         =   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['''height'''],
										        self.image_processor_tester.size['''width'''],
										    ),			)

										# Test batched
										_UpperCamelCase      : Union[str, Any]         =   image_processing(lowerCAmelCase__,			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['''height'''],
										        self.image_processor_tester.size['''width'''],
										    ),			)






				@is_flaky()
				def     snake_case     (			self		:   List[str]							)     ->				str:




										'''simple docstring'''



										_UpperCamelCase      : Union[str, Any]         =   self.image_processing_class(**self.image_processor_dict							)
										# create random numpy tensors
										_UpperCamelCase      : Optional[int]         =   prepare_image_inputs(self.image_processor_tester,			equal_resolution=lowerCAmelCase__,			numpify=lowerCAmelCase__							)
										for image in image_inputs:
																self.assertIsInstance(lowerCAmelCase__,			np.ndarray							)

										# Test not batched input
										_UpperCamelCase      : 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.size['''height'''],
										        self.image_processor_tester.size['''width'''],
										    ),			)

										# Test batched
										_UpperCamelCase      : Any         =   image_processing(lowerCAmelCase__,			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['''height'''],
										        self.image_processor_tester.size['''width'''],
										    ),			)






				@is_flaky()
				def     snake_case     (			self		:   Any							)     ->				Optional[int]:




										'''simple docstring'''



										_UpperCamelCase      : Optional[Any]         =   self.image_processing_class(**self.image_processor_dict							)
										# create random PyTorch tensors
										_UpperCamelCase      : Dict         =   prepare_image_inputs(self.image_processor_tester,			equal_resolution=lowerCAmelCase__,			torchify=lowerCAmelCase__							)
										for image in image_inputs:
																self.assertIsInstance(lowerCAmelCase__,			torch.Tensor							)

										# Test not batched input
										_UpperCamelCase      : int         =   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['''height'''],
										        self.image_processor_tester.size['''width'''],
										    ),			)

										# Test batched
										_UpperCamelCase      : Any         =   image_processing(lowerCAmelCase__,			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['''height'''],
										        self.image_processor_tester.size['''width'''],
										    ),			)










"""simple docstring"""




def 	a_    (							_lowercase	,						_lowercase       ):
						if discount_rate < 0:
												raise ValueError('''Discount rate cannot be negative'''       )
						if not cash_flows:
												raise ValueError('''Cash flows list cannot be empty'''       )
						_UpperCamelCase      : Optional[int]         =   sum(
						    cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_lowercase       )       )
						return round(_lowercase	,						ndigits=2       )


if __name__ == "__main__":
						import doctest

						doctest.testmod()



