





import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip 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 CLIPImageProcessor, CLIPProcessor

@require_vision
class    lowerCAmelCase							(					unittest.TestCase			):
 def      A_	(      self  :      List[Any]	)			->	str:
     lowerCamelCase__    :      int					 =		tempfile.mkdtemp()

     # fmt: off
     lowerCamelCase__    :      Optional[Any]					 =		['l', 'o', 'w', 'e', 'r', 's', 't', 'i', 'd', 'n', 'lo', 'l</w>', 'w</w>', 'r</w>', 't</w>', 'low</w>', 'er</w>', 'lowest</w>', 'newer</w>', 'wider', '<unk>', '<|startoftext|>', '<|endoftext|>']
     # fmt: on
     lowerCamelCase__    :      int					 =		dict(zip(UpperCAmelCase			,     range(len(UpperCAmelCase	)	)	)	)
     lowerCamelCase__    :      Any					 =		['#version: 0.2', 'l o', 'lo w</w>', 'e r</w>', '']
     lowerCamelCase__    :      List[str]					 =		{'unk_token': '<unk>'}

     lowerCamelCase__    :      Tuple					 =		os.path.join(self.tmpdirname			,     VOCAB_FILES_NAMES['vocab_file']	)
     lowerCamelCase__    :      List[str]					 =		os.path.join(self.tmpdirname			,     VOCAB_FILES_NAMES['merges_file']	)
     with open(self.vocab_file			,     'w'			,     encoding='utf-8'	) as fp:
         fp.write(json.dumps(UpperCAmelCase	) + '\n'	)
     with open(self.merges_file			,     'w'			,     encoding='utf-8'	) as fp:
         fp.write('\n'.join(UpperCAmelCase	)	)

     lowerCamelCase__    :      Optional[Any]					 =		{
         'do_resize': True,
         'size': 20,
         'do_center_crop': True,
         'crop_size': 18,
         'do_normalize': True,
         'image_mean': [0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3],
         'image_std': [0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1],
     }
     lowerCamelCase__    :      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  :      Optional[int]			,     **UpperCAmelCase  :      Tuple	)			->	Optional[int]:
     return CLIPTokenizer.from_pretrained(self.tmpdirname			,     **UpperCAmelCase	)
 def      A_	(      self  :      Union[str, Any]			,     **UpperCAmelCase  :      Any	)			->	str:
     return CLIPTokenizerFast.from_pretrained(self.tmpdirname			,     **UpperCAmelCase	)
 def      A_	(      self  :      str			,     **UpperCAmelCase  :      Dict	)			->	Optional[int]:
     return CLIPImageProcessor.from_pretrained(self.tmpdirname			,     **UpperCAmelCase	)
 def      A_	(      self  :      int	)			->	Any:
     shutil.rmtree(self.tmpdirname	)
 def      A_	(      self  :      List[str]	)			->	str:
     lowerCamelCase__    :      List[str]					 =		[np.random.randint(255			,     size=(3, 30, 400)			,     dtype=np.uinta	)]

     lowerCamelCase__    :      List[Any]					 =		[Image.fromarray(np.moveaxis(UpperCAmelCase			,     0			,     -1	)	) for x in image_inputs]

     return image_inputs
 def      A_	(      self  :      int	)			->	int:
     lowerCamelCase__    :      str					 =		self.get_tokenizer()
     lowerCamelCase__    :      Optional[Any]					 =		self.get_rust_tokenizer()
     lowerCamelCase__    :      str					 =		self.get_image_processor()

     lowerCamelCase__    :      List[Any]					 =		CLIPProcessor(tokenizer=UpperCAmelCase			,     image_processor=UpperCAmelCase	)
     processor_slow.save_pretrained(self.tmpdirname	)
     lowerCamelCase__    :      Dict					 =		CLIPProcessor.from_pretrained(self.tmpdirname			,     use_fast=UpperCAmelCase	)

     lowerCamelCase__    :      Any					 =		CLIPProcessor(tokenizer=UpperCAmelCase			,     image_processor=UpperCAmelCase	)
     processor_fast.save_pretrained(self.tmpdirname	)
     lowerCamelCase__    :      Tuple					 =		CLIPProcessor.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  :      int	)			->	Any:
     lowerCamelCase__    :      Any					 =		CLIPProcessor(tokenizer=self.get_tokenizer()			,     image_processor=self.get_image_processor()	)
     processor.save_pretrained(self.tmpdirname	)

     lowerCamelCase__    :      Optional[Any]					 =		self.get_tokenizer(bos_token='(BOS)'			,     eos_token='(EOS)'	)
     lowerCamelCase__    :      Any					 =		self.get_image_processor(do_normalize=UpperCAmelCase			,     padding_value=1.0	)

     lowerCamelCase__    :      Any					 =		CLIPProcessor.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  :      Any	)			->	List[Any]:
     lowerCamelCase__    :      int					 =		self.get_image_processor()
     lowerCamelCase__    :      Union[str, Any]					 =		self.get_tokenizer()

     lowerCamelCase__    :      Dict					 =		CLIPProcessor(tokenizer=UpperCAmelCase			,     image_processor=UpperCAmelCase	)

     lowerCamelCase__    :      Optional[int]					 =		self.prepare_image_inputs()

     lowerCamelCase__    :      str					 =		image_processor(UpperCAmelCase			,     return_tensors='np'	)
     lowerCamelCase__    :      Tuple					 =		processor(images=UpperCAmelCase			,     return_tensors='np'	)

     for key in input_image_proc.keys():
         self.assertAlmostEqual(input_image_proc[key].sum()			,     input_processor[key].sum()			,     delta=1e-2	)
 def      A_	(      self  :      List[str]	)			->	Optional[int]:
     lowerCamelCase__    :      List[Any]					 =		self.get_image_processor()
     lowerCamelCase__    :      Any					 =		self.get_tokenizer()

     lowerCamelCase__    :      List[Any]					 =		CLIPProcessor(tokenizer=UpperCAmelCase			,     image_processor=UpperCAmelCase	)

     lowerCamelCase__    :      Union[str, Any]					 =		'lower newer'

     lowerCamelCase__    :      Dict					 =		processor(text=UpperCAmelCase	)

     lowerCamelCase__    :      Tuple					 =		tokenizer(UpperCAmelCase	)

     for key in encoded_tok.keys():
         self.assertListEqual(encoded_tok[key]			,     encoded_processor[key]	)
 def      A_	(      self  :      Union[str, Any]	)			->	str:
     lowerCamelCase__    :      str					 =		self.get_image_processor()
     lowerCamelCase__    :      Union[str, Any]					 =		self.get_tokenizer()

     lowerCamelCase__    :      Optional[Any]					 =		CLIPProcessor(tokenizer=UpperCAmelCase			,     image_processor=UpperCAmelCase	)

     lowerCamelCase__    :      Union[str, Any]					 =		'lower newer'
     lowerCamelCase__    :      Union[str, Any]					 =		self.prepare_image_inputs()

     lowerCamelCase__    :      List[Any]					 =		processor(text=UpperCAmelCase			,     images=UpperCAmelCase	)

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

     # test if it raises when no input is passed
     with pytest.raises(UpperCAmelCase	):
         processor()
 def      A_	(      self  :      Optional[Any]	)			->	Tuple:
     lowerCamelCase__    :      int					 =		self.get_image_processor()
     lowerCamelCase__    :      Union[str, Any]					 =		self.get_tokenizer()

     lowerCamelCase__    :      Tuple					 =		CLIPProcessor(tokenizer=UpperCAmelCase			,     image_processor=UpperCAmelCase	)

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

     lowerCamelCase__    :      Optional[Any]					 =		processor.batch_decode(UpperCAmelCase	)
     lowerCamelCase__    :      Optional[int]					 =		tokenizer.batch_decode(UpperCAmelCase	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)







 def      A_	(      self  :      Optional[int]	)			->	Dict:
     lowerCamelCase__    :      Any					 =		self.get_image_processor()
     lowerCamelCase__    :      Tuple					 =		self.get_tokenizer()

     lowerCamelCase__    :      Tuple					 =		CLIPProcessor(tokenizer=UpperCAmelCase			,     image_processor=UpperCAmelCase	)

     lowerCamelCase__    :      Optional[Any]					 =		'lower newer'
     lowerCamelCase__    :      List[str]					 =		self.prepare_image_inputs()

     lowerCamelCase__    :      str					 =		processor(text=UpperCAmelCase			,     images=UpperCAmelCase	)

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












from __future__ import annotations

import math


def        SCREAMING_SNAKE_CASE      (       _UpperCAmelCase )			->     bool:

    if 1 < number < 4:
        # 2 and 3 are primes
        return True
    elif number < 2 or number % 2 == 0 or number % 3 == 0:
        # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
        return False

    # All primes number are in format of 6k +/- 1
    for i in range(5						,	int(math.sqrt(_UpperCAmelCase ) + 1 )						,	6 ):
        if number % i == 0 or number % (i + 2) == 0:
            return False
    return True


_UpperCAmelCase				:       Any	   =				[num for num in range(3, 10_00_01, 2) if not is_prime(num)]


def        SCREAMING_SNAKE_CASE      (       _UpperCAmelCase )			->     list[int]:
    if not isinstance(_UpperCAmelCase						,	_UpperCAmelCase ):
        raise ValueError('n must be an integer' )
    if n <= 0:
        raise ValueError('n must be >= 0' )

    lowerCamelCase__    :      int					 =		[]
    for num in range(len(_UpperCAmelCase ) ):
        lowerCamelCase__    :      Union[str, Any]					 =		0
        while 2 * i * i <= odd_composites[num]:
            lowerCamelCase__    :      Dict					 =		odd_composites[num] - 2 * i * i
            if is_prime(_UpperCAmelCase ):
                break
            i += 1
        else:
            list_nums.append(odd_composites[num] )
            if len(_UpperCAmelCase ) == n:
                return list_nums

    return []


def        SCREAMING_SNAKE_CASE      (       )			->     int:
    return compute_nums(1 )[0]


if __name__ == "__main__":
    print(F"""{solution() = }""")





