
"""simple docstring"""
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  _snake_case	(    lowercase__			,					lowercase__			,					unittest.TestCase							):
							SCREAMING_SNAKE_CASE		  =    IFSuperResolutionPipeline
							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 				__lowercase	(       self    :      Optional[int]     ):






												"""simple docstring"""



												return self._get_superresolution_dummy_components()






							def 				__lowercase	(       self    :      Dict    ,			snake_case__    :      Optional[int]    ,			snake_case__    :      List[str]=0     ):






												"""simple docstring"""



												if str(__UpperCamelCase     ).startswith("""mps"""     ):
																	__a:    Optional[Any]		     =       torch.manual_seed(__UpperCamelCase     )
												else:
																	__a:    Any		     =       torch.Generator(device=__UpperCamelCase     ).manual_seed(__UpperCamelCase     )

												__a:    Dict		     =       floats_tensor((1, 3, 3_2, 3_2)    ,			rng=random.Random(__UpperCamelCase     )     ).to(__UpperCamelCase     )

												__a:    List[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 				__lowercase	(       self    :      str     ):






												"""simple docstring"""



												self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3     )






							def 				__lowercase	(       self    :      Optional[Any]     ):






												"""simple docstring"""



												self._test_save_load_optional_components()






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






												"""simple docstring"""



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






							def 				__lowercase	(       self    :      Tuple     ):






												"""simple docstring"""



												self._test_attention_slicing_forward_pass(expected_max_diff=1e-2     )






							def 				__lowercase	(       self    :      str     ):






												"""simple docstring"""



												self._test_save_load_local()






							def 				__lowercase	(       self    :      Union[str, Any]     ):






												"""simple docstring"""



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





'''simple docstring'''



from __future__ import annotations

# Define the Gravitational Constant G and the function
_lowercase       :						List[str]						=6.6743E-11  # unit of G : m^3 * kg^-1 * s^-2


def 							__UpperCAmelCase				(				UpperCamelCase__				:float   ,				UpperCamelCase__				:float   ,				UpperCamelCase__				:float   ,				UpperCamelCase__				:float			)		->						dict[str, float]:
				snake_case__      :   str      =    mass_a * mass_a

				if (force, mass_a, mass_a, distance).count(0			) != 1:
								raise ValueError('''One and only one argument must be 0'''			)
				if force < 0:
								raise ValueError('''Gravitational force can not be negative'''			)
				if distance < 0:
								raise ValueError('''Distance can not be negative'''			)
				if mass_a < 0 or mass_a < 0:
								raise ValueError('''Mass can not be negative'''			)
				if force == 0:
								snake_case__      :   Dict      =    GRAVITATIONAL_CONSTANT * product_of_mass / (distance**2)
								return {"force": force}
				elif mass_a == 0:
								snake_case__      :   List[str]      =    (force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
								return {"mass_1": mass_a}
				elif mass_a == 0:
								snake_case__      :   List[Any]      =    (force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
								return {"mass_2": mass_a}
				elif distance == 0:
								snake_case__      :   str      =    (GRAVITATIONAL_CONSTANT * product_of_mass / (force)) ** 0.5
								return {"distance": distance}
				raise ValueError('''One and only one argument must be 0'''			)


# Run doctest
if __name__ == "__main__":
				import doctest

				doctest.testmod()




