




'''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 ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE=7 ,_SCREAMING_SNAKE_CASE=3 ,_SCREAMING_SNAKE_CASE=18 ,_SCREAMING_SNAKE_CASE=30 ,_SCREAMING_SNAKE_CASE=400 ,_SCREAMING_SNAKE_CASE=True ,_SCREAMING_SNAKE_CASE=None ,_SCREAMING_SNAKE_CASE=True ,_SCREAMING_SNAKE_CASE=False ,_SCREAMING_SNAKE_CASE=True ,_SCREAMING_SNAKE_CASE=True ,_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5] ,_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5] ,)							->      int:
          _snake_case							=				parent
          _snake_case							=				batch_size
          _snake_case							=				num_channels
          _snake_case							=				image_size
          _snake_case							=				min_resolution
          _snake_case							=				max_resolution
          _snake_case							=				do_resize
          _snake_case							=				size if size is not None else {"height": 18, "width": 20}
          _snake_case							=				do_thumbnail
          _snake_case							=				do_align_axis
          _snake_case							=				do_pad
          _snake_case							=				do_normalize
          _snake_case							=				image_mean
          _snake_case							=				image_std






     def     _lowercase     (			self   )							->      str:
          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							):
     SCREAMING_SNAKE_CASE_							:   Tuple       =						DonutImageProcessor if is_vision_available() else None






     def     _lowercase     (			self   )							->      Any:
          _snake_case							=				DonutImageProcessingTester(self   )






     @property
     def     _lowercase     (			self   )							->      int:
          return self.image_processor_tester.prepare_image_processor_dict()






     def     _lowercase     (			self   )							->      Optional[int]:
          _snake_case							=				self.image_processing_class(**self.image_processor_dict   )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,"do_resize"   )   )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,"size"   )   )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,"do_thumbnail"   )   )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,"do_align_long_axis"   )   )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,"do_pad"   )   )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,"do_normalize"   )   )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,"image_mean"   )   )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,"image_std"   )   )






     def     _lowercase     (			self   )							->      List[Any]:
          _snake_case							=				self.image_processing_class.from_dict(self.image_processor_dict   )
          self.assertEqual(image_processor.size ,{"height": 18, "width": 20}   )

          _snake_case							=				self.image_processing_class.from_dict(self.image_processor_dict ,size=42   )
          self.assertEqual(image_processor.size ,{"height": 42, "width": 42}   )

          # Previous config had dimensions in (width, height) order
          _snake_case							=				self.image_processing_class.from_dict(self.image_processor_dict ,size=(42, 84)   )
          self.assertEqual(image_processor.size ,{"height": 84, "width": 42}   )






     def     _lowercase     (			self   )							->      str:
          pass






     @is_flaky()
     def     _lowercase     (			self   )							->      Union[str, Any]:
          # Initialize image_processing
          _snake_case							=				self.image_processing_class(**self.image_processor_dict   )
          # create random PIL images
          _snake_case							=				prepare_image_inputs(self.image_processor_tester ,equal_resolution=_SCREAMING_SNAKE_CASE   )
          for image in image_inputs:
               self.assertIsInstance(_SCREAMING_SNAKE_CASE ,Image.Image   )

          # Test not batched input
          _snake_case							=				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
          _snake_case							=				image_processing(_SCREAMING_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["height"],
                  self.image_processor_tester.size["width"],
              ) ,)






     @is_flaky()
     def     _lowercase     (			self   )							->      List[str]:
          # Initialize image_processing
          _snake_case							=				self.image_processing_class(**self.image_processor_dict   )
          # create random numpy tensors
          _snake_case							=				prepare_image_inputs(self.image_processor_tester ,equal_resolution=_SCREAMING_SNAKE_CASE ,numpify=_SCREAMING_SNAKE_CASE   )
          for image in image_inputs:
               self.assertIsInstance(_SCREAMING_SNAKE_CASE ,np.ndarray   )

          # Test not batched input
          _snake_case							=				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
          _snake_case							=				image_processing(_SCREAMING_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["height"],
                  self.image_processor_tester.size["width"],
              ) ,)






     @is_flaky()
     def     _lowercase     (			self   )							->      List[str]:
          # Initialize image_processing
          _snake_case							=				self.image_processing_class(**self.image_processor_dict   )
          # create random PyTorch tensors
          _snake_case							=				prepare_image_inputs(self.image_processor_tester ,equal_resolution=_SCREAMING_SNAKE_CASE ,torchify=_SCREAMING_SNAKE_CASE   )
          for image in image_inputs:
               self.assertIsInstance(_SCREAMING_SNAKE_CASE ,torch.Tensor   )

          # Test not batched input
          _snake_case							=				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
          _snake_case							=				image_processing(_SCREAMING_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["height"],
                  self.image_processor_tester.size["width"],
              ) ,)








'''simple docstring'''





from decimal import Decimal, getcontext
from math import ceil, factorial





def      __a     (       _UpperCamelCase:   int   )						->			str:

     """simple docstring"""




     if not isinstance(_UpperCamelCase ,						_UpperCamelCase   ):
          raise TypeError("Undefined for non-integers"   )
     elif precision < 1:
          raise ValueError("Undefined for non-natural numbers"   )

     _snake_case							=				precision
     _snake_case							=				ceil(precision / 14   )
     _snake_case							=				426_880 * Decimal(10_005   ).sqrt()
     _snake_case							=				1
     _snake_case							=				13_591_409
     _snake_case							=				Decimal(_UpperCamelCase   )
     for k in range(1 ,						_UpperCamelCase   ):
          _snake_case							=				factorial(6 * k   ) // (factorial(3 * k   ) * factorial(_UpperCamelCase   ) ** 3)
          linear_term += 545_140_134
          exponential_term *= -262_537_412_640_768_000
          partial_sum += Decimal(multinomial_term * linear_term   ) / exponential_term
     return str(constant_term / partial_sum   )[:-1]


if __name__ == "__main__":
   UpperCamelCase_						:      Any       =						50
   print(F'The first {n} digits of pi is: {pi(n)}')


