
"""simple docstring"""




import gc
import unittest

import numpy as np
import torch

from diffusers import (
    AudioDiffusionPipeline,
    AutoencoderKL,
    DDIMScheduler,
    DDPMScheduler,
    DiffusionPipeline,
    Mel,
    UNetaDConditionModel,
    UNetaDModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()


class       __magic_name__							(							unittest.TestCase			):
       def 				lowercase_				(  self							)  ->						Optional[Any]:





         """simple docstring"""




         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()
       @property
       def 				lowercase_				(  self							)  ->						Optional[int]:





         """simple docstring"""




         torch.manual_seed(0							)
         _lowercase:      Any   			=  UNetaDModel(
             sample_size=(32, 64)			,					in_channels=1			,					out_channels=1			,					layers_per_block=2			,					block_out_channels=(128, 128)			,					down_block_types=('''AttnDownBlock2D''', '''DownBlock2D''')			,					up_block_types=('''UpBlock2D''', '''AttnUpBlock2D''')			,					)
         return model
       @property
       def 				lowercase_				(  self							)  ->						Any:





         """simple docstring"""




         torch.manual_seed(0							)
         _lowercase:      Optional[Any]   			=  UNetaDConditionModel(
             sample_size=(64, 32)			,					in_channels=1			,					out_channels=1			,					layers_per_block=2			,					block_out_channels=(128, 128)			,					down_block_types=('''CrossAttnDownBlock2D''', '''DownBlock2D''')			,					up_block_types=('''UpBlock2D''', '''CrossAttnUpBlock2D''')			,					cross_attention_dim=10			,					)
         return model
       @property
       def 				lowercase_				(  self							)  ->						int:





         """simple docstring"""




         torch.manual_seed(0							)
         _lowercase:      Tuple   			=  AutoencoderKL(
             sample_size=(128, 64)			,					in_channels=1			,					out_channels=1			,					latent_channels=1			,					layers_per_block=2			,					block_out_channels=(128, 128)			,					down_block_types=('''DownEncoderBlock2D''', '''DownEncoderBlock2D''')			,					up_block_types=('''UpDecoderBlock2D''', '''UpDecoderBlock2D''')			,					)
         _lowercase:      Optional[int]   			=  UNetaDModel(
             sample_size=(64, 32)			,					in_channels=1			,					out_channels=1			,					layers_per_block=2			,					block_out_channels=(128, 128)			,					down_block_types=('''AttnDownBlock2D''', '''DownBlock2D''')			,					up_block_types=('''UpBlock2D''', '''AttnUpBlock2D''')			,					)
         return vqvae, unet



       @slow
       def 				lowercase_				(  self							)  ->						int:





         """simple docstring"""




         _lowercase:      Union[str, Any]   			=  '''cpu'''  # ensure determinism for the device-dependent torch.Generator
         _lowercase:      Any   			=  Mel(
             x_res=self.dummy_unet.config.sample_size[1]			,					y_res=self.dummy_unet.config.sample_size[0]			,					)

         _lowercase:      Any   			=  DDPMScheduler()
         _lowercase:      Tuple   			=  AudioDiffusionPipeline(vqvae=A_			,					unet=self.dummy_unet			,					mel=A_			,					scheduler=A_							)
         _lowercase:      List[str]   			=  pipe.to(A_							)
         pipe.set_progress_bar_config(disable=A_							)

         _lowercase:      Tuple   			=  torch.Generator(device=A_							).manual_seed(42							)
         _lowercase:      Dict   			=  pipe(generator=A_			,					steps=4							)
         _lowercase:      Any   			=  output.audios[0]
         _lowercase:      List[Any]   			=  output.images[0]

         _lowercase:      List[Any]   			=  torch.Generator(device=A_							).manual_seed(42							)
         _lowercase:      str   			=  pipe(generator=A_			,					steps=4			,					return_dict=A_							)
         _lowercase:      Optional[int]   			=  output[0][0]

         assert audio.shape == (1, (self.dummy_unet.config.sample_size[1] - 1) * mel.hop_length)
         assert (
             image.height == self.dummy_unet.config.sample_size[0]
             and image.width == self.dummy_unet.config.sample_size[1]
         )
         _lowercase:      Dict   			=  np.frombuffer(image.tobytes()			,					dtype='''uint8'''							)[:10]
         _lowercase:      Dict   			=  np.frombuffer(image_from_tuple.tobytes()			,					dtype='''uint8'''							)[:10]
         _lowercase:      Tuple   			=  np.array([69, 255, 255, 255, 0, 0, 77, 181, 12, 127]							)

         assert np.abs(image_slice.flatten() - expected_slice							).max() == 0
         assert np.abs(image_from_tuple_slice.flatten() - expected_slice							).max() == 0

         _lowercase:      List[Any]   			=  Mel(
             x_res=self.dummy_vqvae_and_unet[0].config.sample_size[1]			,					y_res=self.dummy_vqvae_and_unet[0].config.sample_size[0]			,					)

         _lowercase:      Dict   			=  DDIMScheduler()
         _lowercase:      Optional[Any]   			=  self.dummy_vqvae_and_unet
         _lowercase:      Dict   			=  AudioDiffusionPipeline(
             vqvae=self.dummy_vqvae_and_unet[0]			,					unet=dummy_vqvae_and_unet[1]			,					mel=A_			,					scheduler=A_							)
         _lowercase:      int   			=  pipe.to(A_							)
         pipe.set_progress_bar_config(disable=A_							)

         np.random.seed(0							)
         _lowercase:      Optional[Any]   			=  np.random.uniform(-1			,					1			,					((dummy_vqvae_and_unet[0].config.sample_size[1] - 1) * mel.hop_length,)							)
         _lowercase:      Union[str, Any]   			=  torch.Generator(device=A_							).manual_seed(42							)
         _lowercase:      List[Any]   			=  pipe(raw_audio=A_			,					generator=A_			,					start_step=5			,					steps=10							)
         _lowercase:      Optional[Any]   			=  output.images[0]

         assert (
             image.height == self.dummy_vqvae_and_unet[0].config.sample_size[0]
             and image.width == self.dummy_vqvae_and_unet[0].config.sample_size[1]
         )
         _lowercase:      List[Any]   			=  np.frombuffer(image.tobytes()			,					dtype='''uint8'''							)[:10]
         _lowercase:      Optional[int]   			=  np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121]							)

         assert np.abs(image_slice.flatten() - expected_slice							).max() == 0

         _lowercase:      Union[str, Any]   			=  self.dummy_unet_condition
         _lowercase:      str   			=  AudioDiffusionPipeline(
             vqvae=self.dummy_vqvae_and_unet[0]			,					unet=A_			,					mel=A_			,					scheduler=A_							)
         _lowercase:      Union[str, Any]   			=  pipe.to(A_							)
         pipe.set_progress_bar_config(disable=A_							)

         np.random.seed(0							)
         _lowercase:      Union[str, Any]   			=  torch.rand((1, 1, 10)							)
         _lowercase:      Optional[Any]   			=  pipe(generator=A_			,					encoding=A_							)
         _lowercase:      str   			=  output.images[0]
         _lowercase:      Dict   			=  np.frombuffer(image.tobytes()			,					dtype='''uint8'''							)[:10]
         _lowercase:      Any   			=  np.array([107, 103, 120, 127, 142, 122, 113, 122, 97, 111]							)

         assert np.abs(image_slice.flatten() - expected_slice							).max() == 0


@slow
@require_torch_gpu
class       __magic_name__							(							unittest.TestCase			):
       def 				lowercase_				(  self							)  ->						Optional[int]:





         """simple docstring"""




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



       def 				lowercase_				(  self							)  ->						Optional[Any]:





         """simple docstring"""




         _lowercase:      Dict   			=  torch_device

         _lowercase:      List[Any]   			=  DiffusionPipeline.from_pretrained('''teticio/audio-diffusion-ddim-256'''							)
         _lowercase:      Dict   			=  pipe.to(A_							)
         pipe.set_progress_bar_config(disable=A_							)

         _lowercase:      Tuple   			=  torch.Generator(device=A_							).manual_seed(42							)
         _lowercase:      Union[str, Any]   			=  pipe(generator=A_							)
         _lowercase:      str   			=  output.audios[0]
         _lowercase:      Union[str, Any]   			=  output.images[0]

         assert audio.shape == (1, (pipe.unet.config.sample_size[1] - 1) * pipe.mel.hop_length)
         assert image.height == pipe.unet.config.sample_size[0] and image.width == pipe.unet.config.sample_size[1]
         _lowercase:      Union[str, Any]   			=  np.frombuffer(image.tobytes()			,					dtype='''uint8'''							)[:10]
         _lowercase:      Union[str, Any]   			=  np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26]							)

         assert np.abs(image_slice.flatten() - expected_slice							).max() == 0


"""simple docstring"""




from __future__ import annotations

import typing
from collections import Counter




def 			_lowerCAmelCase		(		_UpperCamelCase    ):






  """simple docstring"""



  _lowercase:      typing.Counter[int]   			=  Counter()
  for base in range(1			,					max_perimeter + 1    ):
    for perpendicular in range(_UpperCamelCase			,					max_perimeter + 1    ):
      _lowercase:      str   			=  (base * base + perpendicular * perpendicular) ** 0.5
      if hypotenuse == int(_UpperCamelCase    ):
        _lowercase:      str   			=  int(base + perpendicular + hypotenuse    )
        if perimeter > max_perimeter:
          continue
        triplets[perimeter] += 1
  return triplets




def 			_lowerCAmelCase		(		_UpperCamelCase = 1_000    ):






  """simple docstring"""



  _lowercase:      int   			=  pythagorean_triple(_UpperCamelCase    )
  return triplets.most_common(1    )[0][0]


if __name__ == "__main__":
  print(f"""Perimeter {solution()} has maximum solutions""")
