





import math





def 	lowerCAmelCase_					(			__a      ,       __a = 0      ,       __a = 0						)	->						list:







  """simple docstring"""





  lowerCamelCase__: int         =end or len(snake_case_						)
  for i in range(snake_case_      ,       snake_case_						):
    lowerCamelCase__: Union[str, Any]         =i
    lowerCamelCase__: List[str]         =array[i]
    while temp_index != start and temp_index_value < array[temp_index - 1]:
      lowerCamelCase__: str         =array[temp_index - 1]
      temp_index -= 1
    lowerCamelCase__: List[Any]         =temp_index_value
  return array





def 	lowerCAmelCase_					(			__a      ,       __a      ,       __a						)	->						None:  # Max Heap







  """simple docstring"""





  lowerCamelCase__: Any         =index
  lowerCamelCase__: Union[str, Any]         =2 * index + 1  # Left Node
  lowerCamelCase__: Union[str, Any]         =2 * index + 2  # Right Node

  if left_index < heap_size and array[largest] < array[left_index]:
    lowerCamelCase__: Optional[int]         =left_index

  if right_index < heap_size and array[largest] < array[right_index]:
    lowerCamelCase__: Any         =right_index

  if largest != index:
    lowerCamelCase__: str         =array[largest], array[index]
    heapify(snake_case_      ,       snake_case_      ,       snake_case_						)





def 	lowerCAmelCase_					(			__a						)	->						list:







  """simple docstring"""





  lowerCamelCase__: Tuple         =len(snake_case_						)

  for i in range(n // 2      ,       -1      ,       -1						):
    heapify(snake_case_      ,       snake_case_      ,       snake_case_						)

  for i in range(n - 1      ,       0      ,       -1						):
    lowerCamelCase__: Union[str, Any]         =array[0], array[i]
    heapify(snake_case_      ,       0      ,       snake_case_						)

  return array





def 	lowerCAmelCase_					(			__a      ,       __a      ,       __a      ,       __a						)	->						int:







  """simple docstring"""





  if (array[first_index] > array[middle_index]) != (
      array[first_index] > array[last_index]
  ):
    return array[first_index]
  elif (array[middle_index] > array[first_index]) != (
      array[middle_index] > array[last_index]
  ):
    return array[middle_index]
  else:
    return array[last_index]





def 	lowerCAmelCase_					(			__a      ,       __a      ,       __a      ,       __a						)	->						int:







  """simple docstring"""





  lowerCamelCase__: Any         =low
  lowerCamelCase__: Union[str, Any]         =high
  while True:
    while array[i] < pivot:
      i += 1
    j -= 1
    while pivot < array[j]:
      j -= 1
    if i >= j:
      return i
    lowerCamelCase__: Dict         =array[j], array[i]
    i += 1





def 	lowerCAmelCase_					(			__a						)	->						list:







  """simple docstring"""





  if len(snake_case_						) == 0:
    return array
  lowerCamelCase__: List[Any]         =2 * math.ceil(math.loga(len(snake_case_						)						)						)
  lowerCamelCase__: List[Any]         =16
  return intro_sort(snake_case_      ,       0      ,       len(snake_case_						)      ,       snake_case_      ,       snake_case_						)





def 	lowerCAmelCase_					(			__a      ,       __a      ,       __a      ,       __a      ,       __a						)	->						list:







  """simple docstring"""





  while end - start > size_threshold:
    if max_depth == 0:
      return heap_sort(snake_case_						)
    max_depth -= 1
    lowerCamelCase__: str         =median_of_a(snake_case_      ,       snake_case_      ,       start + ((end - start) // 2) + 1      ,       end - 1						)
    lowerCamelCase__: str         =partition(snake_case_      ,       snake_case_      ,       snake_case_      ,       snake_case_						)
    intro_sort(snake_case_      ,       snake_case_      ,       snake_case_      ,       snake_case_      ,       snake_case_						)
    lowerCamelCase__: List[str]         =p
  return insertion_sort(snake_case_      ,       snake_case_      ,       snake_case_						)


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     __A							   =							input("Enter numbers separated by a comma : ").strip()
     __A							   =							[float(item) for item in user_input.split(",")]
     print(sort(unsorted))








"""simple docstring"""



import gc
import random
import unittest

import numpy as np
import torch

from diffusers import DDIMScheduler, KandinskyVaaPipeline, KandinskyVaaPriorPipeline, UNetaDConditionModel, VQModel
from diffusers.utils import floats_tensor, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference


enable_full_determinism()






class 						__snake_case   (						SCREAMING_SNAKE_CASE__				,				unittest.TestCase	):





 """simple docstring"""


 _lowerCamelCase								=	KandinskyVaaPipeline
 _lowerCamelCase								=	[
     """image_embeds""",
     """negative_image_embeds""",
 ]
 _lowerCamelCase								=	["""image_embeds""", """negative_image_embeds"""]
 _lowerCamelCase								=	[
     """generator""",
     """height""",
     """width""",
     """latents""",
     """guidance_scale""",
     """num_inference_steps""",
     """return_dict""",
     """guidance_scale""",
     """num_images_per_prompt""",
     """output_type""",
     """return_dict""",
 ]
 _lowerCamelCase								=	False

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return 32

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return 32

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return self.time_input_dim

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return self.time_input_dim * 4

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return 100

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     torch.manual_seed(0    )

     __A       :		Optional[Any]							=	{
         '''in_channels''': 4,
         # Out channels is double in channels because predicts mean and variance
         '''out_channels''': 8,
         '''addition_embed_type''': '''image''',
         '''down_block_types''': ('''ResnetDownsampleBlock2D''', '''SimpleCrossAttnDownBlock2D'''),
         '''up_block_types''': ('''SimpleCrossAttnUpBlock2D''', '''ResnetUpsampleBlock2D'''),
         '''mid_block_type''': '''UNetMidBlock2DSimpleCrossAttn''',
         '''block_out_channels''': (self.block_out_channels_a, self.block_out_channels_a * 2),
         '''layers_per_block''': 1,
         '''encoder_hid_dim''': self.text_embedder_hidden_size,
         '''encoder_hid_dim_type''': '''image_proj''',
         '''cross_attention_dim''': self.cross_attention_dim,
         '''attention_head_dim''': 4,
         '''resnet_time_scale_shift''': '''scale_shift''',
         '''class_embed_type''': None,
     }

     __A       :		Optional[Any]							=	UNetaDConditionModel(**__lowerCamelCase    )
     return model

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return {
         "block_out_channels": [32, 64],
         "down_block_types": ["DownEncoderBlock2D", "AttnDownEncoderBlock2D"],
         "in_channels": 3,
         "latent_channels": 4,
         "layers_per_block": 1,
         "norm_num_groups": 8,
         "norm_type": "spatial",
         "num_vq_embeddings": 12,
         "out_channels": 3,
         "up_block_types": [
             "AttnUpDecoderBlock2D",
             "UpDecoderBlock2D",
         ],
         "vq_embed_dim": 4,
     }

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     torch.manual_seed(0    )
     __A       :		Tuple							=	VQModel(**self.dummy_movq_kwargs    )
     return model

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		List[Any]							=	self.dummy_unet
     __A       :		Optional[int]							=	self.dummy_movq

     __A       :		List[Any]							=	DDIMScheduler(
         num_train_timesteps=1000   ,		beta_schedule='''linear'''   ,		beta_start=0.0_0_0_8_5   ,		beta_end=0.0_1_2   ,		clip_sample=__lowerCamelCase   ,		set_alpha_to_one=__lowerCamelCase   ,		steps_offset=1   ,		prediction_type='''epsilon'''   ,		thresholding=__lowerCamelCase   ,		)

     __A       :		Optional[int]							=	{
         '''unet''': unet,
         '''scheduler''': scheduler,
         '''movq''': movq,
     }
     return components

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase=0    ):



     '''simple docstring'''




     __A       :		Optional[int]							=	floats_tensor((1, self.text_embedder_hidden_size)   ,		rng=random.Random(__lowerCamelCase    )    ).to(__lowerCamelCase    )
     __A       :		List[Any]							=	floats_tensor((1, self.text_embedder_hidden_size)   ,		rng=random.Random(seed + 1    )    ).to(
         __lowerCamelCase    )
     if str(__lowerCamelCase    ).startswith('''mps'''    ):
         __A       :		Optional[Any]							=	torch.manual_seed(__lowerCamelCase    )
     else:
         __A       :		Dict							=	torch.Generator(device=__lowerCamelCase    ).manual_seed(__lowerCamelCase    )
     __A       :		Dict							=	{
         '''image_embeds''': image_embeds,
         '''negative_image_embeds''': negative_image_embeds,
         '''generator''': generator,
         '''height''': 64,
         '''width''': 64,
         '''guidance_scale''': 4.0,
         '''num_inference_steps''': 2,
         '''output_type''': '''np''',
     }
     return inputs







 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		str							=	'''cpu'''

     __A       :		str							=	self.get_dummy_components()

     __A       :		Dict							=	self.pipeline_class(**__lowerCamelCase    )
     __A       :		Tuple							=	pipe.to(__lowerCamelCase    )

     pipe.set_progress_bar_config(disable=__lowerCamelCase    )

     __A       :		List[str]							=	pipe(**self.get_dummy_inputs(__lowerCamelCase    )    )
     __A       :		Tuple							=	output.images

     __A       :		Tuple							=	pipe(
         **self.get_dummy_inputs(__lowerCamelCase    )   ,		return_dict=__lowerCamelCase   ,		)[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       :		Optional[int]							=	np.array(
         [0.6_2_3_7_9_7_6, 1.0, 0.3_6_4_4_1_3_3_2, 1.0, 0.7_0_6_3_9_6_3_4, 0.2_9_8_7_7_1_8_6, 0.8_5_6_5_2_1_2_5, 0.5_2_1_6_8_4_3, 0.5_4_4_5_4_0_4_6]    )

     assert (
         np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-2
     ), F""" expected_slice {expected_slice}, but got {image_slice.flatten()}"""

     assert (
         np.abs(image_from_tuple_slice.flatten() - expected_slice    ).max() < 1e-2
     ), F""" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"""






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





 """simple docstring"""


 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




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







 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		Any							=	load_numpy(
         '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
         '''/kandinskyv22/kandinskyv22_text2img_cat_fp16.npy'''    )

     __A       :		Optional[Any]							=	KandinskyVaaPriorPipeline.from_pretrained(
         '''kandinsky-community/kandinsky-2-2-prior'''   ,		torch_dtype=torch.floataa    )
     pipe_prior.to(__lowerCamelCase    )

     __A       :		int							=	KandinskyVaaPipeline.from_pretrained(
         '''kandinsky-community/kandinsky-2-2-decoder'''   ,		torch_dtype=torch.floataa    )
     __A       :		Union[str, Any]							=	pipeline.to(__lowerCamelCase    )
     pipeline.set_progress_bar_config(disable=__lowerCamelCase    )

     __A       :		List[Any]							=	'''red cat, 4k photo'''

     __A       :		Union[str, Any]							=	torch.Generator(device='''cuda'''    ).manual_seed(0    )
     __A					,			__A       :		List[str]							=	pipe_prior(
         __lowerCamelCase   ,		generator=__lowerCamelCase   ,		num_inference_steps=5   ,		negative_prompt=''''''   ,		).to_tuple()

     __A       :		Any							=	torch.Generator(device='''cuda'''    ).manual_seed(0    )
     __A       :		Optional[int]							=	pipeline(
         image_embeds=__lowerCamelCase   ,		negative_image_embeds=__lowerCamelCase   ,		generator=__lowerCamelCase   ,		num_inference_steps=100   ,		output_type='''np'''   ,		)

     __A       :		Union[str, Any]							=	output.images[0]

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

     assert_mean_pixel_difference(__lowerCamelCase   ,		__lowerCamelCase    )




