
"""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       lowerCAmelCase__				(						A_ ,	A_ ,	unittest.TestCase	):
     __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      lowercase	(							self			:			Tuple			):
       return self._get_superresolution_dummy_components()







     def      lowercase	(							self			:			Any    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			Union[str, Any]=0			):
       if str(_lowerCamelCase			).startswith('''mps'''			):
         _snake_case					     =       torch.manual_seed(_lowerCamelCase			)
       else:
         _snake_case					     =       torch.Generator(device=_lowerCamelCase			).manual_seed(_lowerCamelCase			)

       _snake_case					     =       floats_tensor((1, 3, 16, 16)    ,      rng=random.Random(_lowerCamelCase			)			).to(_lowerCamelCase			)
       _snake_case					     =       floats_tensor((1, 3, 32, 32)    ,      rng=random.Random(_lowerCamelCase			)			).to(_lowerCamelCase			)
       _snake_case					     =       floats_tensor((1, 3, 32, 32)    ,      rng=random.Random(_lowerCamelCase			)			).to(_lowerCamelCase			)

       _snake_case					     =       {
           '''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      lowercase	(							self			:			int			):
       self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3			)







     def      lowercase	(							self			:			Union[str, Any]			):
       self._test_save_load_optional_components()







     @unittest.skipIf(torch_device != '''cuda'''    ,      reason='''float16 requires CUDA'''			)
     def      lowercase	(							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      lowercase	(							self			:			Any			):
       self._test_attention_slicing_forward_pass(expected_max_diff=1e-2			)







     def      lowercase	(							self			:			List[Any]			):
       self._test_save_load_local()







     def      lowercase	(							self			:			int			):
       self._test_inference_batch_single_identical(
           expected_max_diff=1e-2    ,      )





"""simple docstring"""



from math import pow
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					)     ->					tuple[int, int]:
  if current_sum == needed_sum:
    # If the sum of the powers is equal to needed_sum, then we have a solution.
    solutions_count += 1
    return current_sum, solutions_count

  _snake_case					     =       int(pow(__lowerCamelCase ,					__lowerCamelCase		)		)
  if current_sum + i_to_n <= needed_sum:
    # If the sum of the powers is less than needed_sum, then continue adding powers.
    current_sum += i_to_n
    _snake_case     ,					_snake_case					     =       backtrack(
        __lowerCamelCase ,					__lowerCamelCase ,					current_number + 1 ,					__lowerCamelCase ,					__lowerCamelCase		)
    current_sum -= i_to_n
  if i_to_n < needed_sum:
    # If the power of i is less than needed_sum, then try with the next power.
    _snake_case     ,					_snake_case					     =       backtrack(
        __lowerCamelCase ,					__lowerCamelCase ,					current_number + 1 ,					__lowerCamelCase ,					__lowerCamelCase		)
  return current_sum, solutions_count
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int ,					__lowerCamelCase   :       int		)     ->					int:
  if not (1 <= needed_sum <= 10_00 and 2 <= power <= 10):
    raise ValueError(
        '''Invalid input\n'''
        '''needed_sum must be between 1 and 1000, power between 2 and 10.'''		)

  return backtrack(__lowerCamelCase ,					__lowerCamelCase ,					1 ,					0 ,					0		)[1]  # Return the solutions_count


if __name__ == "__main__":
 import doctest

 doctest.testmod()



