
import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
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__		(     __UpperCAmelCase  ,       __UpperCAmelCase  ,       unittest.TestCase):
      _UpperCAmelCase    :   List[str]   	=      IFSuperResolutionPipeline
      _UpperCAmelCase    :   Tuple   	=      TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
      _UpperCAmelCase    :   Optional[Any]   	=      TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
      _UpperCAmelCase    :   Optional[int]   	=      PipelineTesterMixin.required_optional_params - {"""latents"""}
      def 						UpperCamelCase__							(				self				):
       return self._get_superresolution_dummy_components()
      def 						UpperCamelCase__							(				self   ,  __magic_name__   ,  __magic_name__=0				):



       if str(lowerCamelCase__				).startswith("""mps"""				):
        lowerCamelCase		:     List[str]          =				torch.manual_seed(lowerCamelCase__				)
       else:
        lowerCamelCase		:     Any          =				torch.Generator(device=lowerCamelCase__				).manual_seed(lowerCamelCase__				)

       lowerCamelCase		:     Any          =				floats_tensor((1, 3, 3_2, 3_2)   ,  rng=random.Random(lowerCamelCase__				)				).to(lowerCamelCase__				)

       lowerCamelCase		:     Union[str, Any]          =				{
           """prompt""": """A painting of a squirrel eating a burger""",
           """image""": 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				):
       self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3				)
      def 						UpperCamelCase__							(				self				):
       self._test_save_load_optional_components()
      @unittest.skipIf(torch_device != """cuda"""   ,  reason="""float16 requires CUDA"""				)
      def 						UpperCamelCase__							(				self				):
       super().test_save_load_floataa(expected_max_diff=1e-1				)
      def 						UpperCamelCase__							(				self				):
       self._test_attention_slicing_forward_pass(expected_max_diff=1e-2				)
      def 						UpperCamelCase__							(				self				):
       self._test_save_load_local()






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






def    _a (						lowerCamelCase,     lowerCamelCase,     lowerCamelCase							):
 lowerCamelCase		:     Optional[int]          =				[1 / first_term]
 lowerCamelCase		:     Any          =				1 / first_term
 for _ in range(number_of_terms - 1							):
  first_term += common_difference
  arithmetic_progression.append(lowerCamelCase							)
 lowerCamelCase		:     Optional[Any]          =				[1 / step for step in arithmetic_progression]
 return sum(lowerCamelCase							)


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      print(sum_of_harmonic_progression(1 / 2, 2, 2))




