code: 
  
  
  '''simple docstring'''
  
  import gc
  import random
  import unittest
  
  import numpy as np
  import torch
  from PIL import Image
  from transformers import CLIPImageProcessor, CLIPVisionConfig
  
  from diffusers import AutoencoderKL, PaintByExamplePipeline, PNDMScheduler, UNetaDConditionModel
  from diffusers.pipelines.paint_by_example import PaintByExampleImageEncoder
  from diffusers.utils import floats_tensor, load_image, slow, torch_device
  from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu
  
  from ..pipeline_params import IMAGE_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, IMAGE_GUIDED_IMAGE_INPAINTING_PARAMS
  from ..test_pipelines_common import PipelineTesterMixin
  
  
  enable_full_determinism()
  class _lowerCamelCase (		lowercase__	,  unittest.TestCase							):
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		A_			:    List[str]   					=       PaintByExamplePipeline
  		A_			:    Optional[int]   					=       IMAGE_GUIDED_IMAGE_INPAINTING_PARAMS
  		A_			:    Union[str, Any]   					=       IMAGE_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
  		A_			:    Dict   					=       frozenset([]							)  # TO_DO: update the image_prams once refactored VaeImageProcessor.preprocess
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[str]    )						->				Any:
  			torch.manual_seed(0    )
  			__magic_name__ :					Optional[Any]  			=  UNetaDConditionModel(
  			    block_out_channels=(32, 64)						,  layers_per_block=2						,  sample_size=32						,  in_channels=9						,  out_channels=4						,  down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')						,  up_block_types=('CrossAttnUpBlock2D', 'UpBlock2D')						,  cross_attention_dim=32						,  )
  			__magic_name__ :					Tuple  			=  PNDMScheduler(skip_prk_steps=_A    )
  			torch.manual_seed(0    )
  			__magic_name__ :					Optional[int]  			=  AutoencoderKL(
  			    block_out_channels=[32, 64]						,  in_channels=3						,  out_channels=3						,  down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']						,  up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']						,  latent_channels=4						,  )
  			torch.manual_seed(0    )
  			__magic_name__ :					Tuple  			=  CLIPVisionConfig(
  			    hidden_size=32						,  projection_dim=32						,  intermediate_size=37						,  layer_norm_eps=1E-05						,  num_attention_heads=4						,  num_hidden_layers=5						,  image_size=32						,  patch_size=4						,  )
  			__magic_name__ :					int  			=  PaintByExampleImageEncoder(_A						,  proj_size=32    )
  			__magic_name__ :					Optional[int]  			=  CLIPImageProcessor(crop_size=32						,  size=32    )
  
  			__magic_name__ :					Optional[int]  			=  {
  			    'unet': unet,
  			    'scheduler': scheduler,
  			    'vae': vae,
  			    'image_encoder': image_encoder,
  			    'safety_checker': None,
  			    'feature_extractor': feature_extractor,
  			}
  			return components
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Any						,  _A	:		Tuple    )						->				Dict:
  			__magic_name__ :					Any  			=  np.array(image.convert('RGB'    )    )
  			__magic_name__ :					List[Any]  			=  image[None].transpose(0						,  3						,  1						,  2    )
  			__magic_name__ :					Any  			=  torch.from_numpy(_A    ).to(dtype=torch.floataa    ) / 127.5 - 1.0
  			return image
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[str]						,  _A	:		List[str]="cpu"						,  _A	:		Tuple=0    )						->				List[Any]:
  			# TODO: use tensor inputs instead of PIL, this is here just to leave the old expected_slices untouched
  			__magic_name__ :					Optional[Any]  			=  floats_tensor((1, 3, 32, 32)						,  rng=random.Random(_A    )    ).to(_A    )
  			__magic_name__ :					Tuple  			=  image.cpu().permute(0						,  2						,  3						,  1    )[0]
  			__magic_name__ :					int  			=  Image.fromarray(np.uinta(_A    )    ).convert('RGB'    ).resize((64, 64)    )
  			__magic_name__ :					str  			=  Image.fromarray(np.uinta(image + 4    )    ).convert('RGB'    ).resize((64, 64)    )
  			__magic_name__ :					Dict  			=  Image.fromarray(np.uinta(_A    )    ).convert('RGB'    ).resize((32, 32)    )
  
  			if str(_A    ).startswith('mps'    ):
  				__magic_name__ :					List[str]  			=  torch.manual_seed(_A    )
  			else:
  				__magic_name__ :					List[Any]  			=  torch.Generator(device=_A    ).manual_seed(_A    )
  			__magic_name__ :					Union[str, Any]  			=  {
  			    'example_image': example_image,
  			    'image': init_image,
  			    'mask_image': mask_image,
  			    'generator': generator,
  			    'num_inference_steps': 2,
  			    'guidance_scale': 6.0,
  			    'output_type': 'numpy',
  			}
  			return inputs
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		str    )						->				Optional[Any]:
  			__magic_name__ :					Optional[int]  			=  self.get_dummy_components()
  
  			# make sure here that pndm scheduler skips prk
  			__magic_name__ :					str  			=  PaintByExamplePipeline(**_A    )
  			__magic_name__ :					Optional[int]  			=  pipe.to('cpu'    )
  			pipe.set_progress_bar_config(disable=_A    )
  
  			__magic_name__ :					Optional[int]  			=  self.get_dummy_inputs()
  			__magic_name__ :					str  			=  pipe(**_A    )
  			__magic_name__ :					List[Any]  			=  output.images
  
  			__magic_name__ :					str  			=  image[0, -3:, -3:, -1]
  
  			assert image.shape == (1, 64, 64, 3)
  			__magic_name__ :					Tuple  			=  np.array([0.4686, 0.5687, 0.4007, 0.5218, 0.5741, 0.4482, 0.4940, 0.4629, 0.4503]    )
  
  			assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1E-2
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[Any]    )						->				str:
  			__magic_name__ :					Union[str, Any]  			=  'cpu'
  			__magic_name__ :					List[str]  			=  self.get_dummy_inputs()
  			inputs.pop('mask_image'    )
  			__magic_name__ :					int  			=  self.convert_to_pt(inputs.pop('image'    )    )
  			__magic_name__ :					Optional[Any]  			=  image.clamp(0						,  1    ) / 2
  
  			# make sure here that pndm scheduler skips prk
  			__magic_name__ :					Union[str, Any]  			=  PaintByExamplePipeline(**self.get_dummy_components()    )
  			__magic_name__ :					List[str]  			=  pipe.to(_A    )
  			pipe.set_progress_bar_config(disable=_A    )
  
  			__magic_name__ :					Tuple  			=  pipe(image=_A						,  mask_image=mask_image[:, 0]						,  **_A    )
  			__magic_name__ :					Dict  			=  output.images
  
  			__magic_name__ :					Dict  			=  image.cpu().permute(0						,  2						,  3						,  1    )[0]
  			__magic_name__ :					Optional[Any]  			=  mask_image.cpu().permute(0						,  2						,  3						,  1    )[0]
  
  			__magic_name__ :					Tuple  			=  Image.fromarray(np.uinta(_A    )    ).convert('RGB'    )
  			__magic_name__ :					str  			=  Image.fromarray(np.uinta(_A    )    ).convert('RGB'    )
  
  			__magic_name__ :					Union[str, Any]  			=  pipe(**self.get_dummy_inputs()    )
  			__magic_name__ :					List[str]  			=  output.images
  
  			assert out_a.shape == (1, 64, 64, 3)
  			assert np.abs(out_a.flatten() - out_a.flatten()    ).max() < 5E-2
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[int]    )						->				Tuple:
  			super().test_inference_batch_single_identical(expected_max_diff=3E-3    )
  
  
  
  
  
  
  
  @slow
  @require_torch_gpu
  class _lowerCamelCase (		unittest.TestCase							):
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		int    )						->				str:
  			# clean up the VRAM after each test
  			super().tearDown()
  			gc.collect()
  			torch.cuda.empty_cache()
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[int]    )						->				Dict:
  			# make sure here that pndm scheduler skips prk
  			__magic_name__ :					Optional[Any]  			=  load_image(
  			    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
  			    '/paint_by_example/dog_in_bucket.png'    )
  			__magic_name__ :					List[Any]  			=  load_image(
  			    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
  			    '/paint_by_example/mask.png'    )
  			__magic_name__ :					Union[str, Any]  			=  load_image(
  			    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
  			    '/paint_by_example/panda.jpg'    )
  
  			__magic_name__ :					Union[str, Any]  			=  PaintByExamplePipeline.from_pretrained('Fantasy-Studio/Paint-by-Example'    )
  			__magic_name__ :					Tuple  			=  pipe.to(_A    )
  			pipe.set_progress_bar_config(disable=_A    )
  
  			__magic_name__ :					Optional[Any]  			=  torch.manual_seed(321    )
  			__magic_name__ :					Dict  			=  pipe(
  			    image=_A						,  mask_image=_A						,  example_image=_A						,  generator=_A						,  guidance_scale=5.0						,  num_inference_steps=50						,  output_type='np'						,  )
  
  			__magic_name__ :					Dict  			=  output.images
  
  			__magic_name__ :					Optional[int]  			=  image[0, -3:, -3:, -1]
  
  			assert image.shape == (1, 512, 512, 3)
  			__magic_name__ :					str  			=  np.array([0.4834, 0.4811, 0.4874, 0.5122, 0.5081, 0.5144, 0.5291, 0.5290, 0.5374]    )
  
  			assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1E-2
style_context: 
  
  
  '''simple docstring'''
  
  from .number_theory.prime_numbers import next_prime
  class _lowerCamelCase :
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def __init__(      self	:		Dict						,  _A	:		int						,  _A	:		int | None = None						,  _A	:		float | None = None						,  )						->				None:
  			__magic_name__ :					Optional[int]  			=  size_table
  			__magic_name__ :					int  			=  [None] * self.size_table
  			__magic_name__ :					int  			=  0.75 if lim_charge is None else lim_charge
  			__magic_name__ :					int  			=  1 if charge_factor is None else charge_factor
  			__magic_name__ :					list  			=  []
  			__magic_name__ :					dict  			=  {}
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[str]    )						->				str:
  			return self._keys
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Dict    )						->				Optional[Any]:
  			return sum(1 for slot in self.values if slot is not None    ) / (
  			    self.size_table * self.charge_factor
  			)
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		int						,  _A	:		int    )						->				List[Any]:
  			return key % self.size_table
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[Any]						,  _A	:		Tuple    )						->				Optional[int]:
  			print(F'step {step_ord}'    )
  			print(list(range(len(self.values    )    )    )    )
  			print(self.values    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		str						,  _A	:		Optional[Any]    )						->				Optional[int]:
  			__magic_name__ :					int  			=  1
  			__magic_name__ :					Optional[int]  			=  values
  			for value in values:
  				self.insert_data(_A    )
  				self._step_by_step(_A    )
  				i += 1
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[Any]						,  _A	:		List[str]						,  _A	:		List[Any]    )						->				Dict:
  			__magic_name__ :					str  			=  data
  			__magic_name__ :					Optional[int]  			=  data
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Union[str, Any]						,  _A	:		List[Any]						,  _A	:		Union[str, Any]=None    )						->				int:
  			__magic_name__ :					int  			=  self.hash_function(key + 1    )
  
  			while self.values[new_key] is not None and self.values[new_key] != key:
  				if self.values.count(_A    ) > 0:
  					__magic_name__ :					Dict  			=  self.hash_function(new_key + 1    )
  				else:
  					__magic_name__ :					Tuple  			=  None
  					break
  
  			return new_key
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[str]    )						->				Tuple:
  			__magic_name__ :					Dict  			=  [value for value in self.values if value is not None]
  			__magic_name__ :					int  			=  next_prime(self.size_table						,  factor=2    )
  			self._keys.clear()
  			__magic_name__ :					Tuple  			=  [None] * self.size_table  # hell's pointers D: don't DRY ;/
  			for value in survivor_values:
  				self.insert_data(_A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Tuple						,  _A	:		Union[str, Any]    )						->				Tuple:
  			__magic_name__ :					Tuple  			=  self.hash_function(_A    )
  
  			if self.values[key] is None:
  				self._set_value(_A						,  _A    )
  
  			elif self.values[key] == data:
  				pass
  
  			else:
  				__magic_name__ :					str  			=  self._collision_resolution(_A						,  _A    )
  				if collision_resolution is not None:
  					self._set_value(_A						,  _A    )
  				else:
  					self.rehashing()
  					self.insert_data(_A    )