


import gc
import random
import tempfile
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.stable_diffusion_safe import StableDiffusionPipelineSafe as StableDiffusionPipeline
from diffusers.utils import floats_tensor, nightly, torch_device
from diffusers.utils.testing_utils import require_torch_gpu






class   _lowerCamelCase (					unittest.TestCase			):




       """simple docstring"""



       def        _snake_case       (      self		)->str:




         '''simple docstring'''





         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()



       @property
       def        _snake_case       (      self		)->Optional[Any]:




         '''simple docstring'''





         A_      :				Optional[Any]		     =					1
         A_      :				str		     =					3
         A_      :				int		     =					(32, 32)

         A_      :				Any		     =					floats_tensor((batch_size, num_channels) + sizes				,       rng=random.Random(0		)		).to(_SCREAMING_SNAKE_CASE		)
         return image



       @property
       def        _snake_case       (      self		)->Optional[Any]:




         '''simple docstring'''





         torch.manual_seed(0		)
         A_      :				Dict		     =					UNetaDConditionModel(
             block_out_channels=(32, 64)				,       layers_per_block=2				,       sample_size=32				,       in_channels=4				,       out_channels=4				,       down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')				,       up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')				,       cross_attention_dim=32				,       )
         return model



       @property
       def        _snake_case       (      self		)->Optional[int]:




         '''simple docstring'''





         torch.manual_seed(0		)
         A_      :				str		     =					AutoencoderKL(
             block_out_channels=[32, 64]				,       in_channels=3				,       out_channels=3				,       down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']				,       up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']				,       latent_channels=4				,       )
         return model



       @property
       def        _snake_case       (      self		)->List[Any]:




         '''simple docstring'''





         torch.manual_seed(0		)
         A_      :				Optional[int]		     =					CLIPTextConfig(
             bos_token_id=0				,       eos_token_id=2				,       hidden_size=32				,       intermediate_size=37				,       layer_norm_eps=1e-05				,       num_attention_heads=4				,       num_hidden_layers=5				,       pad_token_id=1				,       vocab_size=1000				,       )
         return CLIPTextModel(_SCREAMING_SNAKE_CASE		)



       @property
       def        _snake_case       (      self		)->Optional[int]:




         '''simple docstring'''





         def extract(*_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		):






           class   _lowerCamelCase :




                  """simple docstring"""



                  def __init__(      self		)->Dict:




                    '''simple docstring'''





                    A_      :				Any		     =					torch.ones([0]		)







                  def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE		)->Any:




                    '''simple docstring'''





                    self.pixel_values.to(_SCREAMING_SNAKE_CASE		)
                    return self




           return Out()

         return extract



       def        _snake_case       (      self		)->int:




         '''simple docstring'''





         A_      :				Tuple		     =					'''cpu'''  # ensure determinism for the device-dependent torch.Generator
         A_      :				Optional[int]		     =					self.dummy_cond_unet
         A_      :				int		     =					DDIMScheduler(
             beta_start=0.0_0_0_8_5				,       beta_end=0.0_1_2				,       beta_schedule='''scaled_linear'''				,       clip_sample=_SCREAMING_SNAKE_CASE				,       set_alpha_to_one=_SCREAMING_SNAKE_CASE				,       )

         A_      :				Any		     =					self.dummy_vae
         A_      :				Dict		     =					self.dummy_text_encoder
         A_      :				Tuple		     =					CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''		)

         # make sure here that pndm scheduler skips prk
         A_      :				int		     =					StableDiffusionPipeline(
             unet=_SCREAMING_SNAKE_CASE				,       scheduler=_SCREAMING_SNAKE_CASE				,       vae=_SCREAMING_SNAKE_CASE				,       text_encoder=_SCREAMING_SNAKE_CASE				,       tokenizer=_SCREAMING_SNAKE_CASE				,       safety_checker=_SCREAMING_SNAKE_CASE				,       feature_extractor=self.dummy_extractor				,       )
         A_      :				Any		     =					sd_pipe.to(_SCREAMING_SNAKE_CASE		)
         sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE		)

         A_      :				Dict		     =					'''A painting of a squirrel eating a burger'''

         A_      :				List[str]		     =					torch.Generator(device=_SCREAMING_SNAKE_CASE		).manual_seed(0		)
         A_      :				List[str]		     =					sd_pipe([prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=6.0				,       num_inference_steps=2				,       output_type='''np'''		)
         A_      :				Dict		     =					output.images

         A_      :				str		     =					torch.Generator(device=_SCREAMING_SNAKE_CASE		).manual_seed(0		)
         A_      :				Optional[int]		     =					sd_pipe(
             [prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=6.0				,       num_inference_steps=2				,       output_type='''np'''				,       return_dict=_SCREAMING_SNAKE_CASE				,       )[0]

         A_      :				Dict		     =					image[0, -3:, -3:, -1]
         A_      :				Any		     =					image_from_tuple[0, -3:, -3:, -1]

         assert image.shape == (1, 64, 64, 3)
         A_      :				List[str]		     =					np.array([0.5_7_5_6, 0.6_1_1_8, 0.5_0_0_5, 0.5_0_4_1, 0.5_4_7_1, 0.4_7_2_6, 0.4_9_7_6, 0.4_8_6_5, 0.4_8_6_4]		)

         assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2
         assert np.abs(image_from_tuple_slice.flatten() - expected_slice		).max() < 1e-2



       def        _snake_case       (      self		)->int:




         '''simple docstring'''





         A_      :				List[str]		     =					'''cpu'''  # ensure determinism for the device-dependent torch.Generator
         A_      :				Dict		     =					self.dummy_cond_unet
         A_      :				Optional[Any]		     =					PNDMScheduler(skip_prk_steps=_SCREAMING_SNAKE_CASE		)
         A_      :				Any		     =					self.dummy_vae
         A_      :				Tuple		     =					self.dummy_text_encoder
         A_      :				Union[str, Any]		     =					CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''		)

         # make sure here that pndm scheduler skips prk
         A_      :				List[str]		     =					StableDiffusionPipeline(
             unet=_SCREAMING_SNAKE_CASE				,       scheduler=_SCREAMING_SNAKE_CASE				,       vae=_SCREAMING_SNAKE_CASE				,       text_encoder=_SCREAMING_SNAKE_CASE				,       tokenizer=_SCREAMING_SNAKE_CASE				,       safety_checker=_SCREAMING_SNAKE_CASE				,       feature_extractor=self.dummy_extractor				,       )
         A_      :				str		     =					sd_pipe.to(_SCREAMING_SNAKE_CASE		)
         sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE		)

         A_      :				Dict		     =					'''A painting of a squirrel eating a burger'''
         A_      :				List[Any]		     =					torch.Generator(device=_SCREAMING_SNAKE_CASE		).manual_seed(0		)
         A_      :				Union[str, Any]		     =					sd_pipe([prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=6.0				,       num_inference_steps=2				,       output_type='''np'''		)

         A_      :				Optional[Any]		     =					output.images

         A_      :				Dict		     =					torch.Generator(device=_SCREAMING_SNAKE_CASE		).manual_seed(0		)
         A_      :				List[str]		     =					sd_pipe(
             [prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=6.0				,       num_inference_steps=2				,       output_type='''np'''				,       return_dict=_SCREAMING_SNAKE_CASE				,       )[0]

         A_      :				str		     =					image[0, -3:, -3:, -1]
         A_      :				int		     =					image_from_tuple[0, -3:, -3:, -1]

         assert image.shape == (1, 64, 64, 3)
         A_      :				Optional[int]		     =					np.array([0.5_1_2_5, 0.5_7_1_6, 0.4_8_2_8, 0.5_0_6_0, 0.5_6_5_0, 0.4_7_6_8, 0.5_1_8_5, 0.4_8_9_5, 0.4_9_9_3]		)

         assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2
         assert np.abs(image_from_tuple_slice.flatten() - expected_slice		).max() < 1e-2



       def        _snake_case       (      self		)->int:




         '''simple docstring'''





         A_      :				Optional[int]		     =					StableDiffusionPipeline.from_pretrained(
             '''hf-internal-testing/tiny-stable-diffusion-lms-pipe'''				,       safety_checker=_SCREAMING_SNAKE_CASE		)
         assert isinstance(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         assert isinstance(pipe.scheduler				,       _SCREAMING_SNAKE_CASE		)
         assert pipe.safety_checker is None

         A_      :				Optional[Any]		     =					pipe('''example prompt'''				,       num_inference_steps=2		).images[0]
         assert image is not None

         # check that there's no error when saving a pipeline with one of the models being None
         with tempfile.TemporaryDirectory() as tmpdirname:
           pipe.save_pretrained(_SCREAMING_SNAKE_CASE		)
           A_      :				List[str]		     =					StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE		)

         # sanity check that the pipeline still works
         assert pipe.safety_checker is None
         A_      :				Optional[int]		     =					pipe('''example prompt'''				,       num_inference_steps=2		).images[0]
         assert image is not None







       @unittest.skipIf(torch_device != '''cuda'''				,       '''This test requires a GPU'''		)
       def        _snake_case       (      self		)->Optional[Any]:




         '''simple docstring'''





         A_      :				Optional[int]		     =					self.dummy_cond_unet
         A_      :				List[str]		     =					PNDMScheduler(skip_prk_steps=_SCREAMING_SNAKE_CASE		)
         A_      :				Any		     =					self.dummy_vae
         A_      :				Dict		     =					self.dummy_text_encoder
         A_      :				List[str]		     =					CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''		)

         # put models in fp16
         A_      :				List[str]		     =					unet.half()
         A_      :				Optional[Any]		     =					vae.half()
         A_      :				Optional[Any]		     =					bert.half()

         # make sure here that pndm scheduler skips prk
         A_      :				int		     =					StableDiffusionPipeline(
             unet=_SCREAMING_SNAKE_CASE				,       scheduler=_SCREAMING_SNAKE_CASE				,       vae=_SCREAMING_SNAKE_CASE				,       text_encoder=_SCREAMING_SNAKE_CASE				,       tokenizer=_SCREAMING_SNAKE_CASE				,       safety_checker=_SCREAMING_SNAKE_CASE				,       feature_extractor=self.dummy_extractor				,       )
         A_      :				str		     =					sd_pipe.to(_SCREAMING_SNAKE_CASE		)
         sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE		)

         A_      :				int		     =					'''A painting of a squirrel eating a burger'''
         A_      :				Dict		     =					sd_pipe([prompt]				,       num_inference_steps=2				,       output_type='''np'''		).images

         assert image.shape == (1, 64, 64, 3)






@nightly
@require_torch_gpu
class   _lowerCamelCase (					unittest.TestCase			):




       """simple docstring"""



       def        _snake_case       (      self		)->Dict:




         '''simple docstring'''





         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()



       def        _snake_case       (      self		)->int:




         '''simple docstring'''





         A_      :				Union[str, Any]		     =					StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''				,       safety_checker=_SCREAMING_SNAKE_CASE		)
         A_      :				Union[str, Any]		     =					LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config		)
         A_      :				Union[str, Any]		     =					sd_pipe.to(_SCREAMING_SNAKE_CASE		)
         sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE		)

         A_      :				List[Any]		     =					(
             '''portrait of girl with smokey eyes makeup in abandoned hotel, grange clothes, redshift, wide high angle'''
             ''' coloured polaroid photograph with flash, kodak film, hyper real, stunning moody cinematography, with'''
             ''' anamorphic lenses, by maripol, fallen angels by wong kar - wai, style of suspiria and neon demon and'''
             ''' children from bahnhof zoo, detailed '''
         )
         A_      :				List[str]		     =					40_0366_0346
         A_      :				Union[str, Any]		     =					7

         # without safety guidance (sld_guidance_scale = 0)
         A_      :				str		     =					torch.manual_seed(_SCREAMING_SNAKE_CASE		)
         A_      :				Union[str, Any]		     =					sd_pipe(
             [prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=_SCREAMING_SNAKE_CASE				,       num_inference_steps=50				,       output_type='''np'''				,       width=512				,       height=512				,       sld_guidance_scale=0				,       )

         A_      :				Tuple		     =					output.images
         A_      :				str		     =					image[0, -3:, -3:, -1]
         A_      :				List[str]		     =					[0.2_2_7_8, 0.2_2_3_1, 0.2_2_4_9, 0.2_3_3_3, 0.2_3_0_3, 0.1_8_8_5, 0.2_2_7_3, 0.2_1_4_4, 0.2_1_7_6]

         assert image.shape == (1, 512, 512, 3)

         assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2

         # without safety guidance (strong configuration)
         A_      :				Union[str, Any]		     =					torch.manual_seed(_SCREAMING_SNAKE_CASE		)
         A_      :				Union[str, Any]		     =					sd_pipe(
             [prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=_SCREAMING_SNAKE_CASE				,       num_inference_steps=50				,       output_type='''np'''				,       width=512				,       height=512				,       sld_guidance_scale=2000				,       sld_warmup_steps=7				,       sld_threshold=0.0_2_5				,       sld_momentum_scale=0.5				,       sld_mom_beta=0.7				,       )

         A_      :				List[str]		     =					output.images
         A_      :				int		     =					image[0, -3:, -3:, -1]
         A_      :				Optional[Any]		     =					[0.2_3_8_3, 0.2_2_7_6, 0.2_3_6, 0.2_1_9_2, 0.2_1_8_6, 0.2_0_5_3, 0.1_9_7_1, 0.1_9_0_1, 0.1_7_1_9]

         assert image.shape == (1, 512, 512, 3)

         assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2



       def        _snake_case       (      self		)->Optional[int]:




         '''simple docstring'''





         A_      :				Any		     =					StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''				,       safety_checker=_SCREAMING_SNAKE_CASE		)
         A_      :				Optional[int]		     =					LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config		)
         A_      :				Dict		     =					sd_pipe.to(_SCREAMING_SNAKE_CASE		)
         sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE		)

         A_      :				List[str]		     =					'''padme amidala taking a bath artwork, safe for work, no nudity'''
         A_      :				int		     =					27_3497_1755
         A_      :				str		     =					7

         A_      :				Tuple		     =					torch.manual_seed(_SCREAMING_SNAKE_CASE		)
         A_      :				Any		     =					sd_pipe(
             [prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=_SCREAMING_SNAKE_CASE				,       num_inference_steps=50				,       output_type='''np'''				,       width=512				,       height=512				,       sld_guidance_scale=0				,       )

         A_      :				List[Any]		     =					output.images
         A_      :				int		     =					image[0, -3:, -3:, -1]
         A_      :				Union[str, Any]		     =					[0.3_5_0_2, 0.3_6_2_2, 0.3_3_9_6, 0.3_6_4_2, 0.3_4_7_8, 0.3_3_1_8, 0.3_5, 0.3_3_4_8, 0.3_2_9_7]

         assert image.shape == (1, 512, 512, 3)

         assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2

         A_      :				Optional[Any]		     =					torch.manual_seed(_SCREAMING_SNAKE_CASE		)
         A_      :				Any		     =					sd_pipe(
             [prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=_SCREAMING_SNAKE_CASE				,       num_inference_steps=50				,       output_type='''np'''				,       width=512				,       height=512				,       sld_guidance_scale=2000				,       sld_warmup_steps=7				,       sld_threshold=0.0_2_5				,       sld_momentum_scale=0.5				,       sld_mom_beta=0.7				,       )

         A_      :				List[str]		     =					output.images
         A_      :				int		     =					image[0, -3:, -3:, -1]
         A_      :				List[str]		     =					[0.5_5_3_1, 0.5_2_0_6, 0.4_8_9_5, 0.5_1_5_6, 0.5_1_8_2, 0.4_7_5_1, 0.4_8_0_2, 0.4_8_0_3, 0.4_4_4_3]

         assert image.shape == (1, 512, 512, 3)

         assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2







       def        _snake_case       (      self		)->Tuple:




         '''simple docstring'''





         A_      :				Dict		     =					StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''		)
         A_      :				Optional[Any]		     =					sd_pipe.to(_SCREAMING_SNAKE_CASE		)
         sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE		)

         A_      :				Optional[Any]		     =					(
             '''the four horsewomen of the apocalypse, painting by tom of finland, gaston bussiere, craig mullins, j. c.'''
             ''' leyendecker'''
         )
         A_      :				Dict		     =					10_4435_5234
         A_      :				List[Any]		     =					12

         A_      :				str		     =					torch.manual_seed(_SCREAMING_SNAKE_CASE		)
         A_      :				str		     =					sd_pipe(
             [prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=_SCREAMING_SNAKE_CASE				,       num_inference_steps=50				,       output_type='''np'''				,       width=512				,       height=512				,       sld_guidance_scale=0				,       )

         A_      :				Optional[int]		     =					output.images
         A_      :				Optional[int]		     =					image[0, -3:, -3:, -1]
         A_      :				int		     =					np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]		)

         assert image.shape == (1, 512, 512, 3)

         assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-7

         A_      :				Optional[int]		     =					torch.manual_seed(_SCREAMING_SNAKE_CASE		)
         A_      :				int		     =					sd_pipe(
             [prompt]				,       generator=_SCREAMING_SNAKE_CASE				,       guidance_scale=_SCREAMING_SNAKE_CASE				,       num_inference_steps=50				,       output_type='''np'''				,       width=512				,       height=512				,       sld_guidance_scale=2000				,       sld_warmup_steps=7				,       sld_threshold=0.0_2_5				,       sld_momentum_scale=0.5				,       sld_mom_beta=0.7				,       )

         A_      :				str		     =					output.images
         A_      :				Optional[Any]		     =					image[0, -3:, -3:, -1]
         A_      :				str		     =					np.array([0.5_8_1_8, 0.6_2_8_5, 0.6_8_3_5, 0.6_0_1_9, 0.6_2_5, 0.6_7_5_4, 0.6_0_9_6, 0.6_3_3_4, 0.6_5_6_1]		)
         assert image.shape == (1, 512, 512, 3)

         assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2








def   _SCREAMING_SNAKE_CASE	( SCREAMING_SNAKE_CASE       ):
  A_      :				List[Any]		     =					current_set.copy()
  for row_index, row in enumerate(SCREAMING_SNAKE_CASE       ):
    A_      :				List[str]		     =					row[0]
    for column_index, column in enumerate(SCREAMING_SNAKE_CASE       ):
      if magnitude == 0:
        A_      :				Union[str, Any]		     =					column
        continue
      A_      :				Dict		     =					column / magnitude
    # Subtract to cancel term
  A_      :				Union[str, Any]		     =					current_set[0]
  A_      :				Tuple		     =					[first_row]
  A_      :				int		     =					current_set[1::]
  for row in current_set:
    A_      :				Tuple		     =					[]
    # If first term is 0, it is already in form we want, so we preserve it
    if row[0] == 0:
      final_set.append(SCREAMING_SNAKE_CASE       )
      continue
    for column_index in range(len(SCREAMING_SNAKE_CASE       )       ):
      temp_row.append(first_row[column_index] - row[column_index]       )
    final_set.append(SCREAMING_SNAKE_CASE       )
  # Create next recursion iteration set
  if len(final_set[0]       ) != 3:
    A_      :				Optional[Any]		     =					final_set[0]
    A_      :				Any		     =					[]
    A_      :				str		     =					[]
    for row in final_set[1::]:
      current_first_column.append(row[0]       )
      next_iteration.append(row[1::]       )
    A_      :				Optional[Any]		     =					simplify(SCREAMING_SNAKE_CASE       )
    for i in range(len(SCREAMING_SNAKE_CASE       )       ):
      resultant[i].insert(0 ,			current_first_column[i]       )
    resultant.insert(0 ,			SCREAMING_SNAKE_CASE       )
    A_      :				List[Any]		     =					resultant
  return final_set


def   _SCREAMING_SNAKE_CASE	( SCREAMING_SNAKE_CASE       ):
  if len(SCREAMING_SNAKE_CASE       ) == 0:
    raise IndexError('''solve_simultaneous() requires n lists of length n+1'''       )
  A_      :				str		     =					len(SCREAMING_SNAKE_CASE       ) + 1
  if any(len(SCREAMING_SNAKE_CASE       ) != _length for item in equations       ):
    raise IndexError('''solve_simultaneous() requires n lists of length n+1'''       )
  for row in equations:
    if any(not isinstance(SCREAMING_SNAKE_CASE ,			(int, float)       ) for column in row       ):
      raise ValueError('''solve_simultaneous() requires lists of integers'''       )
  if len(SCREAMING_SNAKE_CASE       ) == 1:
    return [equations[0][-1] / equations[0][0]]
  A_      :				Dict		     =					equations.copy()
  if any(0 in row for row in data_set       ):
    A_      :				Tuple		     =					data_set.copy()
    A_      :				Optional[Any]		     =					[]
    for row_index, row in enumerate(SCREAMING_SNAKE_CASE       ):
      if 0 not in row:
        A_      :				str		     =					data_set.pop(SCREAMING_SNAKE_CASE       )
        break
    if not full_row:
      raise ValueError('''solve_simultaneous() requires at least 1 full equation'''       )
    data_set.insert(0 ,			SCREAMING_SNAKE_CASE       )
  A_      :				int		     =					data_set.copy()
  A_      :				Dict		     =					simplify(SCREAMING_SNAKE_CASE       )
  A_      :				Dict		     =					simplified[::-1]
  A_      :				list		     =					[]
  for row in simplified:
    A_      :				Union[str, Any]		     =					row[-1]
    if not solutions:
      if row[-2] == 0:
        solutions.append(0       )
        continue
      solutions.append(current_solution / row[-2]       )
      continue
    A_      :				Optional[Any]		     =					row.copy()[: len(SCREAMING_SNAKE_CASE       ) - 1 :]
    while temp_row[0] == 0:
      temp_row.pop(0       )
    if len(SCREAMING_SNAKE_CASE       ) == 0:
      solutions.append(0       )
      continue
    A_      :				int		     =					temp_row[1::]
    A_      :				int		     =					temp_row[::-1]
    for column_index, column in enumerate(SCREAMING_SNAKE_CASE       ):
      current_solution -= column * solutions[column_index]
    solutions.append(SCREAMING_SNAKE_CASE       )
  A_      :				Union[str, Any]		     =					[]
  for item in solutions:
    final.append(float(round(SCREAMING_SNAKE_CASE ,			5       )       )       )
  return final[::-1]


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     UpperCamelCase								=	[
         [2, 1, 1, 1, 1, 4],
         [1, 2, 1, 1, 1, 5],
         [1, 1, 2, 1, 1, 6],
         [1, 1, 1, 2, 1, 7],
         [1, 1, 1, 1, 2, 8],
     ]
     print(solve_simultaneous(eq))
     print(solve_simultaneous([[4, 2]]))




