


def      UpperCAmelCase__ (lowerCAmelCase_						,		lowerCAmelCase_     ):




					'''simple docstring'''


					if not len(__UpperCamelCase     ) == len(__UpperCamelCase     ) == 3:
										raise ValueError("Please enter a valid equation."     )
					if equationa[0] == equationa[1] == equationa[0] == equationa[1] == 0:
										raise ValueError("Both a & b of two equations can\'t be zero."     )

					# Extract the coefficients
					__SCREAMING_SNAKE_CASE     ,						__SCREAMING_SNAKE_CASE     ,						__SCREAMING_SNAKE_CASE		     =       equationa
					__SCREAMING_SNAKE_CASE     ,						__SCREAMING_SNAKE_CASE     ,						__SCREAMING_SNAKE_CASE		     =       equationa

					# Calculate the determinants of the matrices
					__SCREAMING_SNAKE_CASE		     =       aa * ba - aa * ba
					__SCREAMING_SNAKE_CASE		     =       ca * ba - ca * ba
					__SCREAMING_SNAKE_CASE		     =       aa * ca - aa * ca

					# Check if the system of linear equations has a solution (using Cramer's rule)
					if determinant == 0:
										if determinant_x == determinant_y == 0:
															raise ValueError("Infinite solutions. (Consistent system)"     )
										else:
															raise ValueError("No solution. (Inconsistent system)"     )
					else:
										if determinant_x == determinant_y == 0:
															# Trivial solution (Inconsistent system)
															return (0.0, 0.0)
										else:
															__SCREAMING_SNAKE_CASE		     =       determinant_x / determinant
															__SCREAMING_SNAKE_CASE		     =       determinant_y / determinant
															# Non-Trivial Solution (Consistent system)
															return (x, y)




"""simple docstring"""







import gc
import unittest

import numpy as np
import torch

from diffusers import AutoencoderKL, DDIMScheduler, DiTPipeline, DPMSolverMultistepScheduler, TransformeraDModel
from diffusers.utils import is_xformers_available, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import (
    CLASS_CONDITIONED_IMAGE_GENERATION_BATCH_PARAMS,
    CLASS_CONDITIONED_IMAGE_GENERATION_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()




class 				UpperCamelCase_			(				UpperCamelCase    ,						unittest.TestCase):

	"""simple docstring"""





	snake_case__       :						Union[str, Any]					      =    DiTPipeline
	snake_case__       :						Union[str, Any]					      =    CLASS_CONDITIONED_IMAGE_GENERATION_PARAMS
	snake_case__       :						Any					      =    PipelineTesterMixin.required_optional_params - {
	    "latents",
	    "num_images_per_prompt",
	    "callback",
	    "callback_steps",
	}
	snake_case__       :						Optional[Any]					      =    CLASS_CONDITIONED_IMAGE_GENERATION_BATCH_PARAMS
	snake_case__       :						Optional[Any]					      =    False




	def 						UpperCAmelCase_   (				self    :       Dict     ) ->			Dict:
						torch.manual_seed(0     )
						__SCREAMING_SNAKE_CASE		     =       TransformeraDModel(
						    sample_size=1_6    ,    num_layers=2    ,    patch_size=4    ,    attention_head_dim=8    ,    num_attention_heads=2    ,    in_channels=4    ,    out_channels=8    ,    attention_bias=UpperCAmelCase__    ,    activation_fn="gelu-approximate"    ,    num_embeds_ada_norm=1_0_0_0    ,    norm_type="ada_norm_zero"    ,    norm_elementwise_affine=UpperCAmelCase__    ,    )
						__SCREAMING_SNAKE_CASE		     =       AutoencoderKL()
						__SCREAMING_SNAKE_CASE		     =       DDIMScheduler()
						__SCREAMING_SNAKE_CASE		     =       {"transformer": transformer.eval(), "vae": vae.eval(), "scheduler": scheduler}
						return components




	def 						UpperCAmelCase_   (				self    :       Optional[int]    ,    UpperCAmelCase__    :       Tuple    ,    UpperCAmelCase__    :       str=0     ) ->			Optional[int]:
						if str(UpperCAmelCase__     ).startswith("mps"     ):
											__SCREAMING_SNAKE_CASE		     =       torch.manual_seed(UpperCAmelCase__     )
						else:
											__SCREAMING_SNAKE_CASE		     =       torch.Generator(device=UpperCAmelCase__     ).manual_seed(UpperCAmelCase__     )
						__SCREAMING_SNAKE_CASE		     =       {
						    "class_labels": [1],
						    "generator": generator,
						    "num_inference_steps": 2,
						    "output_type": "numpy",
						}
						return inputs




	def 						UpperCAmelCase_   (				self    :       Optional[int]     ) ->			List[str]:
						__SCREAMING_SNAKE_CASE		     =       "cpu"

						__SCREAMING_SNAKE_CASE		     =       self.get_dummy_components()
						__SCREAMING_SNAKE_CASE		     =       self.pipeline_class(**UpperCAmelCase__     )
						pipe.to(UpperCAmelCase__     )
						pipe.set_progress_bar_config(disable=UpperCAmelCase__     )

						__SCREAMING_SNAKE_CASE		     =       self.get_dummy_inputs(UpperCAmelCase__     )
						__SCREAMING_SNAKE_CASE		     =       pipe(**UpperCAmelCase__     ).images
						__SCREAMING_SNAKE_CASE		     =       image[0, -3:, -3:, -1]

						self.assertEqual(image.shape    ,    (1, 1_6, 1_6, 3)     )
						__SCREAMING_SNAKE_CASE		     =       np.array([0.2_946, 0.6_601, 0.4_329, 0.3_296, 0.4_144, 0.5_319, 0.7_273, 0.5_013, 0.4_457]     )
						__SCREAMING_SNAKE_CASE		     =       np.abs(image_slice.flatten() - expected_slice     ).max()
						self.assertLessEqual(UpperCAmelCase__    ,    1E-3     )




	def 						UpperCAmelCase_   (				self    :       List[str]     ) ->			Union[str, Any]:
						self._test_inference_batch_single_identical(relax_max_difference=UpperCAmelCase__    ,    expected_max_diff=1E-3     )




	@unittest.skipIf(
	    torch_device != "cuda" or not is_xformers_available()    ,    reason="XFormers attention is only available with CUDA and `xformers` installed"    ,    )
	def 						UpperCAmelCase_   (				self    :       int     ) ->			Dict:
						self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3     )




@require_torch_gpu
@slow
class 				UpperCamelCase_			(				unittest.TestCase):

	"""simple docstring"""





	def 						UpperCAmelCase_   (				self    :       Optional[int]     ) ->			Any:
						super().tearDown()
						gc.collect()
						torch.cuda.empty_cache()




	def 						UpperCAmelCase_   (				self    :       Union[str, Any]     ) ->			Optional[int]:
						__SCREAMING_SNAKE_CASE		     =       torch.manual_seed(0     )

						__SCREAMING_SNAKE_CASE		     =       DiTPipeline.from_pretrained("facebook/DiT-XL-2-256"     )
						pipe.to("cuda"     )

						__SCREAMING_SNAKE_CASE		     =       ["vase", "umbrella", "white shark", "white wolf"]
						__SCREAMING_SNAKE_CASE		     =       pipe.get_label_ids(UpperCAmelCase__     )

						__SCREAMING_SNAKE_CASE		     =       pipe(UpperCAmelCase__    ,    generator=UpperCAmelCase__    ,    num_inference_steps=4_0    ,    output_type="np"     ).images

						for word, image in zip(UpperCAmelCase__    ,    UpperCAmelCase__     ):
											__SCREAMING_SNAKE_CASE		     =       load_numpy(
											    F"""https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/dit/{word}.npy"""     )
											assert np.abs((expected_image - image).max()     ) < 1E-2




	def 						UpperCAmelCase_   (				self    :       List[str]     ) ->			List[Any]:
						__SCREAMING_SNAKE_CASE		     =       DiTPipeline.from_pretrained("facebook/DiT-XL-2-512"     )
						__SCREAMING_SNAKE_CASE		     =       DPMSolverMultistepScheduler.from_config(pipe.scheduler.config     )
						pipe.to("cuda"     )

						__SCREAMING_SNAKE_CASE		     =       ["vase", "umbrella"]
						__SCREAMING_SNAKE_CASE		     =       pipe.get_label_ids(UpperCAmelCase__     )

						__SCREAMING_SNAKE_CASE		     =       torch.manual_seed(0     )
						__SCREAMING_SNAKE_CASE		     =       pipe(UpperCAmelCase__    ,    generator=UpperCAmelCase__    ,    num_inference_steps=2_5    ,    output_type="np"     ).images

						for word, image in zip(UpperCAmelCase__    ,    UpperCAmelCase__     ):
											__SCREAMING_SNAKE_CASE		     =       load_numpy(
											    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
											    F"""/dit/{word}_512.npy"""     )

											assert np.abs((expected_image - image).max()     ) < 1E-1
