


'''simple docstring'''







import unittest

import numpy as np

from transformers.file_utils import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision

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 DPTImageProcessor


class 			lowerCAmelCase_    (							unittest.TestCase   ):





  """simple docstring"""



  def __init__(       self  :				Optional[Any]					,				SCREAMING_SNAKE_CASE__  :				str					,				SCREAMING_SNAKE_CASE__  :				Tuple=7					,				SCREAMING_SNAKE_CASE__  :				Tuple=3					,				SCREAMING_SNAKE_CASE__  :				str=1_8					,				SCREAMING_SNAKE_CASE__  :				int=3_0					,				SCREAMING_SNAKE_CASE__  :				Optional[int]=4_0_0					,				SCREAMING_SNAKE_CASE__  :				List[Any]=True					,				SCREAMING_SNAKE_CASE__  :				List[str]=None					,				SCREAMING_SNAKE_CASE__  :				List[Any]=True					,				SCREAMING_SNAKE_CASE__  :				int=[0.5, 0.5, 0.5]					,				SCREAMING_SNAKE_CASE__  :				List[str]=[0.5, 0.5, 0.5]					,				):





       '''simple docstring'''

       __a   			= size if size is not None else {"""height""": 1_8, """width""": 1_8}
       __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  :				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 			lowerCAmelCase_    (							snake_case__		,     unittest.TestCase   ):





  """simple docstring"""



  a_							:str				       =DPTImageProcessor if is_vision_available() else None

  def __a    (       self  :				Union[str, Any]    ):





       '''simple docstring'''

       __a   			= DPTImageProcessingTester(self    )

  @property
  def __a    (       self  :				Tuple    ):





       '''simple docstring'''

       return self.image_processor_tester.prepare_image_processor_dict()

  def __a    (       self  :				Optional[Any]    ):





       '''simple docstring'''

       __a   			= 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"""    )    )

  def __a    (       self  :				Dict    ):





       '''simple docstring'''

       __a   			= self.image_processing_class.from_dict(self.image_processor_dict    )
       self.assertEqual(image_processor.size					,				{"""height""": 1_8, """width""": 1_8}    )

       __a   			= self.image_processing_class.from_dict(self.image_processor_dict					,				size=4_2    )
       self.assertEqual(image_processor.size					,				{"""height""": 4_2, """width""": 4_2}    )

  def __a    (       self  :				Tuple    ):





       '''simple docstring'''

       __a   			= self.image_processing_class(**self.image_processor_dict    )
       # create random PIL images
       __a   			= 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
       __a   			= 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
       __a   			= image_processing(SCREAMING_SNAKE_CASE__					,				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 __a    (       self  :				Union[str, Any]    ):





       '''simple docstring'''

       __a   			= self.image_processing_class(**self.image_processor_dict    )
       # create random numpy tensors
       __a   			= 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
       __a   			= 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
       __a   			= image_processing(SCREAMING_SNAKE_CASE__					,				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 __a    (       self  :				str    ):





       '''simple docstring'''

       __a   			= self.image_processing_class(**self.image_processor_dict    )
       # create random PyTorch tensors
       __a   			= 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
       __a   			= 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
       __a   			= image_processing(SCREAMING_SNAKE_CASE__					,				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"""],
           )					,				)











'''simple docstring'''





class __A     :



 '''simple docstring'''







 def __init__(self					,  A			)       ->	None:


      """simple docstring"""



      _a           =    len(A			)
      _a           =    [0] * len_array

      if len_array > 0:
           _a           =    array[0]

      for i in range(1					,  A			):
           _a           =    self.prefix_sum[i - 1] + array[i]



 def    a__    (self					,  A					,  A			)       ->	int:


      """simple docstring"""



      if start == 0:
           return self.prefix_sum[end]

      return self.prefix_sum[end] - self.prefix_sum[start - 1]



 def    a__    (self					,  A			)       ->	bool:


      """simple docstring"""



      _a           =    {0}
      for sum_item in self.prefix_sum:
           if sum_item - target_sum in sums:
                return True

           sums.add(A			)

      return False


if __name__ == "__main__":
  import doctest

  doctest.testmod()



