



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      snake_case__       (unittest.TestCase	):







						"""simple docstring"""




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




									a__     :		Optional[int]		 =						size if size is not None else {"""shortest_edge""": 1_8}
									a__     :		Any		 =						crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}

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

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




@require_torch
@require_vision
class      snake_case__       (A__      ,			unittest.TestCase	):







						"""simple docstring"""




						__lowerCAmelCase  :int			      =  VideoMAEImageProcessor if is_vision_available() else None

						def 							SCREAMING_SNAKE_CASE__(     self						)      ->   Any:
									"""simple docstring"""




									a__     :		Tuple		 =						VideoMAEImageProcessingTester(self						)

						@property
						def 							SCREAMING_SNAKE_CASE__(     self						)      ->   int:
									"""simple docstring"""




									return self.image_processor_tester.prepare_image_processor_dict()

						def 							SCREAMING_SNAKE_CASE__(     self						)      ->   Optional[int]:
									"""simple docstring"""




									a__     :		Optional[Any]		 =						self.image_processing_class(**self.image_processor_dict						)
									self.assertTrue(hasattr(__lowercase      ,     """image_mean"""						)						)
									self.assertTrue(hasattr(__lowercase      ,     """image_std"""						)						)
									self.assertTrue(hasattr(__lowercase      ,     """do_normalize"""						)						)
									self.assertTrue(hasattr(__lowercase      ,     """do_resize"""						)						)
									self.assertTrue(hasattr(__lowercase      ,     """do_center_crop"""						)						)
									self.assertTrue(hasattr(__lowercase      ,     """size"""						)						)

						def 							SCREAMING_SNAKE_CASE__(     self						)      ->   Tuple:
									"""simple docstring"""




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

									a__     :		int		 =						self.image_processing_class.from_dict(self.image_processor_dict      ,     size=4_2      ,     crop_size=8_4						)
									self.assertEqual(image_processor.size      ,     {"""shortest_edge""": 4_2}						)
									self.assertEqual(image_processor.crop_size      ,     {"""height""": 8_4, """width""": 8_4}						)

						def 							SCREAMING_SNAKE_CASE__(     self						)      ->   Optional[int]:
									"""simple docstring"""




									pass

						def 							SCREAMING_SNAKE_CASE__(     self						)      ->   str:
									"""simple docstring"""




									a__     :		Union[str, Any]		 =						self.image_processing_class(**self.image_processor_dict						)
									# create random PIL videos
									a__     :		Union[str, Any]		 =						prepare_video_inputs(self.image_processor_tester      ,     equal_resolution=__lowercase						)
									for video in video_inputs:
												self.assertIsInstance(__lowercase      ,     __lowercase						)
												self.assertIsInstance(video[0]      ,     Image.Image						)

									# Test not batched input
									a__     :		List[str]		 =						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
									a__     :		Dict		 =						image_processing(__lowercase      ,     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 							SCREAMING_SNAKE_CASE__(     self						)      ->   List[str]:
									"""simple docstring"""




									a__     :		Optional[int]		 =						self.image_processing_class(**self.image_processor_dict						)
									# create random numpy tensors
									a__     :		List[str]		 =						prepare_video_inputs(self.image_processor_tester      ,     equal_resolution=__lowercase      ,     numpify=__lowercase						)
									for video in video_inputs:
												self.assertIsInstance(__lowercase      ,     __lowercase						)
												self.assertIsInstance(video[0]      ,     np.ndarray						)

									# Test not batched input
									a__     :		List[str]		 =						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
									a__     :		List[str]		 =						image_processing(__lowercase      ,     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 							SCREAMING_SNAKE_CASE__(     self						)      ->   str:
									"""simple docstring"""




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

									# Test not batched input
									a__     :		List[Any]		 =						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
									a__     :		Any		 =						image_processing(__lowercase      ,     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"""],
									    )      ,     )









import os
from shutil import copyfile
from typing import Optional, Tuple

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
		from .tokenization_reformer import ReformerTokenizer
else:
		_lowercase	:   Optional[int]    	=None


_lowercase	:   Union[str, Any]    	=logging.get_logger(__name__)


_lowercase	:   Any    	="▁"

_lowercase	:   Union[str, Any]    	={"vocab_file": "spiece.model", "tokenizer_file": "tokenizer.json"}

_lowercase	:   List[str]    	={
    "vocab_file": {
        "google/reformer-crime-and-punishment": (
            "https://huggingface.co/google/reformer-crime-and-punishment/resolve/main/spiece.model"
        )
    },
    "tokenizer_file": {
        "google/reformer-crime-and-punishment": (
            "https://huggingface.co/google/reformer-crime-and-punishment/resolve/main/tokenizer.json"
        )
    },
}

_lowercase	:   List[str]    	={
    "google/reformer-crime-and-punishment": 52_4288,
}

class      snake_case__       (A__	):







						"""simple docstring"""




						__lowerCAmelCase  :Union[str, Any]			      =  VOCAB_FILES_NAMES
						__lowerCAmelCase  :int			      =  PRETRAINED_VOCAB_FILES_MAP
						__lowerCAmelCase  :List[Any]			      =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						__lowerCAmelCase  :Any			      =  ["input_ids", "attention_mask"]
						__lowerCAmelCase  :Tuple			      =  ReformerTokenizer

						def __init__(     self      ,     __lowercase=None      ,     __lowercase=None      ,     __lowercase="</s>"      ,     __lowercase="<unk>"      ,     __lowercase=[]      ,     **__lowercase      ,     )      ->   int:
									"""simple docstring"""




									super().__init__(
									    __lowercase      ,     tokenizer_file=__lowercase      ,     eos_token=__lowercase      ,     unk_token=__lowercase      ,     additional_special_tokens=__lowercase      ,     **__lowercase      ,     )

									a__     :		Union[str, Any]		 =						vocab_file
									a__     :		str		 =						False if not self.vocab_file else True

						def 							SCREAMING_SNAKE_CASE__(     self      ,     __lowercase      ,     __lowercase = None						)      ->   Tuple[str]:
									"""simple docstring"""




									if not self.can_save_slow_tokenizer:
												raise ValueError(
												    """Your fast tokenizer does not have the necessary information to save the vocabulary for a slow """
												    """tokenizer."""						)

									if not os.path.isdir(__lowercase						):
												logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''						)
												return
									a__     :		Tuple		 =						os.path.join(
									    __lowercase      ,     (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]						)

									if os.path.abspath(self.vocab_file						) != os.path.abspath(__lowercase						):
												copyfile(self.vocab_file      ,     __lowercase						)

									return (out_vocab_file,)




