






"""simple docstring"""





import gc
import unittest

import numpy as np
import torch

from diffusers import DanceDiffusionPipeline, IPNDMScheduler, UNetaDModel
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS, UNCONDITIONAL_AUDIO_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()



class       __A		(   SCREAMING_SNAKE_CASE_     ,unittest.TestCase			):
					UpperCAmelCase__								=				DanceDiffusionPipeline
					UpperCAmelCase__								=				UNCONDITIONAL_AUDIO_GENERATION_PARAMS
					UpperCAmelCase__								=				PipelineTesterMixin.required_optional_params - {
					    "callback",
					    "latents",
					    "callback_steps",
					    "output_type",
					    "num_images_per_prompt",
					}
					UpperCAmelCase__								=				UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				False

					def   lowerCamelCase__   (			self  :      Union[str, Any]					)			->							List[Any]:
											torch.manual_seed(0					)
											__magic_name__:	Dict							=       UNetaDModel(
											    block_out_channels=(3_2, 3_2, 6_4)     ,		extra_in_channels=1_6     ,		sample_size=5_1_2     ,		sample_rate=1_6_0_0_0     ,		in_channels=2     ,		out_channels=2     ,		flip_sin_to_cos=__snake_case     ,		use_timestep_embedding=__snake_case     ,		time_embedding_type="""fourier"""     ,		mid_block_type="""UNetMidBlock1D"""     ,		down_block_types=("""DownBlock1DNoSkip""", """DownBlock1D""", """AttnDownBlock1D""")     ,		up_block_types=("""AttnUpBlock1D""", """UpBlock1D""", """UpBlock1DNoSkip""")     ,		)
											__magic_name__:	Tuple							=       IPNDMScheduler()

											__magic_name__:	Union[str, Any]							=       {
											    """unet""": unet,
											    """scheduler""": scheduler,
											}
											return components

					def   lowerCamelCase__   (			self  :      Optional[int]     ,		__snake_case  :      Optional[Any]     ,		__snake_case  :      List[str]=0					)			->							str:
											if str(__snake_case					).startswith("""mps"""					):
																	__magic_name__:	List[str]							=       torch.manual_seed(__snake_case					)
											else:
																	__magic_name__:	Union[str, Any]							=       torch.Generator(device=__snake_case					).manual_seed(__snake_case					)
											__magic_name__:	int							=       {
											    """batch_size""": 1,
											    """generator""": generator,
											    """num_inference_steps""": 4,
											}
											return inputs

					def   lowerCamelCase__   (			self  :      str					)			->							Optional[int]:
											__magic_name__:	int							=       """cpu"""  # ensure determinism for the device-dependent torch.Generator
											__magic_name__:	List[Any]							=       self.get_dummy_components()
											__magic_name__:	Dict							=       DanceDiffusionPipeline(**__snake_case					)
											__magic_name__:	List[str]							=       pipe.to(__snake_case					)
											pipe.set_progress_bar_config(disable=__snake_case					)

											__magic_name__:	Union[str, Any]							=       self.get_dummy_inputs(__snake_case					)
											__magic_name__:	Any							=       pipe(**__snake_case					)
											__magic_name__:	int							=       output.audios

											__magic_name__:	Optional[int]							=       audio[0, -3:, -3:]

											assert audio.shape == (1, 2, components["unet"].sample_size)
											__magic_name__:	Optional[Any]							=       np.array([-0.7265, 1.0000, -0.8388, 0.1175, 0.9498, -1.0000]					)
											assert np.abs(audio_slice.flatten() - expected_slice					).max() < 1E-2

					@skip_mps
					def   lowerCamelCase__   (			self  :      Dict					)			->							Optional[int]:
											return super().test_save_load_local()

					@skip_mps
					def   lowerCamelCase__   (			self  :      int					)			->							Union[str, Any]:
											return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3E-3					)

					@skip_mps
					def   lowerCamelCase__   (			self  :      List[Any]					)			->							List[str]:
											return super().test_save_load_optional_components()

					@skip_mps
					def   lowerCamelCase__   (			self  :      Tuple					)			->							Any:
											return super().test_attention_slicing_forward_pass()






					def   lowerCamelCase__   (			self  :      Dict					)			->							Optional[Any]:
											super().test_inference_batch_single_identical(expected_max_diff=3E-3					)



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

					def   lowerCamelCase__   (			self  :      Any					)			->							str:
											# clean up the VRAM after each test
											super().tearDown()
											gc.collect()
											torch.cuda.empty_cache()

					def   lowerCamelCase__   (			self  :      Tuple					)			->							Optional[int]:
											__magic_name__:	Tuple							=       torch_device

											__magic_name__:	Union[str, Any]							=       DanceDiffusionPipeline.from_pretrained("""harmonai/maestro-150k"""					)
											__magic_name__:	Optional[Any]							=       pipe.to(__snake_case					)
											pipe.set_progress_bar_config(disable=__snake_case					)

											__magic_name__:	List[str]							=       torch.manual_seed(0					)
											__magic_name__:	Any							=       pipe(generator=__snake_case     ,		num_inference_steps=1_0_0     ,		audio_length_in_s=4.096					)
											__magic_name__:	Union[str, Any]							=       output.audios

											__magic_name__:	Optional[int]							=       audio[0, -3:, -3:]

											assert audio.shape == (1, 2, pipe.unet.sample_size)
											__magic_name__:	int							=       np.array([-0.0192, -0.0231, -0.0318, -0.0059, 0.0002, -0.0020]					)

											assert np.abs(audio_slice.flatten() - expected_slice					).max() < 1E-2






					def   lowerCamelCase__   (			self  :      int					)			->							int:
											__magic_name__:	int							=       torch_device

											__magic_name__:	List[Any]							=       DanceDiffusionPipeline.from_pretrained("""harmonai/maestro-150k"""     ,		torch_dtype=torch.floataa					)
											__magic_name__:	List[str]							=       pipe.to(__snake_case					)
											pipe.set_progress_bar_config(disable=__snake_case					)

											__magic_name__:	Tuple							=       torch.manual_seed(0					)
											__magic_name__:	List[Any]							=       pipe(generator=__snake_case     ,		num_inference_steps=1_0_0     ,		audio_length_in_s=4.096					)
											__magic_name__:	str							=       output.audios

											__magic_name__:	Optional[Any]							=       audio[0, -3:, -3:]

											assert audio.shape == (1, 2, pipe.unet.sample_size)
											__magic_name__:	Any							=       np.array([-0.0367, -0.0488, -0.0771, -0.0525, -0.0444, -0.0341]					)

											assert np.abs(audio_slice.flatten() - expected_slice					).max() < 1E-2











"""simple docstring"""





from __future__ import annotations



def   a    (     __UpperCAmelCase      :    list  )    ->							list:
						if len(__UpperCAmelCase  ) == 0:
												return []
						__magic_name__,			__magic_name__:	List[str]							=       min(__UpperCAmelCase  ), max(__UpperCAmelCase  )
						__magic_name__:	Optional[int]							=       int(max_value - min_value  ) + 1
						__magic_name__:	list[list]							=       [[] for _ in range(__UpperCAmelCase  )]

						for i in my_list:
												buckets[int(i - min_value  )].append(__UpperCAmelCase  )

						return [v for bucket in buckets for v in sorted(__UpperCAmelCase  )]


if __name__ == "__main__":
							from doctest import testmod

							testmod()
							assert bucket_sort([4, 5, 3, 2, 1]) == [1, 2, 3, 4, 5]
							assert bucket_sort([0, 1, -10, 15, 2, -2]) == [-10, -2, 0, 1, 2, 15]



