



"""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 				lowercase__       (   unittest.TestCase				):







       '''simple docstring'''


       def __init__(							self      :  Optional[Any]		,    _UpperCAmelCase      :  str		,    _UpperCAmelCase      :  Optional[int]=13		,    _UpperCAmelCase      :  Dict=3		,    _UpperCAmelCase      :  List[str]=224		,    _UpperCAmelCase      :  Optional[Any]=30		,    _UpperCAmelCase      :  Optional[Any]=400		,    _UpperCAmelCase      :  Dict=True		,    _UpperCAmelCase      :  Tuple=None		,    _UpperCAmelCase      :  str=True		,    _UpperCAmelCase      :  int=[0.5, 0.5, 0.5]		,    _UpperCAmelCase      :  List[Any]=[0.5, 0.5, 0.5]		,    )			->						Optional[Any]:


             '''simple docstring'''




             UpperCAmelCase_      			=							size if size is not None else {"height": 18, "width": 18}
             UpperCAmelCase_      			=							parent
             UpperCAmelCase_      			=							batch_size
             UpperCAmelCase_      			=							num_channels
             UpperCAmelCase_      			=							image_size
             UpperCAmelCase_      			=							min_resolution
             UpperCAmelCase_      			=							max_resolution
             UpperCAmelCase_      			=							do_resize
             UpperCAmelCase_      			=							size
             UpperCAmelCase_      			=							do_normalize
             UpperCAmelCase_      			=							image_mean
             UpperCAmelCase_      			=							image_std







       def 					lowercase__    (							self      :  Dict   )			->						Optional[int]:


             '''simple docstring'''




             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 				lowercase__       (   SCREAMING_SNAKE_CASE    , unittest.TestCase				):







       '''simple docstring'''


       UpperCamelCase						=					ViTImageProcessor if is_vision_available() else None



       def 					lowercase__    (							self      :  int   )			->						Dict:


             '''simple docstring'''




             UpperCAmelCase_      			=							EfficientFormerImageProcessorTester(self   )



       @property
       def 					lowercase__    (							self      :  Any   )			->						Dict:


             '''simple docstring'''




             return self.image_proc_tester.prepare_image_processor_dict()



       def 					lowercase__    (							self      :  Dict   )			->						str:


             '''simple docstring'''




             UpperCAmelCase_      			=							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 					lowercase__    (							self      :  Union[str, Any]   )			->						str:


             '''simple docstring'''




             pass



       def 					lowercase__    (							self      :  Optional[int]   )			->						Any:


             '''simple docstring'''




             UpperCAmelCase_      			=							self.image_processing_class(**self.image_processor_dict   )
             # create random PIL images
             UpperCAmelCase_      			=							prepare_image_inputs(self.image_proc_tester		,    equal_resolution=_UpperCAmelCase   )
             for image in image_inputs:
                   self.assertIsInstance(_UpperCAmelCase		,    Image.Image   )

             # Test not batched input
             UpperCAmelCase_      			=							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
             UpperCAmelCase_      			=							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 					lowercase__    (							self      :  Optional[Any]   )			->						Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_      			=							self.image_processing_class(**self.image_processor_dict   )
             # create random numpy tensors
             UpperCAmelCase_      			=							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
             UpperCAmelCase_      			=							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
             UpperCAmelCase_      			=							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 					lowercase__    (							self      :  List[str]   )			->						str:


             '''simple docstring'''




             UpperCAmelCase_      			=							self.image_processing_class(**self.image_processor_dict   )
             # create random PyTorch tensors
             UpperCAmelCase_      			=							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
             UpperCAmelCase_      			=							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
             UpperCAmelCase_      			=							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 collections.abc import Iterable
from typing import Generic, TypeVar

lowerCamelCase       	=						TypeVar("""_T""")
class 				lowercase__       (   Generic[_T]				):







       '''simple docstring'''


       def __init__(							self      :  int		,    _UpperCAmelCase      :  Iterable[_T] | None = None   )			->						None:


             '''simple docstring'''




             UpperCAmelCase_      			=							list(iterable or []   )
             UpperCAmelCase_      			=							[]



       def __len__(							self      :  Optional[int]   )			->						int:


             '''simple docstring'''




             return len(self._stacka   ) + len(self._stacka   )



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


             '''simple docstring'''




             return F"""Queue({tuple(self._stacka[::-1] + self._stacka   )})"""



       def 					lowercase__    (							self      :  Optional[Any]		,    _UpperCAmelCase      :  _T   )			->						None:


             '''simple docstring'''




             self._stacka.append(_UpperCAmelCase   )







       def 					lowercase__    (							self      :  Dict   )			->						_T:


             '''simple docstring'''




             UpperCAmelCase_      			=							self._stacka.pop
             UpperCAmelCase_      			=							self._stacka.append

             if not self._stacka:
                   while self._stacka:
                         stacka_append(stacka_pop()   )

             if not self._stacka:
                   raise IndexError("Queue is empty"   )
             return self._stacka.pop()


if __name__ == "__main__":
  from doctest import testmod

  testmod()




