


'''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 ViTImageProcessor





class 						__SCREAMING_SNAKE_CASE					(      unittest.TestCase ):






     def __init__(			self     ,							__UpperCamelCase     ,							__UpperCamelCase=13     ,							__UpperCamelCase=3     ,							__UpperCamelCase=224     ,							__UpperCamelCase=30     ,							__UpperCamelCase=400     ,							__UpperCamelCase=True     ,							__UpperCamelCase=None     ,							__UpperCamelCase=True     ,							__UpperCamelCase=[0.5, 0.5, 0.5]     ,							__UpperCamelCase=[0.5, 0.5, 0.5]     ,							)       ->    Dict:
          _a						=		size if size is not None else {"height": 18, "width": 18}
          _a						=		parent
          _a						=		batch_size
          _a						=		num_channels
          _a						=		image_size
          _a						=		min_resolution
          _a						=		max_resolution
          _a						=		do_resize
          _a						=		size
          _a						=		do_normalize
          _a						=		image_mean
          _a						=		image_std






     def  a_					(			self		)       ->    List[Any]:
          return {
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_normalize": self.do_normalize,
              "do_resize": self.do_resize,
              "size": self.size,
          }







@require_torch
@require_vision
class 						__SCREAMING_SNAKE_CASE					(      lowerCamelCase__ ,			unittest.TestCase ):
     UpperCAmelCase 					=				ViTImageProcessor if is_vision_available() else None






     def  a_					(			self		)       ->    Optional[int]:
          _a						=		EfficientFormerImageProcessorTester(self		)






     @property
     def  a_					(			self		)       ->    Optional[Any]:
          return self.image_proc_tester.prepare_image_processor_dict()






     def  a_					(			self		)       ->    List[str]:
          _a						=		self.image_processing_class(**self.image_processor_dict		)
          self.assertTrue(hasattr(__UpperCamelCase     ,							"image_mean"		)		)
          self.assertTrue(hasattr(__UpperCamelCase     ,							"image_std"		)		)
          self.assertTrue(hasattr(__UpperCamelCase     ,							"do_normalize"		)		)
          self.assertTrue(hasattr(__UpperCamelCase     ,							"do_resize"		)		)
          self.assertTrue(hasattr(__UpperCamelCase     ,							"size"		)		)






     def  a_					(			self		)       ->    Dict:
          pass






     def  a_					(			self		)       ->    Dict:
          # Initialize image_processor
          _a						=		self.image_processing_class(**self.image_processor_dict		)
          # create random PIL images
          _a						=		prepare_image_inputs(self.image_proc_tester     ,							equal_resolution=__UpperCamelCase		)
          for image in image_inputs:
               self.assertIsInstance(__UpperCamelCase     ,							Image.Image		)

          # Test not batched input
          _a						=		image_processor(image_inputs[0]     ,							return_tensors="pt"		).pixel_values
          self.assertEqual(
              encoded_images.shape     ,							(
                  1,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size["height"],
                  self.image_proc_tester.size["width"],
              )     ,							)

          # Test batched
          _a						=		image_processor(__UpperCamelCase     ,							return_tensors="pt"		).pixel_values
          self.assertEqual(
              encoded_images.shape     ,							(
                  self.image_proc_tester.batch_size,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size["height"],
                  self.image_proc_tester.size["width"],
              )     ,							)






     def  a_					(			self		)       ->    str:
          # Initialize image_processor
          _a						=		self.image_processing_class(**self.image_processor_dict		)
          # create random numpy tensors
          _a						=		prepare_image_inputs(self.image_proc_tester     ,							equal_resolution=__UpperCamelCase     ,							numpify=__UpperCamelCase		)
          for image in image_inputs:
               self.assertIsInstance(__UpperCamelCase     ,							np.ndarray		)

          # Test not batched input
          _a						=		image_processor(image_inputs[0]     ,							return_tensors="pt"		).pixel_values
          self.assertEqual(
              encoded_images.shape     ,							(
                  1,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size["height"],
                  self.image_proc_tester.size["width"],
              )     ,							)

          # Test batched
          _a						=		image_processor(__UpperCamelCase     ,							return_tensors="pt"		).pixel_values
          self.assertEqual(
              encoded_images.shape     ,							(
                  self.image_proc_tester.batch_size,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size["height"],
                  self.image_proc_tester.size["width"],
              )     ,							)






     def  a_					(			self		)       ->    List[str]:
          # Initialize image_processor
          _a						=		self.image_processing_class(**self.image_processor_dict		)
          # create random PyTorch tensors
          _a						=		prepare_image_inputs(self.image_proc_tester     ,							equal_resolution=__UpperCamelCase     ,							torchify=__UpperCamelCase		)
          for image in image_inputs:
               self.assertIsInstance(__UpperCamelCase     ,							torch.Tensor		)

          # Test not batched input
          _a						=		image_processor(image_inputs[0]     ,							return_tensors="pt"		).pixel_values
          self.assertEqual(
              encoded_images.shape     ,							(
                  1,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size["height"],
                  self.image_proc_tester.size["width"],
              )     ,							)

          # Test batched
          _a						=		image_processor(__UpperCamelCase     ,							return_tensors="pt"		).pixel_values
          self.assertEqual(
              encoded_images.shape     ,							(
                  self.image_proc_tester.batch_size,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size["height"],
                  self.image_proc_tester.size["width"],
              )     ,							)





'''simple docstring'''

from math import factorial, pi






def __UpperCamelCase   (			__lowerCamelCase		: float      ,  __lowerCamelCase		: int = 30				)      ->     float:







     '''simple docstring'''






     if not isinstance(__lowerCamelCase      ,  (int, float)				):
          raise ValueError("maclaurin_sin() requires either an int or float for theta"				)

     if not isinstance(__lowerCamelCase      ,  __lowerCamelCase				) or accuracy <= 0:
          raise ValueError("maclaurin_sin() requires a positive int for accuracy"				)

     _a						=		float(__lowerCamelCase				)
     _a						=		theta // (2 * pi)
     theta -= 2 * div * pi
     return sum(
         (-1) ** r * theta ** (2 * r + 1) / factorial(2 * r + 1				) for r in range(__lowerCamelCase				)				)






def __UpperCamelCase   (			__lowerCamelCase		: float      ,  __lowerCamelCase		: int = 30				)      ->     float:







     '''simple docstring'''






     if not isinstance(__lowerCamelCase      ,  (int, float)				):
          raise ValueError("maclaurin_cos() requires either an int or float for theta"				)

     if not isinstance(__lowerCamelCase      ,  __lowerCamelCase				) or accuracy <= 0:
          raise ValueError("maclaurin_cos() requires a positive int for accuracy"				)

     _a						=		float(__lowerCamelCase				)
     _a						=		theta // (2 * pi)
     theta -= 2 * div * pi
     return sum((-1) ** r * theta ** (2 * r) / factorial(2 * r				) for r in range(__lowerCamelCase				)				)


if __name__ == "__main__":
   import doctest

   doctest.testmod()

   print(maclaurin_sin(10))
   print(maclaurin_sin(-10))
   print(maclaurin_sin(10, 15))
   print(maclaurin_sin(-10, 15))

   print(maclaurin_cos(5))
   print(maclaurin_cos(-5))
   print(maclaurin_cos(10, 15))
   print(maclaurin_cos(-10, 15))

