


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

   '''simple docstring'''







   def __init__(  self  : List[Any]       ,  _lowerCamelCase  : Optional[Any]       ,  _lowerCamelCase  : bool = True       ,  _lowerCamelCase  : Dict[str, int] = None       ,  _lowerCamelCase  : int = 3_2       ,  _lowerCamelCase  : bool = True       ,  _lowerCamelCase  : Union[int, float] = 1 / 2_5_5       ,  _lowerCamelCase  : bool = True       ,  _lowerCamelCase  : bool = True       ,  _lowerCamelCase  : Optional[Union[float, List[float]]] = [0.48_145_466, 0.4_578_275, 0.40_821_073]       ,  _lowerCamelCase  : Optional[Union[float, List[float]]] = [0.26_862_954, 0.26_130_258, 0.27_577_711]       ,  _lowerCamelCase  : bool = True       ,  _lowerCamelCase  : List[str]=7       ,  _lowerCamelCase  : Union[str, Any]=3_0       ,  _lowerCamelCase  : Tuple=4_0_0       ,  _lowerCamelCase  : List[Any]=3       ,  ):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[Any]       						=						parent
         __lowerCamelCase     :      Any       						=						do_resize
         __lowerCamelCase     :      str       						=						size if size is not None else {"shortest_edge": 2_8_8}
         __lowerCamelCase     :      Any       						=						size_divisor
         __lowerCamelCase     :      str       						=						do_rescale
         __lowerCamelCase     :      Any       						=						rescale_factor
         __lowerCamelCase     :      Any       						=						do_normalize
         __lowerCamelCase     :      Union[str, Any]       						=						do_center_crop
         __lowerCamelCase     :      Tuple       						=						image_mean
         __lowerCamelCase     :      Any       						=						image_std
         __lowerCamelCase     :      Tuple       						=						do_pad
         __lowerCamelCase     :      Tuple       						=						batch_size
         __lowerCamelCase     :      str       						=						num_channels
         __lowerCamelCase     :      List[Any]       						=						min_resolution
         __lowerCamelCase     :      str       						=						max_resolution

   def   _snake_case    (  self  : List[str]							):






         '''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   _snake_case    (  self  : Any       ,  _lowerCamelCase  : List[str]       ,  _lowerCamelCase  : Optional[Any]=False							):






         '''simple docstring'''



         if not batched:
               __lowerCamelCase     :      int       						=						self.size["shortest_edge"]
               __lowerCamelCase     :      Optional[Any]       						=						image_inputs[0]
               if isinstance(_lowerCamelCase       ,  Image.Image							):
                     __lowerCamelCase     :      Union[str, Any]       						=						image.size
               else:
                     __lowerCamelCase     :      int       						=						image.shape[1], image.shape[2]
               __lowerCamelCase     :      Any       						=						size / min(_lowerCamelCase       ,  _lowerCamelCase							)
               if h < w:
                     __lowerCamelCase     :      Dict       						=						size, scale * w
               else:
                     __lowerCamelCase     :      Tuple       						=						scale * h, size

               __lowerCamelCase     :      Tuple       						=						int((1_3_3_3 / 8_0_0) * size							)
               if max(_lowerCamelCase       ,  _lowerCamelCase							) > max_size:
                     __lowerCamelCase     :      Tuple       						=						max_size / max(_lowerCamelCase       ,  _lowerCamelCase							)
                     __lowerCamelCase     :      Union[str, Any]       						=						newh * scale
                     __lowerCamelCase     :      List[str]       						=						neww * scale

               __lowerCamelCase     :      str       						=						int(newh + 0.5							), int(neww + 0.5							)
               __lowerCamelCase     :      str       						=						(
                   newh // self.size_divisor * self.size_divisor,
                   neww // self.size_divisor * self.size_divisor,
               )

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

         return expected_height, expected_width



@require_torch
@require_vision
class 							_UpperCamelCase (						_UpperCamelCase,unittest.TestCase						):

   '''simple docstring'''







   a_				:							Union[str, Any]    = BridgeTowerImageProcessor if is_vision_available() else None

   def   _snake_case    (  self  : Dict							):






         '''simple docstring'''



         __lowerCamelCase     :      int       						=						BridgeTowerImageProcessingTester(self							)

   @property
   def   _snake_case    (  self  : Union[str, Any]							):






         '''simple docstring'''



         return self.image_processor_tester.prepare_image_processor_dict()

   def   _snake_case    (  self  : Dict							):






         '''simple docstring'''



         __lowerCamelCase     :      Dict       						=						self.image_processing_class(**self.image_processor_dict							)
         self.assertTrue(hasattr(_lowerCamelCase       ,  """image_mean"""							)							)
         self.assertTrue(hasattr(_lowerCamelCase       ,  """image_std"""							)							)
         self.assertTrue(hasattr(_lowerCamelCase       ,  """do_normalize"""							)							)
         self.assertTrue(hasattr(_lowerCamelCase       ,  """do_resize"""							)							)
         self.assertTrue(hasattr(_lowerCamelCase       ,  """size"""							)							)
         self.assertTrue(hasattr(_lowerCamelCase       ,  """size_divisor"""							)							)

   def   _snake_case    (  self  : Optional[int]							):






         '''simple docstring'''



         pass

   def   _snake_case    (  self  : List[Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      List[str]       						=						self.image_processing_class(**self.image_processor_dict							)
         # create random PIL images
         __lowerCamelCase     :      Optional[int]       						=						prepare_image_inputs(self.image_processor_tester       ,  equal_resolution=_lowerCamelCase							)
         for image in image_inputs:
               self.assertIsInstance(_lowerCamelCase       ,  Image.Image							)

         # Test not batched input
         __lowerCamelCase     :      Tuple       						=						image_processing(image_inputs[0]       ,  return_tensors="""pt"""							).pixel_values

         __lowerCamelCase     :      str       						=						self.image_processor_tester.get_expected_values(_lowerCamelCase							)
         self.assertEqual(
             encoded_images.shape       ,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)       ,  )

         # Test batched
         __lowerCamelCase     :      List[Any]       						=						image_processing(_lowerCamelCase       ,  return_tensors="""pt"""							).pixel_values

         __lowerCamelCase     :      Tuple       						=						self.image_processor_tester.get_expected_values(_lowerCamelCase       ,  batched=_lowerCamelCase							)
         self.assertEqual(
             encoded_images.shape       ,  (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             )       ,  )

   def   _snake_case    (  self  : int							):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[Any]       						=						self.image_processing_class(**self.image_processor_dict							)
         # create random numpy tensors
         __lowerCamelCase     :      Optional[Any]       						=						prepare_image_inputs(self.image_processor_tester       ,  equal_resolution=_lowerCamelCase       ,  numpify=_lowerCamelCase							)
         for image in image_inputs:
               self.assertIsInstance(_lowerCamelCase       ,  np.ndarray							)

         # Test not batched input
         __lowerCamelCase     :      str       						=						image_processing(image_inputs[0]       ,  return_tensors="""pt"""							).pixel_values

         __lowerCamelCase     :      Optional[int]       						=						self.image_processor_tester.get_expected_values(_lowerCamelCase							)
         self.assertEqual(
             encoded_images.shape       ,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)       ,  )

         # Test batched
         __lowerCamelCase     :      int       						=						image_processing(_lowerCamelCase       ,  return_tensors="""pt"""							).pixel_values

         __lowerCamelCase     :      List[Any]       						=						self.image_processor_tester.get_expected_values(_lowerCamelCase       ,  batched=_lowerCamelCase							)
         self.assertEqual(
             encoded_images.shape       ,  (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             )       ,  )


   def   _snake_case    (  self  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase     :      Any       						=						self.image_processing_class(**self.image_processor_dict							)
         # create random PyTorch tensors
         __lowerCamelCase     :      Optional[int]       						=						prepare_image_inputs(self.image_processor_tester       ,  equal_resolution=_lowerCamelCase       ,  torchify=_lowerCamelCase							)
         for image in image_inputs:
               self.assertIsInstance(_lowerCamelCase       ,  torch.Tensor							)

         # Test not batched input
         __lowerCamelCase     :      List[str]       						=						image_processing(image_inputs[0]       ,  return_tensors="""pt"""							).pixel_values

         __lowerCamelCase     :      int       						=						self.image_processor_tester.get_expected_values(_lowerCamelCase							)
         self.assertEqual(
             encoded_images.shape       ,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)       ,  )

         # Test batched
         __lowerCamelCase     :      List[Any]       						=						image_processing(_lowerCamelCase       ,  return_tensors="""pt"""							).pixel_values

         __lowerCamelCase     :      Tuple       						=						self.image_processor_tester.get_expected_values(_lowerCamelCase       ,  batched=_lowerCamelCase							)
         self.assertEqual(
             encoded_images.shape       ,  (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             )       ,  )







def   _UpperCAmelCase       (     ):
      """simple docstring"""




      __lowerCamelCase     :      Optional[int]       						=						[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

      __lowerCamelCase     :      str       						=						6
      __lowerCamelCase     :      Optional[int]       						=						1
      __lowerCamelCase     :      Optional[int]       						=						1_901

      __lowerCamelCase     :      Optional[Any]       						=						0

      while year < 2_001:
            day += 7

            if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
                  if day > days_per_month[month - 1] and month != 2:
                        month += 1
                        __lowerCamelCase     :      Tuple       						=						day - days_per_month[month - 2]
                  elif day > 29 and month == 2:
                        month += 1
                        __lowerCamelCase     :      str       						=						day - 29
            else:
                  if day > days_per_month[month - 1]:
                        month += 1
                        __lowerCamelCase     :      Any       						=						day - days_per_month[month - 2]

            if month > 12:
                  year += 1
                  __lowerCamelCase     :      Optional[Any]       						=						1

            if year < 2_001 and day == 1:
                  sundays += 1
      return sundays


if __name__ == "__main__":
    print(solution())



