'''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 			UpperCamelCase_							(      _UpperCAmelCase						:   Optional[int]    ,			_UpperCAmelCase						:   Any=10    ,			_UpperCAmelCase						:   Optional[Any]=10    ,			_UpperCAmelCase						:   Any=False    ,			_UpperCAmelCase						:   List[str]=False					)					->					str:


       """simple docstring"""







       _UpperCAmelCase  :						Any							   =					[]
       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
              _UpperCAmelCase  :						List[str]							   =					[Image.fromarray(np.moveaxis(_UpperCAmelCase    ,			0    ,			-1					)					) for frame in video]

       if torchify:
              _UpperCAmelCase  :						Tuple							   =					[torch.from_numpy(_UpperCAmelCase					) for frame in video]

       return video

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


       """simple docstring"""







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

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

       return video_inputs

class 			lowerCamelCase_			(unittest.TestCase					):
      '''simple docstring'''

      def __init__( self		:       Tuple		,      A		:       Any		,      A		:       int=7		,      A		:       Dict=3		,      A		:       str=4		,      A		:       Optional[Any]=18		,      A		:       Any=30		,      A		:       Optional[int]=400		,      A		:       Tuple=True		,      A		:       List[str]=None		,      A		:       Dict=True		,      A		:       List[Any]=[0.5, 0.5, 0.5]		,      A		:       Tuple=[0.5, 0.5, 0.5]		,      A		:       List[Any]=True		,      A		:       int=None		,      ):
             _UpperCAmelCase  :						Optional[Any]							   =					size if size is not None else {"shortest_edge": 18}
             _UpperCAmelCase  :						Any							   =					crop_size if crop_size is not None else {"height": 18, "width": 18}

             _UpperCAmelCase  :						int							   =					parent
             _UpperCAmelCase  :						Union[str, Any]							   =					batch_size
             _UpperCAmelCase  :						Optional[int]							   =					num_channels
             _UpperCAmelCase  :						Dict							   =					num_frames
             _UpperCAmelCase  :						List[Any]							   =					image_size
             _UpperCAmelCase  :						Any							   =					min_resolution
             _UpperCAmelCase  :						Optional[Any]							   =					max_resolution
             _UpperCAmelCase  :						Tuple							   =					do_resize
             _UpperCAmelCase  :						Tuple							   =					size
             _UpperCAmelCase  :						List[str]							   =					do_normalize
             _UpperCAmelCase  :						str							   =					image_mean
             _UpperCAmelCase  :						str							   =					image_std
             _UpperCAmelCase  :						List[str]							   =					do_center_crop
             _UpperCAmelCase  :						Union[str, Any]							   =					crop_size





      def   _A			( self		:       str ):
             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 			lowerCamelCase_			(snake_case__							,				unittest.TestCase					):
      '''simple docstring'''

      __UpperCamelCase:						Tuple      			=		TvltImageProcessor if is_vision_available() else None




      def   _A			( self		:       int ):
             _UpperCAmelCase  :						int							   =					TvltImageProcessorTester(self )




      @property
      def   _A			( self		:       Union[str, Any] ):
             return self.image_processor_tester.prepare_image_processor_dict()




      def   _A			( self		:       Tuple ):
             _UpperCAmelCase  :						Union[str, Any]							   =					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   _A			( self		:       Optional[int] ):
             # Initialize image_processor
             _UpperCAmelCase  :						str							   =					self.image_processing_class(**self.image_processor_dict )
             # create random PIL videos
             _UpperCAmelCase  :						int							   =					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  :						str							   =					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
             _UpperCAmelCase  :						Optional[int]							   =					image_processor(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   _A			( self		:       List[str] ):
             # Initialize image_processor
             _UpperCAmelCase  :						int							   =					self.image_processing_class(**self.image_processor_dict )
             # create random numpy tensors
             _UpperCAmelCase  :						List[Any]							   =					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  :						Tuple							   =					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
             _UpperCAmelCase  :						Optional[int]							   =					image_processor(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   _A			( self		:       str ):
             # Initialize image_processor
             _UpperCAmelCase  :						List[str]							   =					self.image_processing_class(**self.image_processor_dict )
             # create random PyTorch tensors
             _UpperCAmelCase  :						Dict							   =					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  :						Any							   =					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
             _UpperCAmelCase  :						Union[str, Any]							   =					image_processor(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'''




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


__SCREAMING_SNAKE_CASE :  Union[str, Any]  =						{
    """configuration_gptsan_japanese""": ["""GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP""", """GPTSanJapaneseConfig"""],
    """tokenization_gptsan_japanese""": ["""GPTSanJapaneseTokenizer"""],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __SCREAMING_SNAKE_CASE :  Optional[int]  =						[
      """GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """GPTSanJapaneseForConditionalGeneration""",
      """GPTSanJapaneseModel""",
      """GPTSanJapanesePreTrainedModel""",
  ]
  __SCREAMING_SNAKE_CASE :  Union[str, Any]  =						[
      """GPTSanJapaneseTokenizer""",
  ]


if TYPE_CHECKING:
  from .configuration_gptsan_japanese import GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTSanJapaneseConfig
  from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_gptsan_japanese import (
        GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST,
        GPTSanJapaneseForConditionalGeneration,
        GPTSanJapaneseModel,
        GPTSanJapanesePreTrainedModel,
    )
    from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer


else:
  import sys

  __SCREAMING_SNAKE_CASE :  Union[str, Any]  =						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

