



'''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_image_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import MobileViTImageProcessor






class __A			(  unittest.TestCase						):



 '''simple docstring'''







 def __init__(self ,   A ,   A=7 ,   A=3 ,   A=18 ,   A=30 ,   A=400 ,   A=True ,   A=None ,   A=True ,   A=None ,   A=True ,   )    ->     Optional[int]:


      """simple docstring"""



      _a      =  size if size is not None else {'''shortest_edge''': 20}
      _a      =  crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
      _a      =  parent
      _a      =  batch_size
      _a      =  num_channels
      _a      =  image_size
      _a      =  min_resolution
      _a      =  max_resolution
      _a      =  do_resize
      _a      =  size
      _a      =  do_center_crop
      _a      =  crop_size
      _a      =  do_flip_channel_order



 def 					a__  (self       )    ->     Optional[Any]:


      """simple docstring"""



      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_center_crop": self.do_center_crop,
          "crop_size": self.crop_size,
          "do_flip_channel_order": self.do_flip_channel_order,
      }






@require_torch
@require_vision
class __A			(  A   ,   unittest.TestCase						):



 '''simple docstring'''







 __lowerCamelCase    :       Tuple          =       MobileViTImageProcessor if is_vision_available() else None



 def 					a__  (self       )    ->     List[Any]:


      """simple docstring"""



      _a      =  MobileViTImageProcessingTester(self       )



 @property
 def 					a__  (self       )    ->     str:


      """simple docstring"""



      return self.image_processor_tester.prepare_image_processor_dict()



 def 					a__  (self       )    ->     Tuple:


      """simple docstring"""



      _a      =  self.image_processing_class(**self.image_processor_dict       )
      self.assertTrue(hasattr(_snake_case ,   '''do_resize'''       )       )
      self.assertTrue(hasattr(_snake_case ,   '''size'''       )       )
      self.assertTrue(hasattr(_snake_case ,   '''do_center_crop'''       )       )
      self.assertTrue(hasattr(_snake_case ,   '''center_crop'''       )       )
      self.assertTrue(hasattr(_snake_case ,   '''do_flip_channel_order'''       )       )



 def 					a__  (self       )    ->     List[str]:


      """simple docstring"""



      _a      =  self.image_processing_class.from_dict(self.image_processor_dict       )
      self.assertEqual(image_processor.size ,   {'''shortest_edge''': 20}       )
      self.assertEqual(image_processor.crop_size ,   {'''height''': 18, '''width''': 18}       )

      _a      =  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 					a__  (self       )    ->     int:


      """simple docstring"""



      pass



 def 					a__  (self       )    ->     Union[str, Any]:


      """simple docstring"""



      _a      =  self.image_processing_class(**self.image_processor_dict       )
      # create random PIL images
      _a      =  prepare_image_inputs(self.image_processor_tester ,   equal_resolution=_snake_case       )
      for image in image_inputs:
           self.assertIsInstance(_snake_case ,   Image.Image       )

      # Test not batched input
      _a      =  image_processing(image_inputs[0] ,   return_tensors='''pt'''       ).pixel_values
      self.assertEqual(
          encoded_images.shape ,   (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          ) ,   )

      # Test batched
      _a      =  image_processing(_snake_case ,   return_tensors='''pt'''       ).pixel_values
      self.assertEqual(
          encoded_images.shape ,   (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          ) ,   )



 def 					a__  (self       )    ->     Union[str, Any]:


      """simple docstring"""



      _a      =  self.image_processing_class(**self.image_processor_dict       )
      # create random numpy tensors
      _a      =  prepare_image_inputs(self.image_processor_tester ,   equal_resolution=_snake_case ,   numpify=_snake_case       )
      for image in image_inputs:
           self.assertIsInstance(_snake_case ,   np.ndarray       )

      # Test not batched input
      _a      =  image_processing(image_inputs[0] ,   return_tensors='''pt'''       ).pixel_values
      self.assertEqual(
          encoded_images.shape ,   (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          ) ,   )

      # Test batched
      _a      =  image_processing(_snake_case ,   return_tensors='''pt'''       ).pixel_values
      self.assertEqual(
          encoded_images.shape ,   (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          ) ,   )



 def 					a__  (self       )    ->     Optional[Any]:


      """simple docstring"""



      _a      =  self.image_processing_class(**self.image_processor_dict       )
      # create random PyTorch tensors
      _a      =  prepare_image_inputs(self.image_processor_tester ,   equal_resolution=_snake_case ,   torchify=_snake_case       )
      for image in image_inputs:
           self.assertIsInstance(_snake_case ,   torch.Tensor       )

      # Test not batched input
      _a      =  image_processing(image_inputs[0] ,   return_tensors='''pt'''       ).pixel_values
      self.assertEqual(
          encoded_images.shape ,   (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          ) ,   )

      # Test batched
      _a      =  image_processing(_snake_case ,   return_tensors='''pt'''       ).pixel_values
      self.assertEqual(
          encoded_images.shape ,   (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          ) ,   )









import os
import unittest

from transformers.models.phobert.tokenization_phobert import VOCAB_FILES_NAMES, PhobertTokenizer

from ...test_tokenization_common import TokenizerTesterMixin







class __snake_case			(			a ,  unittest.TestCase		):
   UpperCAmelCase__  :    Any          =  PhobertTokenizer
   UpperCAmelCase__  :    List[str]          =  False







   def lowerCamelCase						(      self		:						str):

        """simple docstring"""


        super().setUp()

        # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
        UpperCAmelCase_          =							['''T@@''', '''i''', '''I''', '''R@@''', '''r''', '''e@@''']
        UpperCAmelCase_          =							dict(zip(_snake_case					,						range(len(_snake_case))))
        UpperCAmelCase_          =							['''#version: 0.2''', '''l à</w>''']
        UpperCAmelCase_          =							{'''unk_token''': '''<unk>'''}

        UpperCAmelCase_          =							os.path.join(self.tmpdirname					,						VOCAB_FILES_NAMES['''vocab_file'''])
        UpperCAmelCase_          =							os.path.join(self.tmpdirname					,						VOCAB_FILES_NAMES['''merges_file'''])

        with open(self.vocab_file					,						'''w'''					,						encoding='''utf-8''') as fp:
             for token in vocab_tokens:
                  fp.write(F"""{token} {vocab_tokens[token]}\n""")
        with open(self.merges_file					,						'''w'''					,						encoding='''utf-8''') as fp:
             fp.write('''\n'''.join(_snake_case))







   def lowerCamelCase						(      self		:						int					,						**_snake_case		:						Any):

        """simple docstring"""


        kwargs.update(self.special_tokens_map)
        return PhobertTokenizer.from_pretrained(self.tmpdirname					,						**_snake_case)







   def lowerCamelCase						(      self		:						Optional[Any]					,						_snake_case		:						Union[str, Any]):

        """simple docstring"""


        UpperCAmelCase_          =							'''Tôi là VinAI Research'''
        UpperCAmelCase_          =							'''T<unk> i <unk> <unk> <unk> <unk> <unk> <unk> I Re<unk> e<unk> <unk> <unk> <unk>'''
        return input_text, output_text







   def lowerCamelCase						(      self		:						List[str]):

        """simple docstring"""


        UpperCAmelCase_          =							PhobertTokenizer(self.vocab_file					,						self.merges_file					,						**self.special_tokens_map)
        UpperCAmelCase_          =							'''Tôi là VinAI Research'''
        UpperCAmelCase_          =							'''T@@ ô@@ i l@@ à V@@ i@@ n@@ A@@ I R@@ e@@ s@@ e@@ a@@ r@@ c@@ h'''.split()
        UpperCAmelCase_          =							tokenizer.tokenize(_snake_case)
        print(_snake_case)
        self.assertListEqual(_snake_case					,						_snake_case)

        UpperCAmelCase_          =							tokens + [tokenizer.unk_token]

        UpperCAmelCase_          =							[4, 3, 5, 3, 3, 3, 3, 3, 3, 6, 7, 9, 3, 9, 3, 3, 3, 3, 3]
        self.assertListEqual(tokenizer.convert_tokens_to_ids(_snake_case)					,						_snake_case)






