





"""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     __lowerCAmelCase	(   unittest.TestCase):







      def        _lowercase  (   self							)       ->						int:



        '''simple docstring'''




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







      @property
      def        _lowercase  (   self							)       ->						Optional[Any]:



        '''simple docstring'''




        torch.manual_seed(0							)
        a__     : List[Any]  =UNetaDModel(
            sample_size=(3_2, 6_4)		,				in_channels=1		,				out_channels=1		,				layers_per_block=2		,				block_out_channels=(1_2_8, 1_2_8)		,				down_block_types=("AttnDownBlock2D", "DownBlock2D")		,				up_block_types=("UpBlock2D", "AttnUpBlock2D")		,				)
        return model







      @property
      def        _lowercase  (   self							)       ->						Dict:



        '''simple docstring'''




        torch.manual_seed(0							)
        a__     : Tuple  =UNetaDConditionModel(
            sample_size=(6_4, 3_2)		,				in_channels=1		,				out_channels=1		,				layers_per_block=2		,				block_out_channels=(1_2_8, 1_2_8)		,				down_block_types=("CrossAttnDownBlock2D", "DownBlock2D")		,				up_block_types=("UpBlock2D", "CrossAttnUpBlock2D")		,				cross_attention_dim=1_0		,				)
        return model







      @property
      def        _lowercase  (   self							)       ->						Optional[Any]:



        '''simple docstring'''




        torch.manual_seed(0							)
        a__     : int  =AutoencoderKL(
            sample_size=(1_2_8, 6_4)		,				in_channels=1		,				out_channels=1		,				latent_channels=1		,				layers_per_block=2		,				block_out_channels=(1_2_8, 1_2_8)		,				down_block_types=("DownEncoderBlock2D", "DownEncoderBlock2D")		,				up_block_types=("UpDecoderBlock2D", "UpDecoderBlock2D")		,				)
        a__     : Tuple  =UNetaDModel(
            sample_size=(6_4, 3_2)		,				in_channels=1		,				out_channels=1		,				layers_per_block=2		,				block_out_channels=(1_2_8, 1_2_8)		,				down_block_types=("AttnDownBlock2D", "DownBlock2D")		,				up_block_types=("UpBlock2D", "AttnUpBlock2D")		,				)
        return vqvae, unet







      @slow
      def        _lowercase  (   self							)       ->						List[Any]:



        '''simple docstring'''




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

        a__     : str  =DDPMScheduler()
        a__     : Tuple  =AudioDiffusionPipeline(vqvae=lowerCAmelCase__		,				unet=self.dummy_unet		,				mel=lowerCAmelCase__		,				scheduler=lowerCAmelCase__							)
        a__     : Any  =pipe.to(lowerCAmelCase__							)
        pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

        a__     : Optional[Any]  =torch.Generator(device=lowerCAmelCase__							).manual_seed(4_2							)
        a__     : Tuple  =pipe(generator=lowerCAmelCase__		,				steps=4							)
        a__     : Any  =output.audios[0]
        a__     : Tuple  =output.images[0]

        a__     : Tuple  =torch.Generator(device=lowerCAmelCase__							).manual_seed(4_2							)
        a__     : Tuple  =pipe(generator=lowerCAmelCase__		,				steps=4		,				return_dict=lowerCAmelCase__							)
        a__     : List[str]  =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]
        )
        a__     : List[Any]  =np.frombuffer(image.tobytes()		,				dtype="uint8"							)[:1_0]
        a__     : Dict  =np.frombuffer(image_from_tuple.tobytes()		,				dtype="uint8"							)[:1_0]
        a__     : Any  =np.array([6_9, 2_5_5, 2_5_5, 2_5_5, 0, 0, 7_7, 1_8_1, 1_2, 1_2_7]							)

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

        a__     : List[str]  =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]		,				)

        a__     : Tuple  =DDIMScheduler()
        a__     : str  =self.dummy_vqvae_and_unet
        a__     : int  =AudioDiffusionPipeline(
            vqvae=self.dummy_vqvae_and_unet[0]		,				unet=dummy_vqvae_and_unet[1]		,				mel=lowerCAmelCase__		,				scheduler=lowerCAmelCase__							)
        a__     : Optional[int]  =pipe.to(lowerCAmelCase__							)
        pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

        np.random.seed(0							)
        a__     : Any  =np.random.uniform(-1		,				1		,				((dummy_vqvae_and_unet[0].config.sample_size[1] - 1) * mel.hop_length,)							)
        a__     : Dict  =torch.Generator(device=lowerCAmelCase__							).manual_seed(4_2							)
        a__     : Dict  =pipe(raw_audio=lowerCAmelCase__		,				generator=lowerCAmelCase__		,				start_step=5		,				steps=1_0							)
        a__     : 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]
        )
        a__     : Optional[Any]  =np.frombuffer(image.tobytes()		,				dtype="uint8"							)[:1_0]
        a__     : Tuple  =np.array([1_2_0, 1_1_7, 1_1_0, 1_0_9, 1_3_8, 1_6_7, 1_3_8, 1_4_8, 1_3_2, 1_2_1]							)

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

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

        np.random.seed(0							)
        a__     : Optional[int]  =torch.rand((1, 1, 1_0)							)
        a__     : Tuple  =pipe(generator=lowerCAmelCase__		,				encoding=lowerCAmelCase__							)
        a__     : Optional[Any]  =output.images[0]
        a__     : List[str]  =np.frombuffer(image.tobytes()		,				dtype="uint8"							)[:1_0]
        a__     : Dict  =np.array([1_0_7, 1_0_3, 1_2_0, 1_2_7, 1_4_2, 1_2_2, 1_1_3, 1_2_2, 9_7, 1_1_1]							)

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







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







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



        '''simple docstring'''




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







      def        _lowercase  (   self							)       ->						Tuple:



        '''simple docstring'''




        a__     : List[str]  =torch_device

        a__     : List[Any]  =DiffusionPipeline.from_pretrained("teticio/audio-diffusion-ddim-256"							)
        a__     : Tuple  =pipe.to(lowerCAmelCase__							)
        pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

        a__     : Any  =torch.Generator(device=lowerCAmelCase__							).manual_seed(4_2							)
        a__     : str  =pipe(generator=lowerCAmelCase__							)
        a__     : Union[str, Any]  =output.audios[0]
        a__     : 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]
        a__     : int  =np.frombuffer(image.tobytes()		,				dtype="uint8"							)[:1_0]
        a__     : str  =np.array([1_5_1, 1_6_7, 1_5_4, 1_4_4, 1_2_2, 1_3_4, 1_2_1, 1_0_5, 7_0, 2_6]							)

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













from __future__ import annotations

import math
def 					_A	(		SCREAMING_SNAKE_CASE					:       int						):





  """simple docstring"""



  if num <= 0:
    a__     : List[str]  =f'''{num}: Invalid input, please enter a positive integer.'''
    raise ValueError(SCREAMING_SNAKE_CASE						)

  a__     : Union[str, Any]  =[True] * (num + 1)
  a__     : Union[str, Any]  =[]
  a__     : str  =2
  a__     : Any  =int(math.sqrt(SCREAMING_SNAKE_CASE						)						)

  while start <= end:
    # If start is a prime
    if sieve[start] is True:
      prime.append(SCREAMING_SNAKE_CASE						)

      # Set multiples of start be False
      for i in range(start * start	,	num + 1	,	SCREAMING_SNAKE_CASE						):
        if sieve[i] is True:
          a__     : Optional[int]  =False

    start += 1

  for j in range(end + 1	,	num + 1						):
    if sieve[j] is True:
      prime.append(SCREAMING_SNAKE_CASE						)

  return prime


if __name__ == "__main__":
     print(prime_sieve(int(input("""Enter a positive integer: """).strip())))






