





import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
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_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin





@skip_mps
class A_					(			_lowerCamelCase ,      _lowerCamelCase ,      unittest.TestCase   ):
   lowerCAmelCase__        = IFImgaImgSuperResolutionPipeline
   lowerCAmelCase__        = TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
   lowerCAmelCase__        = TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({"""original_image"""}   )
   lowerCAmelCase__        = PipelineTesterMixin.required_optional_params - {"""latents"""}




   def _lowerCAmelCase      (self	:Optional[Any] )->					Any:
         return self._get_superresolution_dummy_components()




   def _lowerCAmelCase      (self	:List[Any]    ,   _UpperCamelCase	:Optional[int]    ,   _UpperCamelCase	:Tuple=0 )->					Tuple:
         if str(_UpperCamelCase ).startswith('''mps''' ):
               __A          =				torch.manual_seed(_UpperCamelCase )
         else:
               __A          =				torch.Generator(device=_UpperCamelCase ).manual_seed(_UpperCamelCase )

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

         __A          =				{
             '''prompt''': '''A painting of a squirrel eating a burger''',
             '''image''': image,
             '''original_image''': original_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 _lowerCAmelCase      (self	:Dict )->					List[str]:
         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3 )




   def _lowerCAmelCase      (self	:int )->					Union[str, Any]:
         self._test_save_load_optional_components()




   @unittest.skipIf(torch_device != '''cuda'''    ,   reason='''float16 requires CUDA''' )
   def _lowerCAmelCase      (self	:Optional[Any] )->					List[str]:
         # 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 _lowerCAmelCase      (self	:Optional[int] )->					Any:
         self._test_attention_slicing_forward_pass(expected_max_diff=1e-2 )




   def _lowerCAmelCase      (self	:List[Any] )->					Any:
         self._test_save_load_local()






   def _lowerCAmelCase      (self	:Dict )->					str:
         self._test_inference_batch_single_identical(
             expected_max_diff=1e-2    ,   )












from itertools import permutations



def _a				(	lowerCamelCase:   tuple )	->						bool:







      '''simple docstring'''






      if num[3] % 2 != 0:
            return False

      if (num[2] + num[3] + num[4]) % 3 != 0:
            return False

      if num[5] % 5 != 0:
            return False

      __A          =				[7, 11, 13, 17]
      for i, test in enumerate(lowerCamelCase ):
            if (num[i + 4] * 1_00 + num[i + 5] * 10 + num[i + 6]) % test != 0:
                  return False
      return True



def _a				(	lowerCamelCase:   int = 10 )	->						int:







      '''simple docstring'''






      return sum(
          int(''''''.join(map(lowerCamelCase					,				lowerCamelCase ) ) )
          for num in permutations(range(lowerCamelCase ) )
          if is_substring_divisible(lowerCamelCase ) )


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





