

'''simple docstring'''
import gc
import unittest

import numpy as np
import torch

from diffusers import DDPMScheduler, MidiProcessor, SpectrogramDiffusionPipeline
from diffusers.pipelines.spectrogram_diffusion import SpectrogramContEncoder, SpectrogramNotesEncoder, TaFilmDecoder
from diffusers.utils import require_torch_gpu, skip_mps, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_note_seq, require_onnxruntime

from ..pipeline_params import TOKENS_TO_AUDIO_GENERATION_BATCH_PARAMS, TOKENS_TO_AUDIO_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()


__magic_name__     						=						"""./tests/fixtures/elise_format0.mid"""


@unittest.skip('The note-seq package currently throws an error on import'						)
class      a__						(							lowerCAmelCase_						,   unittest.TestCase						):
   _SCREAMING_SNAKE_CASE					:  Tuple			 =							SpectrogramDiffusionPipeline
   _SCREAMING_SNAKE_CASE					:  int			 =							PipelineTesterMixin.required_optional_params - {
       """callback""",
       """latents""",
       """callback_steps""",
       """output_type""",
       """num_images_per_prompt""",
   }
   _SCREAMING_SNAKE_CASE					:  Any			 =							False
   _SCREAMING_SNAKE_CASE					:  str			 =							False
   _SCREAMING_SNAKE_CASE					:  Tuple			 =							TOKENS_TO_AUDIO_GENERATION_PARAMS
   _SCREAMING_SNAKE_CASE					:  int			 =							TOKENS_TO_AUDIO_GENERATION_BATCH_PARAMS


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      torch.manual_seed(0						)
      _lowercase    :   Any      =     SpectrogramNotesEncoder(
          max_length=2048    ,       vocab_size=1536    ,       d_model=768    ,       dropout_rate=0.1    ,       num_layers=1    ,       num_heads=1    ,       d_kv=4    ,       d_ff=2048    ,       feed_forward_proj="gated-gelu"    ,       )

      _lowercase    :   Any      =     SpectrogramContEncoder(
          input_dims=128    ,       targets_context_length=256    ,       d_model=768    ,       dropout_rate=0.1    ,       num_layers=1    ,       num_heads=1    ,       d_kv=4    ,       d_ff=2048    ,       feed_forward_proj="gated-gelu"    ,       )

      _lowercase    :   int      =     TaFilmDecoder(
          input_dims=128    ,       targets_length=256    ,       max_decoder_noise_time=20000.0    ,       d_model=768    ,       num_layers=1    ,       num_heads=1    ,       d_kv=4    ,       d_ff=2048    ,       dropout_rate=0.1    ,       )

      _lowercase    :   Any      =     DDPMScheduler()

      _lowercase    :   str      =     {
          "notes_encoder": notes_encoder.eval(),
          "continuous_encoder": continuous_encoder.eval(),
          "decoder": decoder.eval(),
          "scheduler": scheduler,
          "melgan": None,
      }
      return components


   def 		_lowerCamelCase     (				self    ,       _UpperCamelCase    ,       _UpperCamelCase=0						):





      """simple docstring"""





      if str(__SCREAMING_SNAKE_CASE						).startswith("mps"						):
         _lowercase    :   str      =     torch.manual_seed(__SCREAMING_SNAKE_CASE						)
      else:
         _lowercase    :   List[str]      =     torch.Generator(device=__SCREAMING_SNAKE_CASE						).manual_seed(__SCREAMING_SNAKE_CASE						)
      _lowercase    :   Tuple      =     {
          "input_tokens": [
              [1134, 90, 1135, 1133, 1080, 112, 1132, 1080, 1133, 1079, 133, 1132, 1079, 1133, 1] + [0] * 2033
          ],
          "generator": generator,
          "num_inference_steps": 4,
          "output_type": "mel",
      }
      return inputs


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Optional[Any]      =     "cpu"  # ensure determinism for the device-dependent torch.Generator
      _lowercase    :   Union[str, Any]      =     self.get_dummy_components()
      _lowercase    :   Tuple      =     SpectrogramDiffusionPipeline(**__SCREAMING_SNAKE_CASE						)
      _lowercase    :   List[str]      =     pipe.to(__SCREAMING_SNAKE_CASE						)
      pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE						)

      _lowercase    :   str      =     self.get_dummy_inputs(__SCREAMING_SNAKE_CASE						)
      _lowercase    :   Optional[Any]      =     pipe(**__SCREAMING_SNAKE_CASE						)
      _lowercase    :   Any      =     output.audios

      _lowercase    :   Tuple      =     mel[0, -3:, -3:]

      assert mel_slice.shape == (3, 3)
      _lowercase    :   Dict      =     np.array(
          [-1_1.5_1_2_9_2_5, -4.7_8_8_2_1_5, -0.4_6_1_7_2_9_0_5, -2.0_5_1_7_1_5, -1_0.5_3_9_1_4_7, -1_0.9_7_0_9_6_3, -9.0_9_1_6_3_4, 4.0, 4.0]						)
      assert np.abs(mel_slice.flatten() - expected_slice						).max() < 1E-2


   @skip_mps
   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      return super().test_save_load_local()


   @skip_mps
   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      return super().test_dict_tuple_outputs_equivalent()


   @skip_mps
   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      return super().test_save_load_optional_components()


   @skip_mps
   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      return super().test_attention_slicing_forward_pass()


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      pass


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      pass






   @skip_mps
   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      return super().test_progress_bar()




@slow
@require_torch_gpu
@require_onnxruntime
@require_note_seq
class      a__						(							unittest.TestCase						):


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





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


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Union[str, Any]      =     torch_device

      _lowercase    :   Tuple      =     SpectrogramDiffusionPipeline.from_pretrained("google/music-spectrogram-diffusion"						)
      _lowercase    :   List[Any]      =     pipe.melgan
      _lowercase    :   str      =     None

      _lowercase    :   Union[str, Any]      =     pipe.to(__SCREAMING_SNAKE_CASE						)
      pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE						)

      def callback(_UpperCamelCase    ,       _UpperCamelCase						):
         # decode mel to audio
         _lowercase    :   Any      =     melgan(input_features=mel_output.astype(np.floataa						)						)[0]
         assert len(audio[0]						) == 81920 * (step + 1)
         # simulate that audio is played
         return audio

      _lowercase    :   int      =     MidiProcessor()
      _lowercase    :   Dict      =     processor(__SCREAMING_SNAKE_CASE						)

      _lowercase    :   Optional[Any]      =     input_tokens[:3]
      _lowercase    :   str      =     torch.manual_seed(0						)
      pipe(__SCREAMING_SNAKE_CASE    ,       num_inference_steps=5    ,       generator=__SCREAMING_SNAKE_CASE    ,       callback=__SCREAMING_SNAKE_CASE    ,       output_type="mel"						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Tuple      =     torch_device

      _lowercase    :   Tuple      =     SpectrogramDiffusionPipeline.from_pretrained("google/music-spectrogram-diffusion"						)
      _lowercase    :   str      =     pipe.to(__SCREAMING_SNAKE_CASE						)
      pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE						)
      _lowercase    :   int      =     MidiProcessor()

      _lowercase    :   int      =     processor(__SCREAMING_SNAKE_CASE						)
      # just run two denoising loops
      _lowercase    :   Optional[int]      =     input_tokens[:2]

      _lowercase    :   List[str]      =     torch.manual_seed(0						)
      _lowercase    :   Any      =     pipe(__SCREAMING_SNAKE_CASE    ,       num_inference_steps=2    ,       generator=__SCREAMING_SNAKE_CASE						)

      _lowercase    :   Any      =     output.audios[0]

      assert abs(np.abs(__SCREAMING_SNAKE_CASE						).sum() - 3_6_1_2.8_4_1						) < 1E-1






   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Optional[int]      =     torch_device

      _lowercase    :   Dict      =     SpectrogramDiffusionPipeline.from_pretrained("google/music-spectrogram-diffusion"						)
      _lowercase    :   Tuple      =     pipe.to(__SCREAMING_SNAKE_CASE						)
      pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE						)

      _lowercase    :   Optional[int]      =     MidiProcessor()

      _lowercase    :   int      =     processor(__SCREAMING_SNAKE_CASE						)

      # just run 4 denoising loops
      _lowercase    :   Dict      =     input_tokens[:4]

      _lowercase    :   Any      =     torch.manual_seed(0						)
      _lowercase    :   int      =     pipe(__SCREAMING_SNAKE_CASE    ,       num_inference_steps=100    ,       generator=__SCREAMING_SNAKE_CASE						)

      _lowercase    :   Dict      =     output.audios[0]
      assert abs(np.abs(__SCREAMING_SNAKE_CASE						).sum() - 9_3_8_9.1_1_1_1						) < 5E-2









'''simple docstring'''
def       _A	(			snake_case  )    ->			list:
   _lowercase    :   Optional[Any]      =     1.3
   _lowercase    :   Optional[Any]      =     len(snake_case  )
   _lowercase    :   Optional[int]      =     False

   while not completed:
      # Update the gap value for a next comb
      _lowercase    :   Tuple      =     int(gap / shrink_factor  )
      if gap <= 1:
         _lowercase    :   List[str]      =     True

      _lowercase    :   Optional[int]      =     0
      while index + gap < len(snake_case  ):
         if data[index] > data[index + gap]:
            # Swap values
            _lowercase  ,   _lowercase    :   Any      =     data[index + gap], data[index]
            _lowercase    :   Tuple      =     False
         index += 1

   return data


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    _snake_case     						=						input('Enter numbers separated by a comma:\n').strip()
    _snake_case     						=						[int(item) for item in user_input.split(',')]
    print(comb_sort(unsorted))






