



"""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       (    lowerCAmelCase	,							unittest.TestCase):
			"""simple docstring"""
			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        lowercase__  (						self   :			Any      )->Optional[int]:
							torch.manual_seed(0      )
							_UpperCAmelCase							=			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=__UpperCamelCase ,      use_timestep_embedding=__UpperCamelCase ,      time_embedding_type='''fourier''' ,      mid_block_type='''UNetMidBlock1D''' ,      down_block_types=('''DownBlock1DNoSkip''', '''DownBlock1D''', '''AttnDownBlock1D''') ,      up_block_types=('''AttnUpBlock1D''', '''UpBlock1D''', '''UpBlock1DNoSkip''') ,      )
							_UpperCAmelCase							=			IPNDMScheduler()

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



			def        lowercase__  (						self   :			Optional[Any] ,      __UpperCamelCase   :			Optional[Any] ,      __UpperCamelCase   :			Optional[int]=0      )->Optional[int]:







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



			def        lowercase__  (						self   :			Optional[Any]      )->Optional[Any]:
							_UpperCAmelCase							=			'''cpu'''  # ensure determinism for the device-dependent torch.Generator
							_UpperCAmelCase							=			self.get_dummy_components()
							_UpperCAmelCase							=			DanceDiffusionPipeline(**__UpperCamelCase      )
							_UpperCAmelCase							=			pipe.to(__UpperCamelCase      )
							pipe.set_progress_bar_config(disable=__UpperCamelCase      )

							_UpperCAmelCase							=			self.get_dummy_inputs(__UpperCamelCase      )
							_UpperCAmelCase							=			pipe(**__UpperCamelCase      )
							_UpperCAmelCase							=			output.audios

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

							assert audio.shape == (1, 2, components["unet"].sample_size)
							_UpperCAmelCase							=			np.array([-0.7_2_6_5, 1.0_0_0_0, -0.8_3_8_8, 0.1_1_7_5, 0.9_4_9_8, -1.0_0_0_0]      )
							assert np.abs(audio_slice.flatten() - expected_slice      ).max() < 1e-2



			@skip_mps
			def        lowercase__  (						self   :			List[Any]      )->List[Any]:
							return super().test_save_load_local()



			@skip_mps
			def        lowercase__  (						self   :			str      )->List[str]:
							return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3e-3      )



			@skip_mps
			def        lowercase__  (						self   :			Tuple      )->int:
							return super().test_save_load_optional_components()



			@skip_mps
			def        lowercase__  (						self   :			int      )->List[Any]:
							return super().test_attention_slicing_forward_pass()



			def        lowercase__  (						self   :			str      )->str:
							super().test_inference_batch_single_identical(expected_max_diff=3e-3      )



@slow
@require_torch_gpu
class 	_a       (    unittest.TestCase):
			"""simple docstring"""



			def        lowercase__  (						self   :			List[Any]      )->List[Any]:
							super().tearDown()
							gc.collect()
							torch.cuda.empty_cache()



			def        lowercase__  (						self   :			List[Any]      )->List[str]:
							_UpperCAmelCase							=			torch_device

							_UpperCAmelCase							=			DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k'''      )
							_UpperCAmelCase							=			pipe.to(__UpperCamelCase      )
							pipe.set_progress_bar_config(disable=__UpperCamelCase      )

							_UpperCAmelCase							=			torch.manual_seed(0      )
							_UpperCAmelCase							=			pipe(generator=__UpperCamelCase ,      num_inference_steps=1_0_0 ,      audio_length_in_s=4.0_9_6      )
							_UpperCAmelCase							=			output.audios

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

							assert audio.shape == (1, 2, pipe.unet.sample_size)
							_UpperCAmelCase							=			np.array([-0.0_1_9_2, -0.0_2_3_1, -0.0_3_1_8, -0.0_0_5_9, 0.0_0_0_2, -0.0_0_2_0]      )

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



			def        lowercase__  (						self   :			Union[str, Any]      )->Union[str, Any]:
							_UpperCAmelCase							=			torch_device

							_UpperCAmelCase							=			DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k''' ,      torch_dtype=torch.floataa      )
							_UpperCAmelCase							=			pipe.to(__UpperCamelCase      )
							pipe.set_progress_bar_config(disable=__UpperCamelCase      )

							_UpperCAmelCase							=			torch.manual_seed(0      )
							_UpperCAmelCase							=			pipe(generator=__UpperCamelCase ,      num_inference_steps=1_0_0 ,      audio_length_in_s=4.0_9_6      )
							_UpperCAmelCase							=			output.audios

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

							assert audio.shape == (1, 2, pipe.unet.sample_size)
							_UpperCAmelCase							=			np.array([-0.0_3_6_7, -0.0_4_8_8, -0.0_7_7_1, -0.0_5_2_5, -0.0_4_4_4, -0.0_3_4_1]      )

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









from __future__ import annotations





def 		__A		(	__lowerCamelCase							,			__lowerCamelCase = None    )      ->       list[list[str]]:
	a										=							word_bank or []
	# create a table
	a										=							len(__lowerCamelCase    ) + 1

	a										=							[]
	for _ in range(__lowerCamelCase    ):
		table.append([]    )
	# seed value
	a										=							[[]]  # because empty string has empty combination

	# iterate through the indices
	for i in range(__lowerCamelCase    ):
		# condition
		if table[i] != []:
			for word in word_bank:
				# slice condition
				if target[i : i + len(__lowerCamelCase    )] == word:
					a										=							[
					    [word, *way] for way in table[i]
					]
					# adds the word to every combination the current position holds
					# now,push that combination to the table[i+len(word)]
					table[i + len(__lowerCamelCase    )] += new_combinations

    # combinations are in reverse order so reverse for better output
	for combination in table[len(__lowerCamelCase    )]:
		combination.reverse()

	return table[len(__lowerCamelCase    )]


if __name__ == "__main__":
		print(all_construct("jwajalapa", ["jwa", "j", "w", "a", "la", "lapa"]))
		print(all_construct("rajamati", ["s", "raj", "amat", "raja", "ma", "i", "t"]))
		print(
		    all_construct(
		        "hexagonosaurus",
		        ["h", "ex", "hex", "ag", "ago", "ru", "auru", "rus", "go", "no", "o", "s"],
		    )
		)

