






"""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_video_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import VideoMAEImageProcessor







class 					lowerCamelCase__					(       unittest.TestCase ):






    def __init__( self	,A	,A=7	,A=3	,A=10	,A=18	,A=30	,A=400	,A=True	,A=None	,A=True	,A=[0.5, 0.5, 0.5]	,A=[0.5, 0.5, 0.5]	,A=None	,):
          UpperCAmelCase							=       size if size is not None else {"""shortest_edge""": 18}
          UpperCAmelCase							=       crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

          UpperCAmelCase							=       parent
          UpperCAmelCase							=       batch_size
          UpperCAmelCase							=       num_channels
          UpperCAmelCase							=       num_frames
          UpperCAmelCase							=       image_size
          UpperCAmelCase							=       min_resolution
          UpperCAmelCase							=       max_resolution
          UpperCAmelCase							=       do_resize
          UpperCAmelCase							=       size
          UpperCAmelCase							=       do_normalize
          UpperCAmelCase							=       image_mean
          UpperCAmelCase							=       image_std
          UpperCAmelCase							=       crop_size






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







@require_torch
@require_vision
class 					lowerCamelCase__					(       snake_case    ,     unittest.TestCase ):
    SCREAMING_SNAKE_CASE		=			VideoMAEImageProcessor if is_vision_available() else None






    def 				_UpperCamelCase							( self					):
          UpperCAmelCase							=       VideoMAEImageProcessingTester(self					)






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






    def 				_UpperCamelCase							( self					):
          UpperCAmelCase							=       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	,"""do_center_crop"""					)					)
          self.assertTrue(hasattr(A	,"""size"""					)					)






    def 				_UpperCamelCase							( self					):
          UpperCAmelCase							=       self.image_processing_class.from_dict(self.image_processor_dict					)
          self.assertEqual(image_processor.size	,{"""shortest_edge""": 18}					)
          self.assertEqual(image_processor.crop_size	,{"""height""": 18, """width""": 18}					)

          UpperCAmelCase							=       self.image_processing_class.from_dict(self.image_processor_dict	,size=42	,crop_size=84					)
          self.assertEqual(image_processor.size	,{"""shortest_edge""": 42}					)
          self.assertEqual(image_processor.crop_size	,{"""height""": 84, """width""": 84}					)






    def 				_UpperCamelCase							( self					):
          pass






    def 				_UpperCamelCase							( self					):
          # Initialize image_processing
          UpperCAmelCase							=       self.image_processing_class(**self.image_processor_dict					)
          # create random PIL videos
          UpperCAmelCase							=       prepare_video_inputs(self.image_processor_tester	,equal_resolution=A					)
          for video in video_inputs:
                self.assertIsInstance(A	,A					)
                self.assertIsInstance(video[0]	,Image.Image					)

          # Test not batched input
          UpperCAmelCase							=       image_processing(video_inputs[0]	,return_tensors="""pt"""					).pixel_values
          self.assertEqual(
              encoded_videos.shape	,(
                  1,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )	,)

          # Test batched
          UpperCAmelCase							=       image_processing(A	,return_tensors="""pt"""					).pixel_values
          self.assertEqual(
              encoded_videos.shape	,(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )	,)






    def 				_UpperCamelCase							( self					):
          # Initialize image_processing
          UpperCAmelCase							=       self.image_processing_class(**self.image_processor_dict					)
          # create random numpy tensors
          UpperCAmelCase							=       prepare_video_inputs(self.image_processor_tester	,equal_resolution=A	,numpify=A					)
          for video in video_inputs:
                self.assertIsInstance(A	,A					)
                self.assertIsInstance(video[0]	,np.ndarray					)

          # Test not batched input
          UpperCAmelCase							=       image_processing(video_inputs[0]	,return_tensors="""pt"""					).pixel_values
          self.assertEqual(
              encoded_videos.shape	,(
                  1,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )	,)

          # Test batched
          UpperCAmelCase							=       image_processing(A	,return_tensors="""pt"""					).pixel_values
          self.assertEqual(
              encoded_videos.shape	,(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )	,)






    def 				_UpperCamelCase							( self					):
          # Initialize image_processing
          UpperCAmelCase							=       self.image_processing_class(**self.image_processor_dict					)
          # create random PyTorch tensors
          UpperCAmelCase							=       prepare_video_inputs(self.image_processor_tester	,equal_resolution=A	,torchify=A					)
          for video in video_inputs:
                self.assertIsInstance(A	,A					)
                self.assertIsInstance(video[0]	,torch.Tensor					)

          # Test not batched input
          UpperCAmelCase							=       image_processing(video_inputs[0]	,return_tensors="""pt"""					).pixel_values
          self.assertEqual(
              encoded_videos.shape	,(
                  1,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )	,)

          # Test batched
          UpperCAmelCase							=       image_processing(A	,return_tensors="""pt"""					).pixel_values
          self.assertEqual(
              encoded_videos.shape	,(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )	,)











"""simple docstring"""







import sys

def _a (		_snake_case      ,       _snake_case							):







      """simple docstring"""






      if not numbers:
            return 0
      if target == 0 and target in numbers:
            return 0
      if not isinstance(_snake_case      ,       (list, tuple)							) or not all(
          isinstance(_snake_case      ,       _snake_case							) for number in numbers							):
            raise ValueError("""numbers must be an iterable of integers"""							)

      UpperCAmelCase							=       UpperCAmelCase							=       UpperCAmelCase							=       0
      UpperCAmelCase							=       sys.maxsize

      while right < len(_snake_case							):
            curr_sum += numbers[right]
            while curr_sum >= target and left <= right:
                  UpperCAmelCase							=       min(_snake_case      ,       right - left + 1							)
                  curr_sum -= numbers[left]
                  left += 1
            right += 1

      return 0 if min_len == sys.maxsize else min_len



