


"""simple docstring"""







import random
import unittest

import torch

from diffusers import IFImgaImgPipeline
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 							lowerCamelCase       (			__SCREAMING_SNAKE_CASE				,					__SCREAMING_SNAKE_CASE				,					unittest.TestCase ):


							"""simple docstring"""
							SCREAMING_SNAKE_CASE										=      IFImgaImgPipeline
							SCREAMING_SNAKE_CASE										=      TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
							SCREAMING_SNAKE_CASE										=      TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
							SCREAMING_SNAKE_CASE										=      PipelineTesterMixin.required_optional_params - {"""latents"""}






							def 					lowerCAmelCase     (						self :     Optional[Any]				):
													return self._get_dummy_components()






							def 					lowerCAmelCase     (						self :     Optional[int]		, lowerCamelCase_ :     Tuple		, lowerCamelCase_ :     str=0				):
													if str(lowerCamelCase_				).startswith('''mps'''				):
																			UpperCAmelCase__		=    torch.manual_seed(lowerCamelCase_				)
													else:
																			UpperCAmelCase__		=    torch.Generator(device=lowerCamelCase_				).manual_seed(lowerCamelCase_				)

													UpperCAmelCase__		=    floats_tensor((1, 3, 32, 32)		, rng=random.Random(lowerCamelCase_				)				).to(lowerCamelCase_				)

													UpperCAmelCase__		=    {
													    '''prompt''': '''A painting of a squirrel eating a burger''',
													    '''image''': image,
													    '''generator''': generator,
													    '''num_inference_steps''': 2,
													    '''output_type''': '''numpy''',
													}

													return inputs






							def 					lowerCAmelCase     (						self :     List[str]				):
													self._test_save_load_optional_components()






							@unittest.skipIf(
							    torch_device != '''cuda''' or not is_xformers_available()		, reason='''XFormers attention is only available with CUDA and `xformers` installed'''		, )
							def 					lowerCAmelCase     (						self :     List[str]				):
													self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3				)






							@unittest.skipIf(torch_device != '''cuda'''		, reason='''float16 requires CUDA'''				)
							def 					lowerCAmelCase     (						self :     Optional[int]				):
													# 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				)






							@unittest.skipIf(torch_device != '''cuda'''		, reason='''float16 requires CUDA'''				)
							def 					lowerCAmelCase     (						self :     Optional[int]				):
													super().test_floataa_inference(expected_max_diff=1E-1				)






							def 					lowerCAmelCase     (						self :     List[str]				):
													self._test_attention_slicing_forward_pass(expected_max_diff=1E-2				)






							def 					lowerCAmelCase     (						self :     int				):
													self._test_save_load_local()






							def 					lowerCAmelCase     (						self :     Union[str, Any]				):
													self._test_inference_batch_single_identical(
													    expected_max_diff=1E-2		, )



"""simple docstring"""







from __future__ import annotations

from collections.abc import Callable






def 					a__ (       _UpperCamelCase	,			_UpperCamelCase	,			_UpperCamelCase	,			_UpperCamelCase = 100	,			):





						"""simple docstring"""

						UpperCAmelCase__		=    x_start
						UpperCAmelCase__		=    fnc(_UpperCamelCase )
						UpperCAmelCase__		=    0.0

						for _ in range(_UpperCamelCase ):
												# Approximates small segments of curve as linear and solve
												# for trapezoidal area
												UpperCAmelCase__		=    (x_end - x_start) / steps + xa
												UpperCAmelCase__		=    fnc(_UpperCamelCase )
												area += abs(fxa + fxa ) * (xa - xa) / 2

												# Increment step
												UpperCAmelCase__		=    xa
												UpperCAmelCase__		=    fxa
						return area


if __name__ == "__main__":






						def 					a__ (       _UpperCamelCase ):





												"""simple docstring"""

												return x**3

						print("f(x) = x^3")
						print("The area between the curve, x = -10, x = 10 and the x axis is:")
						__a			 =   10
						while i <= 10_00_00:
												__a			 =   trapezoidal_area(f, -5, 5, i)
												print(f'''with {i} steps: {area}''')
												i *= 10