




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       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase=10	,      __UpperCamelCase=10	,      __UpperCamelCase=False	,      __UpperCamelCase=False)    ->  Dict:
     a											=   []
     for i in range(image_processor_tester.num_frames):
          video.append(np.random.randint(2_55	,      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       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase=False	,      __UpperCamelCase=False	,      __UpperCamelCase=False)    ->  List[str]:
     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     a__ (      unittest.TestCase   ):







     def __init__(			self						,	A						,	A=7						,	A=3						,	A=4						,	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=True						,	A=None						,	)						->					Tuple:



          '''simple docstring'''



          a											=   size if size is not None else {"shortest_edge": 18}
          a											=   crop_size if crop_size is not None else {"height": 18, "width": 18}

          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     a__ (      UpperCamelCase__     ,      unittest.TestCase   ):
     a	:    Tuple	      =			TvltImageProcessor if is_vision_available() else None







     def     lowerCAmelCase_       (			self				)						->					str:



          '''simple docstring'''



          a											=   TvltImageProcessorTester(self				)







     @property
     def     lowerCAmelCase_       (			self				)						->					List[Any]:



          '''simple docstring'''



          return self.image_processor_tester.prepare_image_processor_dict()







     def     lowerCAmelCase_       (			self				)						->					int:



          '''simple docstring'''



          a											=   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						,	"do_center_crop"				)				)
          self.assertTrue(hasattr(__lowerCamelCase						,	"size"				)				)







     def     lowerCAmelCase_       (			self				)						->					str:



          '''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=__lowerCamelCase				)
          for video in video_inputs:
               self.assertIsInstance(__lowerCamelCase						,	__lowerCamelCase				)
               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(__lowerCamelCase						,	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				)						->					Dict:



          '''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=__lowerCamelCase						,	numpify=__lowerCamelCase				)
          for video in video_inputs:
               self.assertIsInstance(__lowerCamelCase						,	__lowerCamelCase				)
               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(__lowerCamelCase						,	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				)						->					Union[str, 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=__lowerCamelCase						,	torchify=__lowerCamelCase				)
          for video in video_inputs:
               self.assertIsInstance(__lowerCamelCase						,	__lowerCamelCase				)
               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(__lowerCamelCase						,	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"],
              )						,	)







from typing import TYPE_CHECKING

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


lowercase__   :    str 					=      {
    "configuration_rwkv": ["RWKV_PRETRAINED_CONFIG_ARCHIVE_MAP", "RwkvConfig", "RwkvOnnxConfig"],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowercase__   :    int 					=      [
       "RWKV_PRETRAINED_MODEL_ARCHIVE_LIST",
       "RwkvForCausalLM",
       "RwkvModel",
       "RwkvPreTrainedModel",
   ]


if TYPE_CHECKING:
   from .configuration_rwkv import RWKV_PRETRAINED_CONFIG_ARCHIVE_MAP, RwkvConfig, RwkvOnnxConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_rwkv import (
          RWKV_PRETRAINED_MODEL_ARCHIVE_LIST,
          RwkvForCausalLM,
          RwkvModel,
          RwkvPreTrainedModel,
      )
else:
   import sys

   lowercase__   :    List[Any] 					=      _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

