import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin




@skip_mps
class 					_UpperCAmelCase			(     lowerCAmelCase,			lowerCAmelCase,			unittest.TestCase  ):



 '''simple docstring'''




 __A			       =					IFInpaintingSuperResolutionPipeline
 __A			       =					TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {'''width''', '''height'''}
 __A			       =					TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({'''original_image'''}  )
 __A			       =					PipelineTesterMixin.required_optional_params - {'''latents'''}







 def 		__UpperCAmelCase				(		self				:   str)						->	List[Any]:


   """simple docstring"""







   return self._get_superresolution_dummy_components()







 def 		__UpperCAmelCase				(		self				:   Any							, lowercase_				:   Dict							, lowercase_				:   Tuple=0)						->	List[str]:


   """simple docstring"""







   if str(lowercase_).startswith("mps"):
     _UpperCamelCase           =    torch.manual_seed(lowercase_)
   else:
     _UpperCamelCase           =    torch.Generator(device=lowercase_).manual_seed(lowercase_)

   _UpperCamelCase           =    floats_tensor((1, 3, 16, 16)							, rng=random.Random(lowercase_)).to(lowercase_)
   _UpperCamelCase           =    floats_tensor((1, 3, 32, 32)							, rng=random.Random(lowercase_)).to(lowercase_)
   _UpperCamelCase           =    floats_tensor((1, 3, 32, 32)							, rng=random.Random(lowercase_)).to(lowercase_)

   _UpperCamelCase           =    {
       "prompt": "A painting of a squirrel eating a burger",
       "image": image,
       "original_image": original_image,
       "mask_image": mask_image,
       "generator": generator,
       "num_inference_steps": 2,
       "output_type": "numpy",
   }

   return inputs







 @unittest.skipIf(
     torch_device != "cuda" or not is_xformers_available()							, reason="XFormers attention is only available with CUDA and `xformers` installed"							, )
 def 		__UpperCAmelCase				(		self				:   Optional[int])						->	Dict:


   """simple docstring"""







   self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3)







 def 		__UpperCAmelCase				(		self				:   List[Any])						->	str:


   """simple docstring"""







   self._test_save_load_optional_components()







 @unittest.skipIf(torch_device != "cuda"							, reason="float16 requires CUDA")
 def 		__UpperCAmelCase				(		self				:   Union[str, Any])						->	Dict:


   """simple docstring"""







   super().test_save_load_floataa(expected_max_diff=1e-1)







 def 		__UpperCAmelCase				(		self				:   Dict)						->	str:


   """simple docstring"""







   self._test_attention_slicing_forward_pass(expected_max_diff=1e-2)







 def 		__UpperCAmelCase				(		self				:   List[str])						->	Optional[Any]:


   """simple docstring"""







   self._test_save_load_local()







 def 		__UpperCAmelCase				(		self				:   List[str])						->	Tuple:


   """simple docstring"""







   self._test_inference_batch_single_identical(
       expected_max_diff=1e-2							, )





from math import isqrt, loga


def 				lowerCAmelCase__       (			a__ )      ->list[int]:




  '''simple docstring'''

  _UpperCamelCase           =    [True] * max_number
  for i in range(2    ,     isqrt(max_number - 1 ) + 1 ):
    if is_prime[i]:
      for j in range(i**2    ,     a__    ,     a__ ):
        _UpperCamelCase           =    False

  return [i for i in range(2    ,     a__ ) if is_prime[i]]


def 				lowerCAmelCase__       (			a__ = 800_800    ,     a__ = 800_800 )      ->int:




  '''simple docstring'''

  _UpperCamelCase           =    degree * loga(a__ )
  _UpperCamelCase           =    int(a__ )
  _UpperCamelCase           =    calculate_prime_numbers(a__ )

  _UpperCamelCase           =    0
  _UpperCamelCase           =    0
  _UpperCamelCase           =    len(a__ ) - 1
  while left < right:
    while (
        prime_numbers[right] * loga(prime_numbers[left] )
        + prime_numbers[left] * loga(prime_numbers[right] )
        > upper_bound
    ):
      right -= 1
    hybrid_integers_count += right - left
    left += 1

  return hybrid_integers_count


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




