






import unittest

import numpy as np
import torch

from diffusers import PNDMPipeline, PNDMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()

class        lowerCAmelCase_				(      unittest.TestCase	):







				"""simple docstring"""




				@property
				def 				__a   ( self     :int     ):
					torch.manual_seed(0     )
					UpperCamelCase__ :Optional[int]						=      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 				__a   ( self     :Optional[int]     ):
					UpperCamelCase__ :Optional[Any]						=      self.dummy_uncond_unet
					UpperCamelCase__ :List[str]						=      PNDMScheduler()

					UpperCamelCase__ :Union[str, Any]						=      PNDMPipeline(unet=lowerCamelCase__  ,     scheduler=lowerCamelCase__     )
					pndm.to(lowerCamelCase__     )
					pndm.set_progress_bar_config(disable=lowerCamelCase__     )

					UpperCamelCase__ :List[Any]						=      torch.manual_seed(0     )
					UpperCamelCase__ :List[Any]						=      pndm(generator=lowerCamelCase__  ,     num_inference_steps=20  ,     output_type="""numpy"""     ).images

					UpperCamelCase__ :Tuple						=      torch.manual_seed(0     )
					UpperCamelCase__ :Tuple						=      pndm(generator=lowerCamelCase__  ,     num_inference_steps=20  ,     output_type="""numpy"""  ,     return_dict=lowerCamelCase__     )[0]

					UpperCamelCase__ :Optional[Any]						=      image[0, -3:, -3:, -1]
					UpperCamelCase__ :Dict						=      image_from_tuple[0, -3:, -3:, -1]

					assert image.shape == (1, 32, 32, 3)
					UpperCamelCase__ :Optional[Any]						=      np.array([1.0, 1.0, 0.0, 1.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        lowerCAmelCase_				(      unittest.TestCase	):







				"""simple docstring"""




				def 				__a   ( self     :Dict     ):
					UpperCamelCase__ :Tuple						=      """google/ddpm-cifar10-32"""

					UpperCamelCase__ :Optional[Any]						=      UNetaDModel.from_pretrained(lowerCamelCase__     )
					UpperCamelCase__ :Dict						=      PNDMScheduler()

					UpperCamelCase__ :Union[str, Any]						=      PNDMPipeline(unet=lowerCamelCase__  ,     scheduler=lowerCamelCase__     )
					pndm.to(lowerCamelCase__     )
					pndm.set_progress_bar_config(disable=lowerCamelCase__     )
					UpperCamelCase__ :int						=      torch.manual_seed(0     )
					UpperCamelCase__ :Tuple						=      pndm(generator=lowerCamelCase__  ,     output_type="""numpy"""     ).images

					UpperCamelCase__ :str						=      image[0, -3:, -3:, -1]

					assert image.shape == (1, 32, 32, 3)
					UpperCamelCase__ :Dict						=      np.array([0.1564, 0.1_4645, 0.1406, 0.1_4715, 0.1_2425, 0.1_4045, 0.1_3115, 0.1_2175, 0.125]     )

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






'''simple docstring'''

from string import ascii_uppercase

__lowerCAmelCase				:      Union[str, Any]						      ={str(ord(c) - 55): c for c in ascii_uppercase}





def 		UpperCamelCase							(				_lowerCamelCase   :   int		,			_lowerCamelCase   :   int			):
    if isinstance(_lowerCamelCase		,			_lowerCamelCase			):
        raise TypeError("int() can't convert non-string with explicit base"			)
    if num < 0:
        raise ValueError("parameter must be positive int"			)
    if isinstance(_lowerCamelCase		,			_lowerCamelCase			):
        raise TypeError("'str' object cannot be interpreted as an integer"			)
    if isinstance(_lowerCamelCase		,			_lowerCamelCase			):
        raise TypeError("'float' object cannot be interpreted as an integer"			)
    if base in (0, 1):
        raise ValueError("base must be >= 2"			)
    if base > 36:
        raise ValueError("base must be <= 36"			)
    A__							=     ""
    A__							=     0
    A__							=     0
    while div != 1:
        A__,      A__							=     divmod(_lowerCamelCase		,			_lowerCamelCase			)
        if base >= 11 and 9 < mod < 36:
            A__							=     ALPHABET_VALUES[str(_lowerCamelCase			)]
        else:
            A__							=     str(_lowerCamelCase			)
        new_value += actual_value
        A__							=     num // base
        A__							=     div
        if div == 0:
            return str(new_value[::-1]			)
        elif div == 1:
            new_value += str(_lowerCamelCase			)
            return str(new_value[::-1]			)

    return new_value[::-1]


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  for base in range(2, 37):
    for num in range(1000):
      assert int(decimal_to_any(num, base), base) == num, (
          num,
          base,
          decimal_to_any(num, base),
          int(decimal_to_any(num, base), base),
      )



