

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  (	UpperCAmelCase							, UpperCAmelCase							, unittest.TestCase				):
						_lowercase    						=			IFImgaImgSuperResolutionPipeline
						_lowercase    						=			TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
						_lowercase    						=			TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({"original_image"}				)
						_lowercase    						=			PipelineTesterMixin.required_optional_params - {"latents"}


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										return self._get_superresolution_dummy_components()


						def        _UpperCAmelCase				(       self						,					A_						,					A_=0	):







										'''simple docstring'''


										if str(A_	).startswith("mps"	):
														_UpperCAmelCase       :		str 		=    torch.manual_seed(A_	)
										else:
														_UpperCAmelCase       :		Any 		=    torch.Generator(device=A_	).manual_seed(A_	)

										_UpperCAmelCase       :		Optional[Any] 		=    floats_tensor((1, 3, 32, 32)						,					rng=random.Random(A_	)	).to(A_	)
										_UpperCAmelCase       :		Dict 		=    floats_tensor((1, 3, 16, 16)						,					rng=random.Random(A_	)	).to(A_	)

										_UpperCAmelCase       :		str 		=    {
										    "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        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										self._test_save_load_optional_components()


						@unittest.skipIf(torch_device != "cuda"						,					reason="float16 requires CUDA"	)
						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


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


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										self._test_attention_slicing_forward_pass(expected_max_diff=1e-2	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										self._test_save_load_local()





						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


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





from __future__ import annotations

from collections.abc import Callable

def 							__SCREAMING_SNAKE_CASE							(				lowerCAmelCase:  Callable[[int | float], int | float]  ,      lowerCAmelCase:  int | float  ,      lowerCAmelCase:  int | float  ,      lowerCAmelCase:  int = 100  ,      )   ->       float:
				_UpperCAmelCase       :		str 		=    x_start
				_UpperCAmelCase       :		Union[str, Any] 		=    fnc(lowerCAmelCase )
				_UpperCAmelCase       :		Tuple 		=    0.0
				for _ in range(lowerCAmelCase ):
								# Approximates small segments of curve as linear and solve
								# for trapezoidal area
								_UpperCAmelCase       :		Union[str, Any] 		=    (x_end - x_start) / steps + xa
								_UpperCAmelCase       :		Optional[Any] 		=    fnc(lowerCAmelCase )
								area += abs(fxa + fxa ) * (xa - xa) / 2
								# Increment step
								_UpperCAmelCase       :		Any 		=    xa
								_UpperCAmelCase       :		Optional[Any] 		=    fxa
				return area


if __name__ == "__main__":

					def 							__SCREAMING_SNAKE_CASE							(				lowerCAmelCase:  List[str] )   ->       List[Any]:
									return x**3 + x**2

					print('f(x) = x^3 + x^2')
					print('The area between the curve, x = -5, x = 5 and the x axis is:')
					SCREAMING_SNAKE_CASE_        =      10
					while i <= 100000:
										print(F'''with {i} steps: {trapezoidal_area(f, -5, 5, i)}''')
										i *= 10


