





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 OwlViTImageProcessor, OwlViTProcessor



@require_vision
class 					A__   (       unittest.TestCase			):





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					int       	=   tempfile.mkdtemp()

       # fmt: off
       UpperCamelCase	:					Union[str, 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
       UpperCamelCase	:					int       	=   dict(zip(A_       ,							range(len(A_   )   )   )   )
       UpperCamelCase	:					Optional[Any]       	=   ["#version: 0.2", "l o", "lo w</w>", "e r</w>", ""]
       UpperCamelCase	:					int       	=   {"unk_token": "<unk>"}

       UpperCamelCase	:					List[str]       	=   os.path.join(self.tmpdirname       ,							VOCAB_FILES_NAMES["vocab_file"]   )
       UpperCamelCase	:					List[Any]       	=   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(A_   ) + "\n"   )
       with open(self.merges_file       ,							"w"       ,							encoding="utf-8"   ) as fp:
        fp.write("\n".join(A_   )   )

       UpperCamelCase	:					Optional[int]       	=   {
           "do_resize": True,
           "size": 20,
           "do_center_crop": True,
           "crop_size": 18,
           "do_normalize": True,
           "image_mean": [0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73],
           "image_std": [0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11],
       }
       UpperCamelCase	:					Tuple       	=   os.path.join(self.tmpdirname       ,							A_   )
       with open(self.image_processor_file       ,							"w"       ,							encoding="utf-8"   ) as fp:
        json.dump(A_       ,							A_   )





      def        __UpperCamelCase( self       ,							**A_   ):
       '''simple docstring'''




       return CLIPTokenizer.from_pretrained(self.tmpdirname       ,							pad_token="!"       ,							**A_   )





      def        __UpperCamelCase( self       ,							**A_   ):
       '''simple docstring'''




       return CLIPTokenizerFast.from_pretrained(self.tmpdirname       ,							pad_token="!"       ,							**A_   )





      def        __UpperCamelCase( self       ,							**A_   ):
       '''simple docstring'''




       return OwlViTImageProcessor.from_pretrained(self.tmpdirname       ,							**A_   )





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       shutil.rmtree(self.tmpdirname   )





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Tuple       	=   [np.random.randint(255       ,							size=(3, 30, 400)       ,							dtype=np.uinta   )]

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

       return image_inputs





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Union[str, Any]       	=   self.get_tokenizer()
       UpperCamelCase	:					List[Any]       	=   self.get_rust_tokenizer()
       UpperCamelCase	:					Tuple       	=   self.get_image_processor()

       UpperCamelCase	:					List[Any]       	=   OwlViTProcessor(tokenizer=A_       ,							image_processor=A_   )
       processor_slow.save_pretrained(self.tmpdirname   )
       UpperCamelCase	:					List[str]       	=   OwlViTProcessor.from_pretrained(self.tmpdirname       ,							use_fast=A_   )

       UpperCamelCase	:					Optional[Any]       	=   OwlViTProcessor(tokenizer=A_       ,							image_processor=A_   )
       processor_fast.save_pretrained(self.tmpdirname   )
       UpperCamelCase	:					Dict       	=   OwlViTProcessor.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       ,							A_   )
       self.assertIsInstance(processor_fast.tokenizer       ,							A_   )

       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       ,							A_   )
       self.assertIsInstance(processor_fast.image_processor       ,							A_   )





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Union[str, Any]       	=   OwlViTProcessor(tokenizer=self.get_tokenizer()       ,							image_processor=self.get_image_processor()   )
       processor.save_pretrained(self.tmpdirname   )

       UpperCamelCase	:					int       	=   self.get_tokenizer(bos_token="(BOS)"       ,							eos_token="(EOS)"   )
       UpperCamelCase	:					List[str]       	=   self.get_image_processor(do_normalize=A_   )

       UpperCamelCase	:					Optional[int]       	=   OwlViTProcessor.from_pretrained(
           self.tmpdirname       ,							bos_token="(BOS)"       ,							eos_token="(EOS)"       ,							do_normalize=A_   )

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

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





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					int       	=   self.get_image_processor()
       UpperCamelCase	:					Union[str, Any]       	=   self.get_tokenizer()

       UpperCamelCase	:					Dict       	=   OwlViTProcessor(tokenizer=A_       ,							image_processor=A_   )

       UpperCamelCase	:					Dict       	=   self.prepare_image_inputs()

       UpperCamelCase	:					Optional[Any]       	=   image_processor(A_       ,							return_tensors="np"   )
       UpperCamelCase	:					Tuple       	=   processor(images=A_       ,							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        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Optional[int]       	=   self.get_image_processor()
       UpperCamelCase	:					Dict       	=   self.get_tokenizer()

       UpperCamelCase	:					str       	=   OwlViTProcessor(tokenizer=A_       ,							image_processor=A_   )

       UpperCamelCase	:					Optional[Any]       	=   "lower newer"

       UpperCamelCase	:					List[str]       	=   processor(text=A_       ,							return_tensors="np"   )

       UpperCamelCase	:					str       	=   tokenizer(A_       ,							return_tensors="np"   )

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





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Optional[int]       	=   self.get_image_processor()
       UpperCamelCase	:					int       	=   self.get_tokenizer()

       UpperCamelCase	:					Tuple       	=   OwlViTProcessor(tokenizer=A_       ,							image_processor=A_   )

       UpperCamelCase	:					int       	=   "lower newer"
       UpperCamelCase	:					List[str]       	=   self.prepare_image_inputs()

       UpperCamelCase	:					Any       	=   processor(text=A_       ,							images=A_   )

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

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





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					int       	=   "google/owlvit-base-patch32"
       UpperCamelCase	:					int       	=   OwlViTProcessor.from_pretrained(A_   )

       UpperCamelCase	:					Union[str, Any]       	=   ["cat", "nasa badge"]
       UpperCamelCase	:					Any       	=   processor(text=A_   )

       UpperCamelCase	:					Union[str, Any]       	=   16
       self.assertListEqual(list(inputs.keys()   )       ,							["input_ids", "attention_mask"]   )
       self.assertEqual(inputs["input_ids"].shape       ,							(2, seq_length)   )

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





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Optional[int]       	=   "google/owlvit-base-patch32"
       UpperCamelCase	:					List[str]       	=   OwlViTProcessor.from_pretrained(A_   )

       UpperCamelCase	:					Dict       	=   [["cat", "nasa badge"], ["person"]]
       UpperCamelCase	:					Tuple       	=   processor(text=A_   )

       UpperCamelCase	:					str       	=   16
       UpperCamelCase	:					Optional[Any]       	=   len(A_   )
       UpperCamelCase	:					Tuple       	=   max([len(A_   ) for texts in input_texts]   )

       self.assertListEqual(list(inputs.keys()   )       ,							["input_ids", "attention_mask"]   )
       self.assertEqual(inputs["input_ids"].shape       ,							(batch_size * num_max_text_queries, seq_length)   )

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





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					List[str]       	=   "google/owlvit-base-patch32"
       UpperCamelCase	:					Optional[Any]       	=   OwlViTProcessor.from_pretrained(A_   )

       UpperCamelCase	:					List[Any]       	=   ["cat", "nasa badge"]
       UpperCamelCase	:					Any       	=   processor(text=A_   )

       UpperCamelCase	:					Optional[int]       	=   16
       UpperCamelCase	:					Tuple       	=   inputs["input_ids"]
       UpperCamelCase	:					int       	=   [
           [4_9406, 2368, 4_9407, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [4_9406, 6841, 1_1301, 4_9407, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       ]

       self.assertListEqual(list(inputs.keys()   )       ,							["input_ids", "attention_mask"]   )
       self.assertEqual(inputs["input_ids"].shape       ,							(2, seq_length)   )
       self.assertListEqual(list(input_ids[0]   )       ,							predicted_ids[0]   )
       self.assertListEqual(list(input_ids[1]   )       ,							predicted_ids[1]   )





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					str       	=   self.get_image_processor()
       UpperCamelCase	:					List[str]       	=   self.get_tokenizer()

       UpperCamelCase	:					Union[str, Any]       	=   OwlViTProcessor(tokenizer=A_       ,							image_processor=A_   )

       UpperCamelCase	:					Tuple       	=   self.prepare_image_inputs()
       UpperCamelCase	:					Optional[Any]       	=   self.prepare_image_inputs()

       UpperCamelCase	:					Tuple       	=   processor(images=A_       ,							query_images=A_   )

       self.assertListEqual(list(inputs.keys()   )       ,							["query_pixel_values", "pixel_values"]   )

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





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Optional[int]       	=   self.get_image_processor()
       UpperCamelCase	:					Dict       	=   self.get_tokenizer()

       UpperCamelCase	:					int       	=   OwlViTProcessor(tokenizer=A_       ,							image_processor=A_   )

       UpperCamelCase	:					Optional[Any]       	=   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

       UpperCamelCase	:					Dict       	=   processor.batch_decode(A_   )
       UpperCamelCase	:					Optional[int]       	=   tokenizer.batch_decode(A_   )

       self.assertListEqual(A_       ,							A_   )







from __future__ import annotations

from functools import lru_cache
from math import ceil

__lowerCamelCase       :     str   =     100

__lowerCamelCase       :     Any   =     set(range(3, NUM_PRIMES, 2))
primes.add(2)
__lowerCamelCase       :     int

for prime in range(3, ceil(NUM_PRIMES**0.5), 2):
    if prime not in primes:
        continue
    primes.difference_update(set(range(prime * prime, NUM_PRIMES, prime)))



@lru_cache(maxsize=100     )
def 		A_				(     _lowerCAmelCase     )						-> set[int]:
 if number_to_partition < 0:
  return set()
 elif number_to_partition == 0:
  return {1}

 UpperCamelCase	:					set[int]       	=   set()
 UpperCamelCase	:					int
 UpperCamelCase	:					int

 for prime in primes:
  if prime > number_to_partition:
   continue
  for sub in partition(number_to_partition - prime     ):
   ret.add(sub * prime     )

 return ret



def 		A_				(     _lowerCAmelCase = 5000     )						-> int | None:
 for number_to_partition in range(1							,   _lowerCAmelCase     ):
  if len(partition(_lowerCAmelCase     )     ) > number_unique_partitions:
   return number_to_partition
 return None


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