"""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 			UpperCamelCase						(     lowercase_		, unittest.TestCase    ):
   lowercase				=    DanceDiffusionPipeline
   lowercase				=    UNCONDITIONAL_AUDIO_GENERATION_PARAMS
   lowercase				=    PipelineTesterMixin.required_optional_params - {
       'callback',
       'latents',
       'callback_steps',
       'output_type',
       'num_images_per_prompt',
   }
   lowercase				=    UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
   lowercase				=    False
   lowercase				=    False
   def      _UpperCAmelCase  (     self     )      -> Any:


        '''simple docstring'''


        torch.manual_seed(0     )
        lowercase_      :							List[str]						=      UNetaDModel(
            block_out_channels=(32, 32, 64)	,extra_in_channels=16	,sample_size=512	,sample_rate=1_6000	,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')	,)
        lowercase_      :							List[Any]						=      IPNDMScheduler()

        lowercase_      :							Any						=      {
            'unet': unet,
            'scheduler': scheduler,
        }
        return components
   def      _UpperCAmelCase  (     self	,__UpperCamelCase	,__UpperCamelCase=0     )      -> Optional[int]:


        '''simple docstring'''


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


        '''simple docstring'''


        lowercase_      :							Optional[int]						=      'cpu'  # ensure determinism for the device-dependent torch.Generator
        lowercase_      :							Optional[int]						=      self.get_dummy_components()
        lowercase_      :							int						=      DanceDiffusionPipeline(**lowerCamelCase__     )
        lowercase_      :							Union[str, Any]						=      pipe.to(lowerCamelCase__     )
        pipe.set_progress_bar_config(disable=lowerCamelCase__     )

        lowercase_      :							str						=      self.get_dummy_inputs(lowerCamelCase__     )
        lowercase_      :							Optional[Any]						=      pipe(**lowerCamelCase__     )
        lowercase_      :							List[str]						=      output.audios

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

        assert audio.shape == (1, 2, components["unet"].sample_size)
        lowercase_      :							Union[str, 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      _UpperCAmelCase  (     self     )      -> int:


        '''simple docstring'''


        return super().test_save_load_local()
   @skip_mps
   def      _UpperCAmelCase  (     self     )      -> Dict:


        '''simple docstring'''


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


        '''simple docstring'''


        return super().test_save_load_optional_components()
   @skip_mps
   def      _UpperCAmelCase  (     self     )      -> str:


        '''simple docstring'''


        return super().test_attention_slicing_forward_pass()







   def      _UpperCAmelCase  (     self     )      -> List[str]:


        '''simple docstring'''


        super().test_inference_batch_single_identical(expected_max_diff=3e-3     )







@slow
@require_torch_gpu
class 			UpperCamelCase						(     unittest.TestCase    ):
   def      _UpperCAmelCase  (     self     )      -> List[str]:


        '''simple docstring'''


        super().tearDown()
        gc.collect()
        torch.cuda.empty_cache()
   def      _UpperCAmelCase  (     self     )      -> str:


        '''simple docstring'''


        lowercase_      :							Optional[int]						=      torch_device

        lowercase_      :							Any						=      DanceDiffusionPipeline.from_pretrained('harmonai/maestro-150k'     )
        lowercase_      :							List[str]						=      pipe.to(lowerCamelCase__     )
        pipe.set_progress_bar_config(disable=lowerCamelCase__     )

        lowercase_      :							int						=      torch.manual_seed(0     )
        lowercase_      :							Any						=      pipe(generator=lowerCamelCase__	,num_inference_steps=100	,audio_length_in_s=4.096     )
        lowercase_      :							List[Any]						=      output.audios

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

        assert audio.shape == (1, 2, pipe.unet.sample_size)
        lowercase_      :							Optional[Any]						=      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      _UpperCAmelCase  (     self     )      -> List[Any]:


        '''simple docstring'''


        lowercase_      :							Tuple						=      torch_device

        lowercase_      :							str						=      DanceDiffusionPipeline.from_pretrained('harmonai/maestro-150k'	,torch_dtype=torch.floataa     )
        lowercase_      :							str						=      pipe.to(lowerCamelCase__     )
        pipe.set_progress_bar_config(disable=lowerCamelCase__     )

        lowercase_      :							Optional[Any]						=      torch.manual_seed(0     )
        lowercase_      :							Dict						=      pipe(generator=lowerCamelCase__	,num_inference_steps=100	,audio_length_in_s=4.096     )
        lowercase_      :							Tuple						=      output.audios

        lowercase_      :							Union[str, Any]						=      audio[0, -3:, -3:]

        assert audio.shape == (1, 2, pipe.unet.sample_size)
        lowercase_      :							Dict						=      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'''
def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_				):
						return base * power(UpperCAmelCase_    ,    (exponent - 1)				) if exponent else 1


if __name__ == "__main__":
					print('Raise base to the power of exponent using recursion...')
					snake_case_					:      int    			=    int(input('Enter the base: ').strip())
					snake_case_					:      Optional[int]    			=    int(input('Enter the exponent: ').strip())
					snake_case_					:      Optional[int]    			=    power(base, abs(exponent))
					if exponent < 0:  # power() does not properly deal w/ negative exponents
										snake_case_					:      List[Any]    			=    1 / result
					print(F"""{base} to the power of {exponent} is {result}""")


