
'''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 	__lowercase				(  _lowercase      ,     unittest.TestCase    ):
			lowerCamelCase			:		Any	      =			DanceDiffusionPipeline
			lowerCamelCase			:		str	      =			UNCONDITIONAL_AUDIO_GENERATION_PARAMS
			lowerCamelCase			:		Optional[int]	      =			PipelineTesterMixin.required_optional_params - {
			    "callback",
			    "latents",
			    "callback_steps",
			    "output_type",
			    "num_images_per_prompt",
			}
			lowerCamelCase			:		List[Any]	      =			UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
			lowerCamelCase			:		Tuple	      =			False
			lowerCamelCase			:		List[str]	      =			False

			def        UpperCAmelCase__ (self      ):
								torch.manual_seed(0      )
								lowerCamelCase_					:      List[Any]     =		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=A			,   use_timestep_embedding=A			,   time_embedding_type='''fourier'''			,   mid_block_type='''UNetMidBlock1D'''			,   down_block_types=('''DownBlock1DNoSkip''', '''DownBlock1D''', '''AttnDownBlock1D''')			,   up_block_types=('''AttnUpBlock1D''', '''UpBlock1D''', '''UpBlock1DNoSkip''')			,   )
								lowerCamelCase_					:      Tuple     =		IPNDMScheduler()

								lowerCamelCase_					:      List[str]     =		{
								    '''unet''': unet,
								    '''scheduler''': scheduler,
								}
								return components

			def        UpperCAmelCase__ (self			,   A			,   A=0      ):
								if str(A      ).startswith('''mps'''      ):
													lowerCamelCase_					:      Any     =		torch.manual_seed(A      )
								else:
													lowerCamelCase_					:      Optional[Any]     =		torch.Generator(device=A      ).manual_seed(A      )
								lowerCamelCase_					:      Tuple     =		{
								    '''batch_size''': 1,
								    '''generator''': generator,
								    '''num_inference_steps''': 4,
								}
								return inputs

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		'''cpu'''  # ensure determinism for the device-dependent torch.Generator
								lowerCamelCase_					:      Any     =		self.get_dummy_components()
								lowerCamelCase_					:      Dict     =		DanceDiffusionPipeline(**A      )
								lowerCamelCase_					:      Dict     =		pipe.to(A      )
								pipe.set_progress_bar_config(disable=A      )

								lowerCamelCase_					:      Optional[int]     =		self.get_dummy_inputs(A      )
								lowerCamelCase_					:      str     =		pipe(**A      )
								lowerCamelCase_					:      str     =		output.audios

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

								assert audio.shape == (1, 2, components["unet"].sample_size)
								lowerCamelCase_					:      Any     =		np.array([-0.72_65, 1.00_00, -0.83_88, 0.11_75, 0.94_98, -1.00_00]      )
								assert np.abs(audio_slice.flatten() - expected_slice      ).max() < 1E-2

			@skip_mps
			def        UpperCAmelCase__ (self      ):
								return super().test_save_load_local()

			@skip_mps
			def        UpperCAmelCase__ (self      ):
								return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3E-3      )

			@skip_mps
			def        UpperCAmelCase__ (self      ):
								return super().test_save_load_optional_components()

			@skip_mps
			def        UpperCAmelCase__ (self      ):
								return super().test_attention_slicing_forward_pass()






			def        UpperCAmelCase__ (self      ):
								super().test_inference_batch_single_identical(expected_max_diff=3E-3      )

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

			def        UpperCAmelCase__ (self      ):
								# clean up the VRAM after each test
								super().tearDown()
								gc.collect()
								torch.cuda.empty_cache()

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      int     =		torch_device

								lowerCamelCase_					:      Optional[Any]     =		DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k'''      )
								lowerCamelCase_					:      Any     =		pipe.to(A      )
								pipe.set_progress_bar_config(disable=A      )

								lowerCamelCase_					:      Optional[Any]     =		torch.manual_seed(0      )
								lowerCamelCase_					:      Optional[int]     =		pipe(generator=A			,   num_inference_steps=1_0_0			,   audio_length_in_s=4.0_96      )
								lowerCamelCase_					:      List[str]     =		output.audios

								lowerCamelCase_					:      Any     =		audio[0, -3:, -3:]

								assert audio.shape == (1, 2, pipe.unet.sample_size)
								lowerCamelCase_					:      List[Any]     =		np.array([-0.01_92, -0.02_31, -0.03_18, -0.00_59, 0.00_02, -0.00_20]      )

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






			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      List[str]     =		torch_device

								lowerCamelCase_					:      str     =		DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k'''			,   torch_dtype=torch.floataa      )
								lowerCamelCase_					:      Union[str, Any]     =		pipe.to(A      )
								pipe.set_progress_bar_config(disable=A      )

								lowerCamelCase_					:      List[Any]     =		torch.manual_seed(0      )
								lowerCamelCase_					:      List[str]     =		pipe(generator=A			,   num_inference_steps=1_0_0			,   audio_length_in_s=4.0_96      )
								lowerCamelCase_					:      List[Any]     =		output.audios

								lowerCamelCase_					:      str     =		audio[0, -3:, -3:]

								assert audio.shape == (1, 2, pipe.unet.sample_size)
								lowerCamelCase_					:      List[Any]     =		np.array([-0.03_67, -0.04_88, -0.07_71, -0.05_25, -0.04_44, -0.03_41]      )

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




'''simple docstring'''


from __future__ import annotations




def lowercase_	(   _lowercase			,       _lowercase			,       _lowercase			,       _lowercase				)     ->							None:
					'''simple docstring'''

					if (direction == 1 and array[indexa] > array[indexa]) or (
					    direction == 0 and array[indexa] < array[indexa]
					):
										lowerCamelCase_,      lowerCamelCase_					:      str     =		array[indexa], array[indexa]




def lowercase_	(   _lowercase			,       _lowercase			,       _lowercase			,       _lowercase				)     ->							None:
					'''simple docstring'''

					if length > 1:
										lowerCamelCase_					:      int     =		int(length / 2				)
										for i in range(_lowercase			,       low + middle				):
															comp_and_swap(_lowercase			,       _lowercase			,       i + middle			,       _lowercase				)
										bitonic_merge(_lowercase			,       _lowercase			,       _lowercase			,       _lowercase				)
										bitonic_merge(_lowercase			,       low + middle			,       _lowercase			,       _lowercase				)




def lowercase_	(   _lowercase			,       _lowercase			,       _lowercase			,       _lowercase				)     ->							None:
					'''simple docstring'''

					if length > 1:
										lowerCamelCase_					:      Dict     =		int(length / 2				)
										bitonic_sort(_lowercase			,       _lowercase			,       _lowercase			,       1				)
										bitonic_sort(_lowercase			,       low + middle			,       _lowercase			,       0				)
										bitonic_merge(_lowercase			,       _lowercase			,       _lowercase			,       _lowercase				)


if __name__ == "__main__":
					__lowercase							:   Any					=     input('''Enter numbers separated by a comma:\n''').strip()
					__lowercase							:   Tuple					=     [int(item.strip()) for item in user_input.split(''',''')]

					bitonic_sort(unsorted, 0, len(unsorted), 1)
					print('''\nSorted array in ascending order is: ''', end='''''')
					print(*unsorted, sep=''', ''')

					bitonic_merge(unsorted, 0, len(unsorted), 0)
					print('''Sorted array in descending order is: ''', end='''''')
					print(*unsorted, sep=''', ''')


