

'''simple docstring'''

import unittest

import numpy as np
import PIL
import torch

from diffusers.image_processor import VaeImageProcessor





class 							_snake_case	(    unittest.TestCase  ):
   @property
   def       __UpperCamelCase  (	self     : Optional[Any]							):
     SCREAMING_SNAKE_CASE:Dict   =   1
     SCREAMING_SNAKE_CASE:int   =   3
     SCREAMING_SNAKE_CASE:List[str]   =   8
     SCREAMING_SNAKE_CASE:str   =   8

     SCREAMING_SNAKE_CASE:int   =   torch.rand((batch_size, num_channels, height, width)							)

     return sample
   def       __UpperCamelCase  (	self     : Dict       ,SCREAMING_SNAKE_CASE__     : Any							):
     if isinstance(image[0]       ,PIL.Image.Image							):
       return np.stack([np.array(SCREAMING_SNAKE_CASE__							) for i in image]       ,axis=0							)
     elif isinstance(SCREAMING_SNAKE_CASE__       ,torch.Tensor							):
       return image.cpu().numpy().transpose(0       ,2       ,3       ,1							)
     return image
   def       __UpperCamelCase  (	self     : Any							):
     SCREAMING_SNAKE_CASE:int   =   VaeImageProcessor(do_resize=SCREAMING_SNAKE_CASE__       ,do_normalize=SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Union[str, Any]   =   self.dummy_sample
     SCREAMING_SNAKE_CASE:List[str]   =   self.to_np(SCREAMING_SNAKE_CASE__							)

     for output_type in ["pt", "np", "pil"]:
       SCREAMING_SNAKE_CASE:Any   =   image_processor.postprocess(
           image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type=SCREAMING_SNAKE_CASE__       ,)
       SCREAMING_SNAKE_CASE:int   =   self.to_np(SCREAMING_SNAKE_CASE__							)
       SCREAMING_SNAKE_CASE:Dict   =   (input_np * 255).round() if output_type == "pil" else input_np
       assert (
           np.abs(in_np - out_np							).max() < 1e-6
       ), F'''decoded output does not match input for output_type {output_type}'''
   def       __UpperCamelCase  (	self     : Optional[int]							):
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   VaeImageProcessor(do_resize=SCREAMING_SNAKE_CASE__       ,do_normalize=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[str]   =   self.dummy_sample.cpu().numpy().transpose(0       ,2       ,3       ,1							)

     for output_type in ["pt", "np", "pil"]:
       SCREAMING_SNAKE_CASE:List[str]   =   image_processor.postprocess(image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type=SCREAMING_SNAKE_CASE__							)

       SCREAMING_SNAKE_CASE:Optional[int]   =   self.to_np(SCREAMING_SNAKE_CASE__							)
       SCREAMING_SNAKE_CASE:int   =   (input_np * 255).round() if output_type == "pil" else input_np
       assert (
           np.abs(in_np - out_np							).max() < 1e-6
       ), F'''decoded output does not match input for output_type {output_type}'''
   def       __UpperCamelCase  (	self     : Optional[Any]							):
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   VaeImageProcessor(do_resize=SCREAMING_SNAKE_CASE__       ,do_normalize=SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Optional[int]   =   self.dummy_sample.cpu().numpy().transpose(0       ,2       ,3       ,1							)
     SCREAMING_SNAKE_CASE:List[Any]   =   image_processor.numpy_to_pil(SCREAMING_SNAKE_CASE__							)

     for output_type in ["pt", "np", "pil"]:
       SCREAMING_SNAKE_CASE:List[str]   =   image_processor.postprocess(image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type=SCREAMING_SNAKE_CASE__							)
       for i, o in zip(SCREAMING_SNAKE_CASE__       ,SCREAMING_SNAKE_CASE__							):
         SCREAMING_SNAKE_CASE:Optional[Any]   =   np.array(SCREAMING_SNAKE_CASE__							)
         SCREAMING_SNAKE_CASE:Optional[Any]   =   self.to_np(SCREAMING_SNAKE_CASE__							) if output_type == "pil" else (self.to_np(SCREAMING_SNAKE_CASE__							) * 255).round()
         assert (
             np.abs(in_np - out_np							).max() < 1e-6
         ), F'''decoded output does not match input for output_type {output_type}'''
   def       __UpperCamelCase  (	self     : Optional[int]							):
     SCREAMING_SNAKE_CASE:List[Any]   =   VaeImageProcessor(do_resize=SCREAMING_SNAKE_CASE__       ,do_normalize=SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:int   =   self.dummy_sample
     SCREAMING_SNAKE_CASE:Optional[Any]   =   input_pt_ad.squeeze(0							)

     SCREAMING_SNAKE_CASE:str   =   image_processor.postprocess(
         image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type="np"       ,)
     SCREAMING_SNAKE_CASE:List[str]   =   image_processor.postprocess(
         image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type="np"       ,)

     SCREAMING_SNAKE_CASE:Any   =   self.to_np(self.dummy_sample							)
     SCREAMING_SNAKE_CASE:Dict   =   input_np_ad.squeeze(0							)

     SCREAMING_SNAKE_CASE:Optional[Any]   =   image_processor.postprocess(
         image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type="np"       ,)
     SCREAMING_SNAKE_CASE:Any   =   image_processor.postprocess(
         image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type="np"       ,)

     assert np.abs(out_pt_ad - out_pt_ad							).max() < 1e-6
     assert np.abs(out_np_ad - out_np_ad							).max() < 1e-6







   def       __UpperCamelCase  (	self     : Optional[int]							):
     SCREAMING_SNAKE_CASE:str   =   VaeImageProcessor(do_resize=SCREAMING_SNAKE_CASE__       ,do_normalize=SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Optional[Any]   =   self.dummy_sample
     SCREAMING_SNAKE_CASE:List[Any]   =   list(SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Tuple   =   image_processor.postprocess(
         image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type="np"       ,)

     SCREAMING_SNAKE_CASE:Any   =   image_processor.postprocess(
         image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type="np"       ,)

     SCREAMING_SNAKE_CASE:List[Any]   =   self.to_np(self.dummy_sample							)
     list(SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:List[str]   =   image_processor.postprocess(
         image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type="np"       ,)

     SCREAMING_SNAKE_CASE:str   =   image_processor.postprocess(
         image_processor.preprocess(SCREAMING_SNAKE_CASE__							)       ,output_type="np"       ,)

     assert np.abs(out_pt_ad - out_pt_list							).max() < 1e-6
     assert np.abs(out_np_ad - out_np_list							).max() < 1e-6









'''simple docstring'''

from __future__ import annotations

from collections import Counter





def 				A_					(	snake_case	):
  SCREAMING_SNAKE_CASE:int   =   [True] * n
  SCREAMING_SNAKE_CASE:List[str]   =   False
  SCREAMING_SNAKE_CASE:Tuple   =   False
  SCREAMING_SNAKE_CASE:int   =   True

  for i in range(3 ,    int(n**0.5 + 1	) ,    2	):
    SCREAMING_SNAKE_CASE:str   =   i * 2
    while index < n:
      SCREAMING_SNAKE_CASE:Any   =   False
      SCREAMING_SNAKE_CASE:List[Any]   =   index + i

  SCREAMING_SNAKE_CASE:Union[str, Any]   =   [2]

  for i in range(3 ,    snake_case ,    2	):
    if is_prime[i]:
      primes.append(snake_case	)

  return primes





def 				A_					(	snake_case	):
  SCREAMING_SNAKE_CASE:List[str]   =   str(snake_case	)
  SCREAMING_SNAKE_CASE:Union[str, Any]   =   []
  SCREAMING_SNAKE_CASE:List[str]   =   ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]

  for duplicate in Counter(snake_case	) - Counter(set(snake_case	)	):
    SCREAMING_SNAKE_CASE:List[str]   =   [int(number_str.replace(snake_case ,    snake_case	)	) for digit in digits]
    replacements.append(snake_case	)

  return replacements





def 				A_					(	snake_case = 8	):
  SCREAMING_SNAKE_CASE:str   =   set()

  # Filter primes with less than 3 replaceable digits
  SCREAMING_SNAKE_CASE:Tuple   =   {
      x for x in set(prime_sieve(1000000	)	) if len(str(snake_case	)	) - len(set(str(snake_case	)	)	) >= 3
  }

  for prime in primes:
    if prime in numbers_checked:
      continue

    SCREAMING_SNAKE_CASE:List[Any]   =   digit_replacements(snake_case	)

    for family in replacements:
      numbers_checked.update(snake_case	)
      SCREAMING_SNAKE_CASE:Optional[Any]   =   primes.intersection(snake_case	)

      if len(snake_case	) != family_length:
        continue

      return min(snake_case	)

  return -1


if __name__ == "__main__":
    print(solution())






