






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


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import TvltImageProcessor






def 							lowerCAmelCase			(   UpperCamelCase_:				Optional[Any]  ,			UpperCamelCase_:				str=10  ,			UpperCamelCase_:				Dict=10  ,			UpperCamelCase_:				List[Any]=False  ,			UpperCamelCase_:				str=False       )							->				Union[str, Any]:







  '''simple docstring'''







  _a					      =						[]
  for i in range(image_processor_tester.num_frames       ):
    video.append(np.random.randint(255  ,			size=(image_processor_tester.num_channels, width, height)  ,			dtype=np.uinta       )       )

  if not numpify and not torchify:
    # PIL expects the channel dimension as last dimension
    _a					      =						[Image.fromarray(np.moveaxis(UpperCamelCase_  ,			0  ,			-1       )       ) for frame in video]

  if torchify:
    _a					      =						[torch.from_numpy(UpperCamelCase_       ) for frame in video]

  return video






def 							lowerCAmelCase			(   UpperCamelCase_:				List[str]  ,			UpperCamelCase_:				Optional[int]=False  ,			UpperCamelCase_:				Optional[int]=False  ,			UpperCamelCase_:				Any=False       )							->				List[Any]:







  '''simple docstring'''







  assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

  _a					      =						[]
  for i in range(image_processor_tester.batch_size       ):
    if equal_resolution:
      _a					      =						image_processor_tester.max_resolution
    else:
      _a					      =						np.random.choice(
          np.arange(image_processor_tester.min_resolution  ,			image_processor_tester.max_resolution       )  ,			2       )
      _a					      =						prepare_video(
          image_processor_tester=UpperCamelCase_  ,			width=UpperCamelCase_  ,			height=UpperCamelCase_  ,			numpify=UpperCamelCase_  ,			torchify=UpperCamelCase_  ,			)
    video_inputs.append(UpperCamelCase_       )

  return video_inputs




class  lowercase_     (unittest.TestCase  ):






      def __init__(     self  ,  a_  ,  a_=7  ,  a_=3  ,  a_=4  ,  a_=1_8  ,  a_=3_0  ,  a_=4_0_0  ,  a_=True  ,  a_=None  ,  a_=True  ,  a_=[0.5, 0.5, 0.5]  ,  a_=[0.5, 0.5, 0.5]  ,  a_=True  ,  a_=None  ,  )						->int:







        '''simple docstring'''


        _a					      =						size if size is not None else {"shortest_edge": 1_8}
        _a					      =						crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}

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






      def       lowerCamelCase__     (     self						)						->Optional[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,
            "do_center_crop": self.do_center_crop,
            "crop_size": self.crop_size,
        }







@require_torch
@require_vision
class  lowercase_     (lowerCAmelCase_,     unittest.TestCase  ):
      A__						:		Union[str, Any]							      =					TvltImageProcessor if is_vision_available() else None






      def       lowerCamelCase__     (     self						)						->int:







        '''simple docstring'''


        _a					      =						TvltImageProcessorTester(self						)






      @property
      def       lowerCamelCase__     (     self						)						->Dict:







        '''simple docstring'''


        return self.image_processor_tester.prepare_image_processor_dict()






      def       lowerCamelCase__     (     self						)						->Optional[int]:







        '''simple docstring'''


        _a					      =						self.image_processing_class(**self.image_processor_dict						)
        self.assertTrue(hasattr(__UpperCamelCase  ,  "image_mean"						)						)
        self.assertTrue(hasattr(__UpperCamelCase  ,  "image_std"						)						)
        self.assertTrue(hasattr(__UpperCamelCase  ,  "do_normalize"						)						)
        self.assertTrue(hasattr(__UpperCamelCase  ,  "do_resize"						)						)
        self.assertTrue(hasattr(__UpperCamelCase  ,  "do_center_crop"						)						)
        self.assertTrue(hasattr(__UpperCamelCase  ,  "size"						)						)






      def       lowerCamelCase__     (     self						)						->int:







        '''simple docstring'''


        _a					      =						self.image_processing_class(**self.image_processor_dict						)
        # create random PIL videos
        _a					      =						prepare_video_inputs(self.image_processor_tester  ,  equal_resolution=__UpperCamelCase						)
        for video in video_inputs:
          self.assertIsInstance(__UpperCamelCase  ,  __UpperCamelCase						)
          self.assertIsInstance(video[0]  ,  Image.Image						)

        # Test not batched input
        _a					      =						image_processor(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
        _a					      =						image_processor(__UpperCamelCase  ,  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       lowerCamelCase__     (     self						)						->Tuple:







        '''simple docstring'''


        _a					      =						self.image_processing_class(**self.image_processor_dict						)
        # create random numpy tensors
        _a					      =						prepare_video_inputs(self.image_processor_tester  ,  equal_resolution=__UpperCamelCase  ,  numpify=__UpperCamelCase						)
        for video in video_inputs:
          self.assertIsInstance(__UpperCamelCase  ,  __UpperCamelCase						)
          self.assertIsInstance(video[0]  ,  np.ndarray						)

        # Test not batched input
        _a					      =						image_processor(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
        _a					      =						image_processor(__UpperCamelCase  ,  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       lowerCamelCase__     (     self						)						->Any:







        '''simple docstring'''


        _a					      =						self.image_processing_class(**self.image_processor_dict						)
        # create random PyTorch tensors
        _a					      =						prepare_video_inputs(self.image_processor_tester  ,  equal_resolution=__UpperCamelCase  ,  torchify=__UpperCamelCase						)
        for video in video_inputs:
          self.assertIsInstance(__UpperCamelCase  ,  __UpperCamelCase						)
          self.assertIsInstance(video[0]  ,  torch.Tensor						)

        # Test not batched input
        _a					      =						image_processor(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
        _a					      =						image_processor(__UpperCamelCase  ,  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"""




def 				a__			(					lowerCAmelCase						:							str		):






     '''simple docstring'''
     UpperCAmelCase__				:			Optional[Any]							=    str(lowerCAmelCase		).strip()
     if not oct_string:
          raise ValueError("Empty string was passed to the function"		)
     UpperCAmelCase__				:			Tuple							=    oct_string[0] == "-"
     if is_negative:
          UpperCAmelCase__				:			List[Any]							=    oct_string[1:]
     if not oct_string.isdigit() or not all(0 <= int(lowerCAmelCase		) <= 7 for char in oct_string		):
          raise ValueError("Non-octal value was passed to the function"		)
     UpperCAmelCase__				:			Optional[int]							=    0
     for char in oct_string:
          UpperCAmelCase__				:			Tuple							=    8 * decimal_number + int(lowerCAmelCase		)
     if is_negative:
          UpperCAmelCase__				:			int							=    -decimal_number
     return decimal_number


if __name__ == "__main__":
    from doctest import testmod

    testmod()



