




import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel

from diffusers import DDIMScheduler, LDMPipeline, UNetaDModel, VQModel
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  lowercase_       ( self				)       -> List[str]:



							'''simple docstring'''
							torch.manual_seed(0				)
							__lowerCamelCase									=       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


			@property
			def  lowercase_       ( self				)       -> Tuple:



							'''simple docstring'''
							torch.manual_seed(0				)
							__lowerCamelCase									=       VQModel(
							    block_out_channels=[32, 64]     ,		in_channels=3     ,		out_channels=3     ,		down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']     ,		up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']     ,		latent_channels=3     ,		)
							return model


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



							'''simple docstring'''
							torch.manual_seed(0				)
							__lowerCamelCase									=       CLIPTextConfig(
							    bos_token_id=0     ,		eos_token_id=2     ,		hidden_size=32     ,		intermediate_size=37     ,		layer_norm_eps=1e-05     ,		num_attention_heads=4     ,		num_hidden_layers=5     ,		pad_token_id=1     ,		vocab_size=1_000     ,		)
							return CLIPTextModel(lowerCamelCase__				)






			def  lowercase_       ( self				)       -> int:



							'''simple docstring'''
							__lowerCamelCase									=       self.dummy_uncond_unet
							__lowerCamelCase									=       DDIMScheduler()
							__lowerCamelCase									=       self.dummy_vq_model

							__lowerCamelCase									=       LDMPipeline(unet=lowerCamelCase__     ,		vqvae=lowerCamelCase__     ,		scheduler=lowerCamelCase__				)
							ldm.to(lowerCamelCase__				)
							ldm.set_progress_bar_config(disable=lowerCamelCase__				)

							__lowerCamelCase									=       torch.manual_seed(0				)
							__lowerCamelCase									=       ldm(generator=lowerCamelCase__     ,		num_inference_steps=2     ,		output_type='numpy'				).images

							__lowerCamelCase									=       torch.manual_seed(0				)
							__lowerCamelCase									=       ldm(generator=lowerCamelCase__     ,		num_inference_steps=2     ,		output_type='numpy'     ,		return_dict=lowerCamelCase__				)[0]

							__lowerCamelCase									=       image[0, -3:, -3:, -1]
							__lowerCamelCase									=       image_from_tuple[0, -3:, -3:, -1]

							assert image.shape == (1, 64, 64, 3)
							__lowerCamelCase									=       np.array([0.85_12, 0.8_18, 0.64_11, 0.68_08, 0.44_65, 0.56_18, 0.46, 0.62_31, 0.51_72]				)
							__lowerCamelCase									=       1e-2 if torch_device != 'mps' else 3e-2

							assert np.abs(image_slice.flatten() - expected_slice				).max() < tolerance
							assert np.abs(image_from_tuple_slice.flatten() - expected_slice				).max() < tolerance







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

			"""simple docstring"""







			def  lowercase_       ( self				)       -> Tuple:



							'''simple docstring'''
							__lowerCamelCase									=       LDMPipeline.from_pretrained('CompVis/ldm-celebahq-256'				)
							ldm.to(lowerCamelCase__				)
							ldm.set_progress_bar_config(disable=lowerCamelCase__				)

							__lowerCamelCase									=       torch.manual_seed(0				)
							__lowerCamelCase									=       ldm(generator=lowerCamelCase__     ,		num_inference_steps=5     ,		output_type='numpy'				).images

							__lowerCamelCase									=       image[0, -3:, -3:, -1]

							assert image.shape == (1, 256, 256, 3)
							__lowerCamelCase									=       np.array([0.43_99, 0.4_49_75, 0.4_68_25, 0.4_74, 0.43_59, 0.45_81, 0.4_50_95, 0.43_41, 0.44_47]				)
							__lowerCamelCase									=       1e-2 if torch_device != 'mps' else 3e-2

							assert np.abs(image_slice.flatten() - expected_slice				).max() < tolerance








from string import ascii_uppercase

__A								=       {str(ord(c) - 55): c for c in ascii_uppercase}







def      lowerCamelCase_						(			UpperCamelCase__							: int					,	UpperCamelCase__							: int )	->			str:





				"""simple docstring"""


				if isinstance(UpperCamelCase__					,	UpperCamelCase__ ):
								raise TypeError('int() can\'t convert non-string with explicit base' )
				if num < 0:
								raise ValueError('parameter must be positive int' )
				if isinstance(UpperCamelCase__					,	UpperCamelCase__ ):
								raise TypeError('\'str\' object cannot be interpreted as an integer' )
				if isinstance(UpperCamelCase__					,	UpperCamelCase__ ):
								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' )
				__lowerCamelCase									=       ''
				__lowerCamelCase									=       0
				__lowerCamelCase									=       0
				while div != 1:
								__lowerCamelCase			,		__lowerCamelCase									=       divmod(UpperCamelCase__					,	UpperCamelCase__ )
								if base >= 11 and 9 < mod < 36:
												__lowerCamelCase									=       ALPHABET_VALUES[str(UpperCamelCase__ )]
								else:
												__lowerCamelCase									=       str(UpperCamelCase__ )
								new_value += actual_value
								__lowerCamelCase									=       num // base
								__lowerCamelCase									=       div
								if div == 0:
												return str(new_value[::-1] )
								elif div == 1:
												new_value += str(UpperCamelCase__ )
												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(10_00):
															assert int(decimal_to_any(num, base), base) == num, (
															    num,
															    base,
															    decimal_to_any(num, base),
															    int(decimal_to_any(num, base), base),
															)


