

'''simple docstring'''

import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()






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






				"""simple docstring"""



				def   a__					(    self       )     ->							Dict:
											# clean up the VRAM after each test
											super().tearDown()
											gc.collect()
											torch.cuda.empty_cache()



				def   a__					(    self       )     ->							List[Any]:
											SCREAMING_SNAKE_CASE_				=				StableDiffusionKDiffusionPipeline.from_pretrained('CompVis/stable-diffusion-v1-4'       )
											SCREAMING_SNAKE_CASE_				=				sd_pipe.to(_lowercase       )
											sd_pipe.set_progress_bar_config(disable=_lowercase       )

											sd_pipe.set_scheduler('sample_euler'       )

											SCREAMING_SNAKE_CASE_				=				'A painting of a squirrel eating a burger'
											SCREAMING_SNAKE_CASE_				=				torch.manual_seed(0       )
											SCREAMING_SNAKE_CASE_				=				sd_pipe([prompt],     generator=_lowercase,     guidance_scale=9.0,     num_inference_steps=20,     output_type='np'       )

											SCREAMING_SNAKE_CASE_				=				output.images

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

											assert image.shape == (1, 512, 512, 3)
											SCREAMING_SNAKE_CASE_				=				np.array([0.0_447, 0.0_492, 0.0_468, 0.0_408, 0.0_383, 0.0_408, 0.0_354, 0.0_380, 0.0_339]       )

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



				def   a__					(    self       )     ->							Union[str, Any]:
											SCREAMING_SNAKE_CASE_				=				StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'       )
											SCREAMING_SNAKE_CASE_				=				sd_pipe.to(_lowercase       )
											sd_pipe.set_progress_bar_config(disable=_lowercase       )

											sd_pipe.set_scheduler('sample_euler'       )

											SCREAMING_SNAKE_CASE_				=				'A painting of a squirrel eating a burger'
											SCREAMING_SNAKE_CASE_				=				torch.manual_seed(0       )
											SCREAMING_SNAKE_CASE_				=				sd_pipe([prompt],     generator=_lowercase,     guidance_scale=9.0,     num_inference_steps=20,     output_type='np'       )

											SCREAMING_SNAKE_CASE_				=				output.images

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

											assert image.shape == (1, 512, 512, 3)
											SCREAMING_SNAKE_CASE_				=				np.array([0.1_237, 0.1_320, 0.1_438, 0.1_359, 0.1_390, 0.1_132, 0.1_277, 0.1_175, 0.1_112]       )

											assert np.abs(image_slice.flatten() - expected_slice       ).max() < 5E-1





				def   a__					(    self       )     ->							Tuple:
											SCREAMING_SNAKE_CASE_				=				StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'       )
											SCREAMING_SNAKE_CASE_				=				sd_pipe.to(_lowercase       )
											sd_pipe.set_progress_bar_config(disable=_lowercase       )

											sd_pipe.set_scheduler('sample_dpmpp_2m'       )

											SCREAMING_SNAKE_CASE_				=				'A painting of a squirrel eating a burger'
											SCREAMING_SNAKE_CASE_				=				torch.manual_seed(0       )
											SCREAMING_SNAKE_CASE_				=				sd_pipe(
											    [prompt],     generator=_lowercase,     guidance_scale=7.5,     num_inference_steps=15,     output_type='np',     use_karras_sigmas=_lowercase,     )

											SCREAMING_SNAKE_CASE_				=				output.images

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

											assert image.shape == (1, 512, 512, 3)
											SCREAMING_SNAKE_CASE_				=				np.array(
											    [0.11_381_689, 0.12_112_921, 0.1_389_457, 0.12_549_606, 0.1_244_964, 0.10_831_517, 0.11_562_866, 0.10_867_816, 0.10_499_048]       )

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








'''simple docstring'''

def 							_UpperCamelCase				(   lowerCAmelCase__:					str   )      -> bool:
							return credit_card_number.startswith(('34', '35', '37', '4', '5', '6')   )




def 							_UpperCamelCase				(   lowerCAmelCase__:					str   )      -> bool:
							SCREAMING_SNAKE_CASE_				=				credit_card_number
							SCREAMING_SNAKE_CASE_				=				0
							SCREAMING_SNAKE_CASE_				=				len(lowerCAmelCase__   ) - 2
							for i in range(lowerCAmelCase__		,-1		,-2   ):
														#  double the value of every second digit
														SCREAMING_SNAKE_CASE_				=				int(cc_number[i]   )
														digit *= 2
														# If doubling of a number results in a two digit number
														# i.e greater than 9(e.g., 6 × 2 = 12),
														# then add the digits of the product (e.g., 12: 1 + 2 = 3, 15: 1 + 5 = 6),
														# to get a single digit number.
														if digit > 9:
																					digit %= 10
																					digit += 1
														SCREAMING_SNAKE_CASE_				=				cc_number[:i] + str(lowerCAmelCase__   ) + cc_number[i + 1 :]
														total += digit

							# Sum up the remaining digits
							for i in range(len(lowerCAmelCase__   ) - 1		,-1		,-2   ):
														total += int(cc_number[i]   )

							return total % 10 == 0




def 							_UpperCamelCase				(   lowerCAmelCase__:					str   )      -> bool:
							SCREAMING_SNAKE_CASE_				=				F"""{credit_card_number} is an invalid credit card number because"""
							if not credit_card_number.isdigit():
														print(F"""{error_message} it has nonnumerical characters."""   )
														return False

							if not 13 <= len(lowerCAmelCase__   ) <= 16:
														print(F"""{error_message} of its length."""   )
														return False

							if not validate_initial_digits(lowerCAmelCase__   ):
														print(F"""{error_message} of its first two digits."""   )
														return False

							if not luhn_validation(lowerCAmelCase__   ):
														print(F"""{error_message} it fails the Luhn check."""   )
														return False

							print(F"""{credit_card_number} is a valid credit card number."""   )
							return True


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							validate_credit_card_number("4111111111111111")
							validate_credit_card_number("32323")





