

import unittest
from typing import Dict, List, Optional, Union

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 BridgeTowerImageProcessor
class  _A		(  unittest.TestCase):

  def __init__(				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE = True ,					_SCREAMING_SNAKE_CASE = None ,					_SCREAMING_SNAKE_CASE = 32 ,					_SCREAMING_SNAKE_CASE = True ,					_SCREAMING_SNAKE_CASE = 1 / 255 ,					_SCREAMING_SNAKE_CASE = True ,					_SCREAMING_SNAKE_CASE = True ,					_SCREAMING_SNAKE_CASE = [0.48145466, 0.4578275, 0.40821073] ,					_SCREAMING_SNAKE_CASE = [0.26862954, 0.26130258, 0.27577711] ,					_SCREAMING_SNAKE_CASE = True ,					_SCREAMING_SNAKE_CASE=7 ,					_SCREAMING_SNAKE_CASE=30 ,					_SCREAMING_SNAKE_CASE=400 ,					_SCREAMING_SNAKE_CASE=3 ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     parent
        SCREAMING_SNAKE_CASE_				:  Any           =     do_resize
        SCREAMING_SNAKE_CASE_				:  Any           =     size if size is not None else {'shortest_edge': 288}
        SCREAMING_SNAKE_CASE_				:  Any           =     size_divisor
        SCREAMING_SNAKE_CASE_				:  List[str]           =     do_rescale
        SCREAMING_SNAKE_CASE_				:  str           =     rescale_factor
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     do_normalize
        SCREAMING_SNAKE_CASE_				:  List[str]           =     do_center_crop
        SCREAMING_SNAKE_CASE_				:  List[str]           =     image_mean
        SCREAMING_SNAKE_CASE_				:  List[str]           =     image_std
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     do_pad
        SCREAMING_SNAKE_CASE_				:  int           =     batch_size
        SCREAMING_SNAKE_CASE_				:  List[str]           =     num_channels
        SCREAMING_SNAKE_CASE_				:  Dict           =     min_resolution
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     max_resolution

  def  UpperCAmelCase    (				self					):





        """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,
            "size_divisor": self.size_divisor,
        }



  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE=False					):





        """simple docstring"""







        if not batched:
              SCREAMING_SNAKE_CASE_				:  List[str]           =     self.size['shortest_edge']
              SCREAMING_SNAKE_CASE_				:  Dict           =     image_inputs[0]
              if isinstance(_SCREAMING_SNAKE_CASE ,					Image.Image					):
                    SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Optional[int]           =     image.size
              else:
                    SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  List[Any]           =     image.shape[1], image.shape[2]
              SCREAMING_SNAKE_CASE_				:  str           =     size / min(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              if h < w:
                    SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  List[Any]           =     size, scale * w
              else:
                    SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Optional[int]           =     scale * h, size

              SCREAMING_SNAKE_CASE_				:  Tuple           =     int((1333 / 800) * size					)
              if max(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					) > max_size:
                    SCREAMING_SNAKE_CASE_				:  Optional[int]           =     max_size / max(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
                    SCREAMING_SNAKE_CASE_				:  List[str]           =     newh * scale
                    SCREAMING_SNAKE_CASE_				:  str           =     neww * scale

              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Dict           =     int(newh + 0.5					), int(neww + 0.5					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Any           =     (
                  newh // self.size_divisor * self.size_divisor,
                  neww // self.size_divisor * self.size_divisor,
              )

        else:
              SCREAMING_SNAKE_CASE_				:  List[str]           =     []
              for image in image_inputs:
                    SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Dict           =     self.get_expected_values([image]					)
                    expected_values.append((expected_height, expected_width)					)
              SCREAMING_SNAKE_CASE_				:  int           =     max(_SCREAMING_SNAKE_CASE ,					key=lambda _SCREAMING_SNAKE_CASE					: item[0]					)[0]
              SCREAMING_SNAKE_CASE_				:  Any           =     max(_SCREAMING_SNAKE_CASE ,					key=lambda _SCREAMING_SNAKE_CASE					: item[1]					)[1]

        return expected_height, expected_width

@require_torch
@require_vision
class  _A		(  __magic_name__   ,     unittest.TestCase):
  SCREAMING_SNAKE_CASE    :      Optional[Any]       =  BridgeTowerImageProcessor if is_vision_available() else None

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     BridgeTowerImageProcessingTester(self					)

  @property
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        return self.image_processor_tester.prepare_image_processor_dict()

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Dict           =     self.image_processing_class(**self.image_processor_dict					)
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,					'image_mean'					)					)
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,					'image_std'					)					)
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,					'do_normalize'					)					)
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,					'do_resize'					)					)
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,					'size'					)					)
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,					'size_divisor'					)					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        pass

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  str           =     self.image_processing_class(**self.image_processor_dict					)
        # create random PIL images
        SCREAMING_SNAKE_CASE_				:  List[str]           =     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
        SCREAMING_SNAKE_CASE_				:  int           =     image_processing(image_inputs[0] ,					return_tensors='pt'					).pixel_values

        SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Tuple           =     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE					)
        self.assertEqual(
            encoded_images.shape ,					(1, self.image_processor_tester.num_channels, expected_height, expected_width) ,					)

        # Test batched
        SCREAMING_SNAKE_CASE_				:  str           =     image_processing(_SCREAMING_SNAKE_CASE ,					return_tensors='pt'					).pixel_values

        SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Any           =     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE ,					batched=_SCREAMING_SNAKE_CASE					)
        self.assertEqual(
            encoded_images.shape ,					(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            ) ,					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Tuple           =     self.image_processing_class(**self.image_processor_dict					)
        # create random numpy tensors
        SCREAMING_SNAKE_CASE_				:  Tuple           =     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
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     image_processing(image_inputs[0] ,					return_tensors='pt'					).pixel_values

        SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE					)
        self.assertEqual(
            encoded_images.shape ,					(1, self.image_processor_tester.num_channels, expected_height, expected_width) ,					)

        # Test batched
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     image_processing(_SCREAMING_SNAKE_CASE ,					return_tensors='pt'					).pixel_values

        SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE ,					batched=_SCREAMING_SNAKE_CASE					)
        self.assertEqual(
            encoded_images.shape ,					(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            ) ,					)



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  int           =     self.image_processing_class(**self.image_processor_dict					)
        # create random PyTorch tensors
        SCREAMING_SNAKE_CASE_				:  int           =     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
        SCREAMING_SNAKE_CASE_				:  int           =     image_processing(image_inputs[0] ,					return_tensors='pt'					).pixel_values

        SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Tuple           =     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE					)
        self.assertEqual(
            encoded_images.shape ,					(1, self.image_processor_tester.num_channels, expected_height, expected_width) ,					)

        # Test batched
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     image_processing(_SCREAMING_SNAKE_CASE ,					return_tensors='pt'					).pixel_values

        SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Any           =     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE ,					batched=_SCREAMING_SNAKE_CASE					)
        self.assertEqual(
            encoded_images.shape ,					(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            ) ,					)









def    A_  (							a					,   a  ):

      """simple docstring"""



      return int((input_a, input_a).count(0  ) != 0  )

def    A_  (							):

      """simple docstring"""



      assert nand_gate(0					,   0  ) == 1
      assert nand_gate(0					,   1  ) == 1
      assert nand_gate(1					,   0  ) == 1
      assert nand_gate(1					,   1  ) == 0


if __name__ == "__main__":
    print(nand_gate(0, 0))
    print(nand_gate(0, 1))
    print(nand_gate(1, 0))
    print(nand_gate(1, 1))






