




'''simple docstring'''







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 					_a (a__,		a__,		unittest.TestCase	):





     '''simple docstring'''



     lowerCAmelCase_  :     str          =					IFInpaintingSuperResolutionPipeline
     lowerCAmelCase_  :     Optional[int]          =					TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"""width""", """height"""}
     lowerCAmelCase_  :     Dict          =					TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"""original_image"""}	)
     lowerCAmelCase_  :     List[Any]          =					PipelineTesterMixin.required_optional_params - {"""latents"""}







     def 			snake_case_      (				self							)      ->				Tuple:
          return self._get_superresolution_dummy_components()







     def 			snake_case_      (				self							,__a							,__a=0							)      ->				Any:
          if str(__a							).startswith("""mps"""							):
               snake_case			:      Optional[Any]        =			torch.manual_seed(__a							)
          else:
               snake_case			:      int        =			torch.Generator(device=__a							).manual_seed(__a							)

          snake_case			:      Tuple        =			floats_tensor((1, 3, 16, 16)							,rng=random.Random(__a							)							).to(__a							)
          snake_case			:      Union[str, Any]        =			floats_tensor((1, 3, 32, 32)							,rng=random.Random(__a							)							).to(__a							)
          snake_case			:      Tuple        =			floats_tensor((1, 3, 32, 32)							,rng=random.Random(__a							)							).to(__a							)

          snake_case			:      Union[str, Any]        =			{
              """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 			snake_case_      (				self							)      ->				List[str]:
          self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3							)







     def 			snake_case_      (				self							)      ->				Optional[int]:
          self._test_save_load_optional_components()







     @unittest.skipIf(torch_device != """cuda"""							,reason="""float16 requires CUDA"""							)
     def 			snake_case_      (				self							)      ->				Tuple:
          # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
          super().test_save_load_floataa(expected_max_diff=1E-1							)







     def 			snake_case_      (				self							)      ->				int:
          self._test_attention_slicing_forward_pass(expected_max_diff=1E-2							)







     def 			snake_case_      (				self							)      ->				Union[str, Any]:
          self._test_save_load_local()







     def 			snake_case_      (				self							)      ->				Any:
          self._test_inference_batch_single_identical(
              expected_max_diff=1E-2							,)









'''simple docstring'''







def        lowerCamelCase__				(      __lowercase				):
     if not isinstance(__lowercase     ,   __lowercase				):
          snake_case			:      int        =			F'''Input value of [number={number}] must be an integer'''
          raise TypeError(__lowercase				)
     if number < 0:
          return False
     snake_case			:      Optional[int]        =			number * number
     while number > 0:
          if number % 10 != number_square % 10:
               return False
          number //= 10
          number_square //= 10
     return True


if __name__ == "__main__":
      import doctest

      doctest.testmod()



