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




			def 					lowerCAmelCase__					(       self	):
				torch.manual_seed(0	)
				a_      				=						UNetaDModel(
				    block_out_channels=(32, 32, 64)					,   extra_in_channels=16					,   sample_size=5_12					,   sample_rate=1_60_00					,   in_channels=2					,   out_channels=2					,   flip_sin_to_cos=_lowerCAmelCase					,   use_timestep_embedding=_lowerCAmelCase					,   time_embedding_type="""fourier"""					,   mid_block_type="""UNetMidBlock1D"""					,   down_block_types=("""DownBlock1DNoSkip""", """DownBlock1D""", """AttnDownBlock1D""")					,   up_block_types=("""AttnUpBlock1D""", """UpBlock1D""", """UpBlock1DNoSkip""")					,   )
				a_      				=						IPNDMScheduler()

				a_      				=						{
				    '''unet''': unet,
				    '''scheduler''': scheduler,
				}
				return components




			def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase=0	):




				if str(_lowerCAmelCase	).startswith("""mps"""	):
					a_      				=						torch.manual_seed(_lowerCAmelCase	)
				else:
					a_      				=						torch.Generator(device=_lowerCAmelCase	).manual_seed(_lowerCAmelCase	)
				a_      				=						{
				    '''batch_size''': 1,
				    '''generator''': generator,
				    '''num_inference_steps''': 4,
				}
				return inputs




			def 					lowerCAmelCase__					(       self	):
				a_      				=						'''cpu'''  # ensure determinism for the device-dependent torch.Generator
				a_      				=						self.get_dummy_components()
				a_      				=						DanceDiffusionPipeline(**_lowerCAmelCase	)
				a_      				=						pipe.to(_lowerCAmelCase	)
				pipe.set_progress_bar_config(disable=_lowerCAmelCase	)

				a_      				=						self.get_dummy_inputs(_lowerCAmelCase	)
				a_      				=						pipe(**_lowerCAmelCase	)
				a_      				=						output.audios

				a_      				=						audio[0, -3:, -3:]

				assert audio.shape == (1, 2, components["unet"].sample_size)
				a_      				=						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 					lowerCAmelCase__					(       self	):
				return super().test_save_load_local()




			@skip_mps
			def 					lowerCAmelCase__					(       self	):
				return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3e-3	)




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




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






			def 					lowerCAmelCase__					(       self	):
				super().test_inference_batch_single_identical(expected_max_diff=3e-3	)







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




			def 					lowerCAmelCase__					(       self	):
				super().tearDown()
				gc.collect()
				torch.cuda.empty_cache()




			def 					lowerCAmelCase__					(       self	):
				a_      				=						torch_device

				a_      				=						DanceDiffusionPipeline.from_pretrained("""harmonai/maestro-150k"""	)
				a_      				=						pipe.to(_lowerCAmelCase	)
				pipe.set_progress_bar_config(disable=_lowerCAmelCase	)

				a_      				=						torch.manual_seed(0	)
				a_      				=						pipe(generator=_lowerCAmelCase					,   num_inference_steps=1_00					,   audio_length_in_s=4.0_96	)
				a_      				=						output.audios

				a_      				=						audio[0, -3:, -3:]

				assert audio.shape == (1, 2, pipe.unet.sample_size)
				a_      				=						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 					lowerCAmelCase__					(       self	):
				a_      				=						torch_device

				a_      				=						DanceDiffusionPipeline.from_pretrained("""harmonai/maestro-150k"""					,   torch_dtype=torch.floataa	)
				a_      				=						pipe.to(_lowerCAmelCase	)
				pipe.set_progress_bar_config(disable=_lowerCAmelCase	)

				a_      				=						torch.manual_seed(0	)
				a_      				=						pipe(generator=_lowerCAmelCase					,   num_inference_steps=1_00					,   audio_length_in_s=4.0_96	)
				a_      				=						output.audios

				a_      				=						audio[0, -3:, -3:]

				assert audio.shape == (1, 2, pipe.unet.sample_size)
				a_      				=						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







def 		lowerCAmelCase  (	UpperCamelCase__   :   List[Any]       ,			UpperCamelCase__   :   Dict					)      ->    List[Any]:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				int           =   [0 for i in range(r + 1					)]
						# nc0 = 1
						__SCREAMING_SNAKE_CASE:				Dict           =   1
						for i in range(1       ,			n + 1					):
												# to compute current row from previous row.
												__SCREAMING_SNAKE_CASE:				Optional[Any]           =   min(UpperCamelCase__       ,			UpperCamelCase__					)
												while j > 0:
																		c[j] += c[j - 1]
																		j -= 1
						return c[r]




print(binomial_coefficient(n=10, r=5))



