

import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()
class  _A		(  unittest.TestCase):

  @property
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        torch.manual_seed(0					)
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     UNetaDModel(
            block_out_channels=(32, 64) ,					layers_per_block=2 ,					sample_size=32 ,					in_channels=3 ,					out_channels=3 ,					down_block_types=('DownBlock2D', 'AttnDownBlock2D') ,					up_block_types=('AttnUpBlock2D', 'UpBlock2D') ,					)
        return model



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     self.dummy_uncond_unet
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     KarrasVeScheduler()

        SCREAMING_SNAKE_CASE_				:  str           =     KarrasVePipeline(unet=_SCREAMING_SNAKE_CASE ,					scheduler=_SCREAMING_SNAKE_CASE					)
        pipe.to(_SCREAMING_SNAKE_CASE					)
        pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     torch.manual_seed(0					)
        SCREAMING_SNAKE_CASE_				:  str           =     pipe(num_inference_steps=2 ,					generator=_SCREAMING_SNAKE_CASE ,					output_type='numpy'					).images

        SCREAMING_SNAKE_CASE_				:  Tuple           =     torch.manual_seed(0					)
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     pipe(num_inference_steps=2 ,					generator=_SCREAMING_SNAKE_CASE ,					output_type='numpy' ,					return_dict=_SCREAMING_SNAKE_CASE					)[0]

        SCREAMING_SNAKE_CASE_				:  Tuple           =     image[0, -3:, -3:, -1]
        SCREAMING_SNAKE_CASE_				:  int           =     image_from_tuple[0, -3:, -3:, -1]

        assert image.shape == (1, 32, 32, 3)
        SCREAMING_SNAKE_CASE_				:  Any           =     np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]					)

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

@slow
@require_torch
class  _A		(  unittest.TestCase):

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     'google/ncsnpp-celebahq-256'
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     UNetaDModel.from_pretrained(_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Tuple           =     KarrasVeScheduler()

        SCREAMING_SNAKE_CASE_				:  List[str]           =     KarrasVePipeline(unet=_SCREAMING_SNAKE_CASE ,					scheduler=_SCREAMING_SNAKE_CASE					)
        pipe.to(_SCREAMING_SNAKE_CASE					)
        pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  Any           =     torch.manual_seed(0					)
        SCREAMING_SNAKE_CASE_				:  int           =     pipe(num_inference_steps=20 ,					generator=_SCREAMING_SNAKE_CASE ,					output_type='numpy'					).images

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     image[0, -3:, -3:, -1]
        assert image.shape == (1, 256, 256, 3)
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]					)

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









def    A_  (							a  ):

      """simple docstring"""



      if upper_limit < 0:
            raise ValueError('Limit for the Catalan sequence must be ≥ 0'  )

      SCREAMING_SNAKE_CASE_				:  List[str]           =     [0] * (upper_limit + 1)

      # Base case: C(0) = C(1) = 1
      SCREAMING_SNAKE_CASE_				:  Any           =     1
      if upper_limit > 0:
            SCREAMING_SNAKE_CASE_				:  int           =     1

      # Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i
      for i in range(2					,   upper_limit + 1  ):
            for j in range(a  ):
                  catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1]

      return catalan_list


if __name__ == "__main__":
    print('\n********* Catalan Numbers Using Dynamic Programming ************\n')
    print('\n*** Enter -1 at any time to quit ***')
    print('\nEnter the upper limit (≥ 0) for the Catalan number sequence: ', end='')
    try:
        while True:
            lowerCAmelCase     :   Union[str, Any]						     =  int(input().strip())
            if N < 0:
                print('\n********* Goodbye!! ************')
                break
            else:
                print(F'The Catalan numbers from 0 through {N} are:')
                print(catalan_numbers(N))
                print('Try another upper limit for the sequence: ', end='')
    except (NameError, ValueError):
        print('\n********* Invalid input, goodbye! ************\n')

    import doctest

    doctest.testmod()






