
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 EfficientNetImageProcessor

class 		__magic_name__				( unittest.TestCase					):


  """simple docstring"""





  def __init__(					self	,		a__	,		a__=13	,		a__=3	,		a__=18	,		a__=30	,		a__=4_00	,		a__=True	,		a__=None	,		a__=True	,		a__=[0.5, 0.5, 0.5]	,		a__=[0.5, 0.5, 0.5]	,		):
    _lowerCamelCase      =						size if size is not None else {'''height''': 18, '''width''': 18}
    _lowerCamelCase      =						parent
    _lowerCamelCase      =						batch_size
    _lowerCamelCase      =						num_channels
    _lowerCamelCase      =						image_size
    _lowerCamelCase      =						min_resolution
    _lowerCamelCase      =						max_resolution
    _lowerCamelCase      =						do_resize
    _lowerCamelCase      =						size
    _lowerCamelCase      =						do_normalize
    _lowerCamelCase      =						image_mean
    _lowerCamelCase      =						image_std


  def     _UpperCAmelCase  (					self		):
    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 		__magic_name__				( lowercase_						,unittest.TestCase					):


  """simple docstring"""





  _UpperCamelCase						 = EfficientNetImageProcessor if is_vision_available() else None


  def     _UpperCAmelCase  (					self		):
    _lowerCamelCase      =						EfficientNetImageProcessorTester(self		)


  @property
  def     _UpperCAmelCase  (					self		):
    return self.image_processor_tester.prepare_image_processor_dict()


  def     _UpperCAmelCase  (					self		):
    _lowerCamelCase      =						self.image_processing_class(**self.image_processor_dict		)
    self.assertTrue(hasattr(a__	,		'''image_mean'''		)		)
    self.assertTrue(hasattr(a__	,		'''image_std'''		)		)
    self.assertTrue(hasattr(a__	,		'''do_normalize'''		)		)
    self.assertTrue(hasattr(a__	,		'''do_resize'''		)		)
    self.assertTrue(hasattr(a__	,		'''size'''		)		)


  def     _UpperCAmelCase  (					self		):
    _lowerCamelCase      =						self.image_processing_class.from_dict(self.image_processor_dict		)
    self.assertEqual(image_processor.size	,		{'''height''': 18, '''width''': 18}		)

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


  def     _UpperCAmelCase  (					self		):
    # Initialize image_processing
    _lowerCamelCase      =						self.image_processing_class(**self.image_processor_dict		)
    # create random PIL images
    _lowerCamelCase      =						prepare_image_inputs(self.image_processor_tester	,		equal_resolution=a__		)
    for image in image_inputs:
      self.assertIsInstance(a__	,		Image.Image		)

    # Test not batched input
    _lowerCamelCase      =						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
    _lowerCamelCase      =						image_processing(a__	,		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'''],
        )	,		)


  def     _UpperCAmelCase  (					self		):
    # Initialize image_processing
    _lowerCamelCase      =						self.image_processing_class(**self.image_processor_dict		)
    # create random numpy tensors
    _lowerCamelCase      =						prepare_image_inputs(self.image_processor_tester	,		equal_resolution=a__	,		numpify=a__		)
    for image in image_inputs:
      self.assertIsInstance(a__	,		np.ndarray		)

    # Test not batched input
    _lowerCamelCase      =						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
    _lowerCamelCase      =						image_processing(a__	,		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'''],
        )	,		)


  def     _UpperCAmelCase  (					self		):
    # Initialize image_processing
    _lowerCamelCase      =						self.image_processing_class(**self.image_processor_dict		)
    # create random PyTorch tensors
    _lowerCamelCase      =						prepare_image_inputs(self.image_processor_tester	,		equal_resolution=a__	,		torchify=a__		)
    for image in image_inputs:
      self.assertIsInstance(a__	,		torch.Tensor		)

    # Test not batched input
    _lowerCamelCase      =						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
    _lowerCamelCase      =						image_processing(a__	,		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'''],
        )	,		)






from __future__ import annotations

from collections.abc import Iterable
from dataclasses import dataclass
from typing import Any

class 		__magic_name__				:


  """simple docstring"""





  _UpperCamelCase						 = ("_front", "_back", "_len")

  @dataclass
  class 		__magic_name__				:


    """simple docstring"""





    _UpperCamelCase						 = None
    _UpperCamelCase						 = None
    _UpperCamelCase						 = None







  class 		__magic_name__				:


    """simple docstring"""





    _UpperCamelCase						 = ("_cur",)


    def __init__(					self	,		a__		):
      _lowerCamelCase      =						cur


    def __iter__(					self		):
      return self


    def     _UpperCAmelCase  (					self		):
      if self._cur is None:
        # finished iterating
        raise StopIteration
      _lowerCamelCase      =						self._cur.val
      _lowerCamelCase      =						self._cur.next_node

      return val







  def __init__(					self	,		a__ = None		):
    _lowerCamelCase      =						None
    _lowerCamelCase      =						None
    _lowerCamelCase      =						0

    if iterable is not None:
      # append every value to the deque
      for val in iterable:
        self.append(a__		)


  def     _UpperCAmelCase  (					self	,		a__		):
    _lowerCamelCase      =						self._Node(a__	,		a__	,		a__		)
    if self.is_empty():
      # front = back
      _lowerCamelCase      =						_lowerCamelCase      =						node
      _lowerCamelCase      =						1
    else:
      # connect nodes
      _lowerCamelCase      =						node
      _lowerCamelCase      =						self._back
      _lowerCamelCase      =						node  # assign new back to the new node

      self._len += 1

      # make sure there were no errors
      assert not self.is_empty(), "Error on appending value."


  def     _UpperCAmelCase  (					self	,		a__		):
    _lowerCamelCase      =						self._Node(a__	,		a__	,		a__		)
    if self.is_empty():
      # front = back
      _lowerCamelCase      =						_lowerCamelCase      =						node
      _lowerCamelCase      =						1
    else:
      # connect nodes
      _lowerCamelCase      =						self._front
      _lowerCamelCase      =						node
      _lowerCamelCase      =						node  # assign new front to the new node

      self._len += 1

      # make sure there were no errors
      assert not self.is_empty(), "Error on appending value."


  def     _UpperCAmelCase  (					self	,		a__		):
    for val in iterable:
      self.append(a__		)


  def     _UpperCAmelCase  (					self	,		a__		):
    for val in iterable:
      self.appendleft(a__		)


  def     _UpperCAmelCase  (					self		):
    assert not self.is_empty(), "Deque is empty."

    _lowerCamelCase      =						self._back
    _lowerCamelCase      =						self._back.prev_node  # set new back
    # drop the last node - python will deallocate memory automatically
    _lowerCamelCase      =						None

    self._len -= 1

    return topop.val


  def     _UpperCAmelCase  (					self		):
    assert not self.is_empty(), "Deque is empty."

    _lowerCamelCase      =						self._front
    _lowerCamelCase      =						self._front.next_node  # set new front and drop the first node
    _lowerCamelCase      =						None

    self._len -= 1

    return topop.val


  def     _UpperCAmelCase  (					self		):
    return self._front is None


  def __len__(					self		):
    return self._len


  def __eq__(					self	,		a__		):

    if not isinstance(a__	,		a__		):
      return NotImplemented

    _lowerCamelCase      =						self._front
    _lowerCamelCase      =						other._front

    # if the length of the dequeues are not the same, they are not equal
    if len(self		) != len(a__		):
      return False

    while me is not None and oth is not None:
      # compare every value
      if me.val != oth.val:
        return False
      _lowerCamelCase      =						me.next_node
      _lowerCamelCase      =						oth.next_node

    return True


  def __iter__(					self		):
    return Deque._Iterator(self._front		)


  def __repr__(					self		):
    _lowerCamelCase      =						[]
    _lowerCamelCase      =						self._front
    while aux is not None:
      # append the values in a list to display
      values_list.append(aux.val		)
      _lowerCamelCase      =						aux.next_node

    return f'''[{', '.join(repr(a__		) for val in values_list		)}]'''


if __name__ == "__main__":
  import doctest

  doctest.testmod()




