




import json
import os
import random
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
   from PIL import Image

   from transformers import FlavaImageProcessor, FlavaProcessor
   from transformers.models.flava.image_processing_flava import (
       FLAVA_CODEBOOK_MEAN,
       FLAVA_CODEBOOK_STD,
       FLAVA_IMAGE_MEAN,
       FLAVA_IMAGE_STD,
   )

@require_vision
class   UpperCAmelCase    (      unittest.TestCase ):






   def 			_a    (						self :							List[Any]  )->      Optional[int]:
     _lowercase:			List[Any]      =     tempfile.mkdtemp()

     # fmt: off
     _lowercase:			Optional[int]      =     ['[UNK]', '[CLS]', '[SEP]', '[PAD]', '[MASK]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing', ',', 'low', 'lowest']
     # fmt: on
     _lowercase:			Optional[int]      =     os.path.join(self.tmpdirname    ,       VOCAB_FILES_NAMES['vocab_file']  )

     with open(self.vocab_file    ,       'w'    ,       encoding='utf-8'  ) as fp:
       fp.write(''.join([x + '\n' for x in vocab_tokens]  )  )

     _lowercase:			Tuple      =     {
         'image_mean': FLAVA_IMAGE_MEAN,
         'image_std': FLAVA_IMAGE_STD,
         'do_normalize': True,
         'do_resize': True,
         'size': 2_24,
         'do_center_crop': True,
         'crop_size': 2_24,
         'input_size_patches': 14,
         'total_mask_patches': 75,
         'mask_group_max_patches': None,
         'mask_group_min_patches': 16,
         'mask_group_min_aspect_ratio': 0.3,
         'mask_group_max_aspect_ratio': None,
         'codebook_do_resize': True,
         'codebook_size': 1_12,
         'codebook_do_center_crop': True,
         'codebook_crop_size': 1_12,
         'codebook_do_map_pixels': True,
         'codebook_do_normalize': True,
         'codebook_image_mean': FLAVA_CODEBOOK_MEAN,
         'codebook_image_std': FLAVA_CODEBOOK_STD,
     }

     _lowercase:			Optional[int]      =     os.path.join(self.tmpdirname    ,       UpperCamelCase_  )
     with open(self.image_processor_file    ,       'w'    ,       encoding='utf-8'  ) as fp:
       json.dump(UpperCamelCase_    ,       UpperCamelCase_  )






   def 			_a    (						self :							List[Any]    ,       **UpperCamelCase_ :							List[Any]  )->      Any:
     return BertTokenizer.from_pretrained(self.tmpdirname    ,       **UpperCamelCase_  )






   def 			_a    (						self :							Optional[Any]    ,       **UpperCamelCase_ :							str  )->      int:
     return BertTokenizerFast.from_pretrained(self.tmpdirname    ,       **UpperCamelCase_  )






   def 			_a    (						self :							List[Any]    ,       **UpperCamelCase_ :							Union[str, Any]  )->      str:
     return FlavaImageProcessor.from_pretrained(self.tmpdirname    ,       **UpperCamelCase_  )






   def 			_a    (						self :							List[str]  )->      Optional[int]:
     shutil.rmtree(self.tmpdirname  )






   def 			_a    (						self :							Tuple  )->      Optional[Any]:
     _lowercase:			Tuple      =     [np.random.randint(2_55    ,       size=(3, 30, 4_00)    ,       dtype=np.uinta  )]

     _lowercase:			Optional[Any]      =     [Image.fromarray(np.moveaxis(UpperCamelCase_    ,       0    ,       -1  )  ) for x in image_inputs]

     return image_inputs






   def 			_a    (						self :							Union[str, Any]  )->      Union[str, Any]:
     _lowercase:			str      =     self.get_tokenizer()
     _lowercase:			List[Any]      =     self.get_rust_tokenizer()
     _lowercase:			Optional[Any]      =     self.get_image_processor()

     _lowercase:			int      =     FlavaProcessor(tokenizer=UpperCamelCase_    ,       image_processor=UpperCamelCase_  )
     processor_slow.save_pretrained(self.tmpdirname  )
     _lowercase:			str      =     FlavaProcessor.from_pretrained(self.tmpdirname    ,       use_fast=UpperCamelCase_  )

     _lowercase:			int      =     FlavaProcessor(tokenizer=UpperCamelCase_    ,       image_processor=UpperCamelCase_  )
     processor_fast.save_pretrained(self.tmpdirname  )
     _lowercase:			List[str]      =     FlavaProcessor.from_pretrained(self.tmpdirname  )

     self.assertEqual(processor_slow.tokenizer.get_vocab()    ,       tokenizer_slow.get_vocab()  )
     self.assertEqual(processor_fast.tokenizer.get_vocab()    ,       tokenizer_fast.get_vocab()  )
     self.assertEqual(tokenizer_slow.get_vocab()    ,       tokenizer_fast.get_vocab()  )
     self.assertIsInstance(processor_slow.tokenizer    ,       UpperCamelCase_  )
     self.assertIsInstance(processor_fast.tokenizer    ,       UpperCamelCase_  )

     self.assertEqual(processor_slow.image_processor.to_json_string()    ,       image_processor.to_json_string()  )
     self.assertEqual(processor_fast.image_processor.to_json_string()    ,       image_processor.to_json_string()  )
     self.assertIsInstance(processor_slow.image_processor    ,       UpperCamelCase_  )
     self.assertIsInstance(processor_fast.image_processor    ,       UpperCamelCase_  )






   def 			_a    (						self :							Union[str, Any]  )->      Tuple:
     _lowercase:			Optional[Any]      =     FlavaProcessor(tokenizer=self.get_tokenizer()    ,       image_processor=self.get_image_processor()  )
     processor.save_pretrained(self.tmpdirname  )

     _lowercase:			Any      =     self.get_tokenizer(bos_token='(BOS)'    ,       eos_token='(EOS)'  )
     _lowercase:			Any      =     self.get_image_processor(do_normalize=UpperCamelCase_    ,       padding_value=1.0  )

     _lowercase:			Any      =     FlavaProcessor.from_pretrained(
         self.tmpdirname    ,       bos_token='(BOS)'    ,       eos_token='(EOS)'    ,       do_normalize=UpperCamelCase_    ,       padding_value=1.0  )

     self.assertEqual(processor.tokenizer.get_vocab()    ,       tokenizer_add_kwargs.get_vocab()  )
     self.assertIsInstance(processor.tokenizer    ,       UpperCamelCase_  )

     self.assertEqual(processor.image_processor.to_json_string()    ,       image_processor_add_kwargs.to_json_string()  )
     self.assertIsInstance(processor.image_processor    ,       UpperCamelCase_  )






   def 			_a    (						self :							Union[str, Any]  )->      List[str]:
     _lowercase:			List[Any]      =     self.get_image_processor()
     _lowercase:			int      =     self.get_tokenizer()

     _lowercase:			Optional[int]      =     FlavaProcessor(tokenizer=UpperCamelCase_    ,       image_processor=UpperCamelCase_  )

     _lowercase:			Optional[Any]      =     self.prepare_image_inputs()

     _lowercase:			str      =     image_processor(UpperCamelCase_    ,       return_tensors='np'  )
     _lowercase:			str      =     processor(images=UpperCamelCase_    ,       return_tensors='np'  )

     for key in input_feat_extract.keys():
       self.assertAlmostEqual(input_feat_extract[key].sum()    ,       input_processor[key].sum()    ,       delta=1E-2  )

     # With rest of the args
     random.seed(12_34  )
     _lowercase:			Optional[int]      =     image_processor(
         UpperCamelCase_    ,       return_image_mask=UpperCamelCase_    ,       return_codebook_pixels=UpperCamelCase_    ,       return_tensors='np'  )
     random.seed(12_34  )
     _lowercase:			int      =     processor(
         images=UpperCamelCase_    ,       return_image_mask=UpperCamelCase_    ,       return_codebook_pixels=UpperCamelCase_    ,       return_tensors='np'  )

     for key in input_feat_extract.keys():
       self.assertAlmostEqual(input_feat_extract[key].sum()    ,       input_processor[key].sum()    ,       delta=1E-2  )






   def 			_a    (						self :							str  )->      Dict:
     _lowercase:			Tuple      =     self.get_image_processor()
     _lowercase:			Dict      =     self.get_tokenizer()

     _lowercase:			List[str]      =     FlavaProcessor(tokenizer=UpperCamelCase_    ,       image_processor=UpperCamelCase_  )

     _lowercase:			Optional[int]      =     'lower newer'

     _lowercase:			str      =     processor(text=UpperCamelCase_  )

     _lowercase:			Tuple      =     tokenizer(UpperCamelCase_  )

     for key in encoded_tok.keys():
       self.assertListEqual(encoded_tok[key]    ,       encoded_processor[key]  )






   def 			_a    (						self :							Tuple  )->      List[Any]:
     _lowercase:			List[str]      =     self.get_image_processor()
     _lowercase:			Dict      =     self.get_tokenizer()

     _lowercase:			str      =     FlavaProcessor(tokenizer=UpperCamelCase_    ,       image_processor=UpperCamelCase_  )

     _lowercase:			int      =     'lower newer'
     _lowercase:			int      =     self.prepare_image_inputs()

     _lowercase:			Optional[int]      =     processor(text=UpperCamelCase_    ,       images=UpperCamelCase_  )

     self.assertListEqual(list(inputs.keys()  )    ,       ['input_ids', 'token_type_ids', 'attention_mask', 'pixel_values']  )

     # add extra args
     _lowercase:			Union[str, Any]      =     processor(text=UpperCamelCase_    ,       images=UpperCamelCase_    ,       return_codebook_pixels=UpperCamelCase_    ,       return_image_mask=UpperCamelCase_  )

     self.assertListEqual(
         list(inputs.keys()  )    ,       [
             'input_ids',
             'token_type_ids',
             'attention_mask',
             'pixel_values',
             'codebook_pixel_values',
             'bool_masked_pos',
         ]    ,       )

     # test if it raises when no input is passed
     with pytest.raises(UpperCamelCase_  ):
       processor()






   def 			_a    (						self :							List[Any]  )->      List[Any]:
     _lowercase:			int      =     self.get_image_processor()
     _lowercase:			Tuple      =     self.get_tokenizer()

     _lowercase:			Any      =     FlavaProcessor(tokenizer=UpperCamelCase_    ,       image_processor=UpperCamelCase_  )

     _lowercase:			str      =     [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

     _lowercase:			Tuple      =     processor.batch_decode(UpperCamelCase_  )
     _lowercase:			Optional[int]      =     tokenizer.batch_decode(UpperCamelCase_  )

     self.assertListEqual(UpperCamelCase_    ,       UpperCamelCase_  )






   def 			_a    (						self :							Optional[int]  )->      List[str]:
     _lowercase:			List[str]      =     self.get_image_processor()
     _lowercase:			int      =     self.get_tokenizer()

     _lowercase:			Any      =     FlavaProcessor(tokenizer=UpperCamelCase_    ,       image_processor=UpperCamelCase_  )

     _lowercase:			str      =     'lower newer'
     _lowercase:			Tuple      =     self.prepare_image_inputs()

     _lowercase:			List[str]      =     processor(text=UpperCamelCase_    ,       images=UpperCamelCase_  )

     self.assertListEqual(list(inputs.keys()  )    ,       processor.model_input_names  )






from math import sqrt


def 		_lowerCamelCase					(       UpperCamelCase				)      ->		list[int]:





  """simple docstring"""





  _lowercase:			Dict      =     [1]
  for i in range(2       ,  int(sqrt(UpperCamelCase				)				) + 1       ,  1				):
    if number % i == 0:
      values.append(UpperCamelCase				)
      if int(number // i				) != i:
        values.append(int(number // i				)				)
  return sorted(UpperCamelCase				)


def 		_lowerCamelCase					(       UpperCamelCase				)      ->		bool:





  """simple docstring"""





  return sum(factors(UpperCamelCase				)				) > n


def 		_lowerCamelCase					(       UpperCamelCase				)      ->		bool:





  """simple docstring"""





  _lowercase:			Dict      =     factors(UpperCamelCase				)
  _lowercase:			int      =     len(UpperCamelCase				)
  _lowercase:			Optional[int]      =     [[0 for i in range(number + 1				)] for j in range(r + 1				)]
  for i in range(r + 1				):
    _lowercase:			List[Any]      =     True

  for i in range(1       ,  number + 1				):
    _lowercase:			Optional[int]      =     False

  for i in range(1       ,  r + 1				):
    for j in range(1       ,  number + 1				):
      if j < values[i - 1]:
        _lowercase:			Optional[int]      =     subset[i - 1][j]
      else:
        _lowercase:			Optional[Any]      =     subset[i - 1][j] or subset[i - 1][j - values[i - 1]]

  return subset[r][number] != 0


def 		_lowerCamelCase					(       UpperCamelCase				)      ->		bool:





  """simple docstring"""





  return abundant(UpperCamelCase				) and not semi_perfect(UpperCamelCase				)


if __name__ == "__main__":
   import doctest

   doctest.testmod(verbose=True)
   for number in (69, 70, 71):
      print(f'''{number} is {'' if weird(number) else 'not '}weird.''')
