





'''simple docstring'''






import tempfile
import unittest

from diffusers import (
    DDIMScheduler,
    DDPMScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    PNDMScheduler,
    logging,
)
from diffusers.configuration_utils import ConfigMixin, register_to_config
from diffusers.utils.testing_utils import CaptureLogger



class  lowerCamelCase__				(						snake_case_						):


	"""simple docstring"""





	__magic_name__							   =		"""config.json"""




	@register_to_config
	def __init__(					self   ,     UpperCAmelCase__=2   ,     UpperCAmelCase__=5   ,     UpperCAmelCase__=(2, 5)   ,     UpperCAmelCase__="for diffusion"   ,     UpperCAmelCase__=[1, 3]   ,     )       ->				Union[str, Any]:
					pass



class  lowerCamelCase__				(						snake_case_						):


	"""simple docstring"""





	__magic_name__							   =		"""config.json"""




	@register_to_config
	def __init__(					self   ,     UpperCAmelCase__=2   ,     UpperCAmelCase__=5   ,     UpperCAmelCase__=(2, 5)   ,     UpperCAmelCase__="for diffusion"   ,     UpperCAmelCase__=[1, 3]   ,     )       ->				Dict:
					pass



class  lowerCamelCase__				(						snake_case_						):


	"""simple docstring"""





	__magic_name__							   =		"""config.json"""




	@register_to_config
	def __init__(					self   ,     UpperCAmelCase__=2   ,     UpperCAmelCase__=5   ,     UpperCAmelCase__=(2, 5)   ,     UpperCAmelCase__="for diffusion"   ,     UpperCAmelCase__=[1, 3]   ,     UpperCAmelCase__=[1, 3]   ,     )       ->				Dict:
					pass



class  lowerCamelCase__				(						snake_case_						):


	"""simple docstring"""





	__magic_name__							   =		"""config.json"""




	@register_to_config
	def __init__(					self   ,     UpperCAmelCase__=2   ,     UpperCAmelCase__=5   ,     UpperCAmelCase__=(2, 5)   ,     UpperCAmelCase__="for diffusion"   ,     UpperCAmelCase__=[1, 5]   ,     UpperCAmelCase__=[5, 4]   ,     )       ->				Any:
					pass



class  lowerCamelCase__				(						unittest.TestCase						):


	"""simple docstring"""





	def 				_lowerCamelCase				(					self			)       ->				Tuple:
					with self.assertRaises(UpperCAmelCase__			):
									ConfigMixin.load_config('''dummy_path'''			)




	def 				_lowerCamelCase				(					self			)       ->				Tuple:
					_A :				Union[str, Any]				=  SampleObject()
					_A :				List[str]				=  obj.config
					assert config["a"] == 2
					assert config["b"] == 5
					assert config["c"] == (2, 5)
					assert config["d"] == "for diffusion"
					assert config["e"] == [1, 3]

					# init ignore private arguments
					_A :				Optional[int]				=  SampleObject(_name_or_path='''lalala'''			)
					_A :				str				=  obj.config
					assert config["a"] == 2
					assert config["b"] == 5
					assert config["c"] == (2, 5)
					assert config["d"] == "for diffusion"
					assert config["e"] == [1, 3]

					# can override default
					_A :				int				=  SampleObject(c=6			)
					_A :				List[Any]				=  obj.config
					assert config["a"] == 2
					assert config["b"] == 5
					assert config["c"] == 6
					assert config["d"] == "for diffusion"
					assert config["e"] == [1, 3]

					# can use positional arguments.
					_A :				Optional[Any]				=  SampleObject(1   ,     c=6			)
					_A :				int				=  obj.config
					assert config["a"] == 1
					assert config["b"] == 5
					assert config["c"] == 6
					assert config["d"] == "for diffusion"
					assert config["e"] == [1, 3]




	def 				_lowerCamelCase				(					self			)       ->				Dict:
					_A :				Tuple				=  SampleObject()
					_A :				int				=  obj.config

					assert config["a"] == 2
					assert config["b"] == 5
					assert config["c"] == (2, 5)
					assert config["d"] == "for diffusion"
					assert config["e"] == [1, 3]

					with tempfile.TemporaryDirectory() as tmpdirname:
									obj.save_config(UpperCAmelCase__			)
									_A :				Dict				=  SampleObject.from_config(SampleObject.load_config(UpperCAmelCase__			)			)
									_A :				List[str]				=  new_obj.config

					# unfreeze configs
					_A :				int				=  dict(UpperCAmelCase__			)
					_A :				Any				=  dict(UpperCAmelCase__			)

					assert config.pop('''c'''			) == (2, 5)  # instantiated as tuple
					assert new_config.pop('''c'''			) == [2, 5]  # saved & loaded as list because of json
					config.pop('''_use_default_values'''			)
					assert config == new_config




	def 				_lowerCamelCase				(					self			)       ->				List[Any]:
					_A :				int				=  logging.get_logger('''diffusers.configuration_utils'''			)
					# 30 for warning
					logger.setLevel(3_0			)

					with CaptureLogger(UpperCAmelCase__			) as cap_logger:
									_A :				str				=  DDIMScheduler.from_pretrained(
									    '''hf-internal-testing/tiny-stable-diffusion-torch'''   ,     subfolder='''scheduler'''			)

					assert ddim.__class__ == DDIMScheduler
					# no warning should be thrown
					assert cap_logger.out == ""




	def 				_lowerCamelCase				(					self			)       ->				Tuple:
					_A :				List[str]				=  logging.get_logger('''diffusers.configuration_utils'''			)
					# 30 for warning
					logger.setLevel(3_0			)

					with CaptureLogger(UpperCAmelCase__			) as cap_logger:
									_A :				Dict				=  EulerDiscreteScheduler.from_pretrained(
									    '''hf-internal-testing/tiny-stable-diffusion-torch'''   ,     subfolder='''scheduler'''			)

					assert euler.__class__ == EulerDiscreteScheduler
					# no warning should be thrown
					assert cap_logger.out == ""




	def 				_lowerCamelCase				(					self			)       ->				List[str]:
					_A :				Any				=  logging.get_logger('''diffusers.configuration_utils'''			)
					# 30 for warning
					logger.setLevel(3_0			)

					with CaptureLogger(UpperCAmelCase__			) as cap_logger:
									_A :				Dict				=  EulerAncestralDiscreteScheduler.from_pretrained(
									    '''hf-internal-testing/tiny-stable-diffusion-torch'''   ,     subfolder='''scheduler'''			)

					assert euler.__class__ == EulerAncestralDiscreteScheduler
					# no warning should be thrown
					assert cap_logger.out == ""




	def 				_lowerCamelCase				(					self			)       ->				str:
					_A :				str				=  logging.get_logger('''diffusers.configuration_utils'''			)
					# 30 for warning
					logger.setLevel(3_0			)

					with CaptureLogger(UpperCAmelCase__			) as cap_logger:
									_A :				Dict				=  PNDMScheduler.from_pretrained(
									    '''hf-internal-testing/tiny-stable-diffusion-torch'''   ,     subfolder='''scheduler'''			)

					assert pndm.__class__ == PNDMScheduler
					# no warning should be thrown
					assert cap_logger.out == ""




	def 				_lowerCamelCase				(					self			)       ->				List[str]:
					_A :				int				=  logging.get_logger('''diffusers.configuration_utils'''			)
					# 30 for warning
					logger.setLevel(3_0			)

					with CaptureLogger(UpperCAmelCase__			) as cap_logger:
									_A :				Optional[int]				=  DDPMScheduler.from_pretrained(
									    '''hf-internal-testing/tiny-stable-diffusion-torch'''   ,     subfolder='''scheduler'''   ,     prediction_type='''sample'''   ,     beta_end=8   ,     )

					with CaptureLogger(UpperCAmelCase__			) as cap_logger_a:
									_A :				str				=  DDPMScheduler.from_pretrained('''google/ddpm-celebahq-256'''   ,     beta_start=8_8			)

					assert ddpm.__class__ == DDPMScheduler
					assert ddpm.config.prediction_type == "sample"
					assert ddpm.config.beta_end == 8
					assert ddpm_a.config.beta_start == 8_8

					# no warning should be thrown
					assert cap_logger.out == ""
					assert cap_logger_a.out == ""




	def 				_lowerCamelCase				(					self			)       ->				int:
					_A :				Tuple				=  logging.get_logger('''diffusers.configuration_utils'''			)
					# 30 for warning
					logger.setLevel(3_0			)

					with CaptureLogger(UpperCAmelCase__			) as cap_logger:
									_A :				int				=  DPMSolverMultistepScheduler.from_pretrained(
									    '''hf-internal-testing/tiny-stable-diffusion-torch'''   ,     subfolder='''scheduler'''			)

					assert dpm.__class__ == DPMSolverMultistepScheduler
					# no warning should be thrown
					assert cap_logger.out == ""




	def 				_lowerCamelCase				(					self			)       ->				int:
					# let's first save a config that should be in the form
					#    a=2,
					#    b=5,
					#    c=(2, 5),
					#    d="for diffusion",
					#    e=[1, 3],

					_A :				str				=  SampleObject()

					_A :				Any				=  {k: v for k, v in config.config.items() if not k.startswith('''_'''			)}

					# make sure that default config has all keys in `_use_default_values`
					assert set(config_dict.keys()			) == set(config.config._use_default_values			)

					with tempfile.TemporaryDirectory() as tmpdirname:
									config.save_config(UpperCAmelCase__			)

									# now loading it with SampleObject2 should put f into `_use_default_values`
									_A :				Union[str, Any]				=  SampleObjecta.from_config(UpperCAmelCase__			)

									assert "f" in config._use_default_values
									assert config.f == [1, 3]

					# now loading the config, should **NOT** use [1, 3] for `f`, but the default [1, 4] value
					# **BECAUSE** it is part of `config._use_default_values`
					_A :				Union[str, Any]				=  SampleObjecta.from_config(config.config			)
					assert new_config.f == [5, 4]

					config.config._use_default_values.pop()
					_A :				Union[str, Any]				=  SampleObjecta.from_config(config.config			)
					assert new_config_a.f == [1, 3]

					# Nevertheless "e" should still be correctly loaded to [1, 3] from SampleObject2 instead of defaulting to [1, 5]
					assert new_config_a.e == [1, 3]







'''simple docstring'''






from .hash_table import HashTable
from .number_theory.prime_numbers import is_prime, next_prime



class  lowerCamelCase__				(						snake_case_						):


	"""simple docstring"""





	def __init__(					self   ,     *UpperCAmelCase__   ,     **UpperCAmelCase__			)       ->				Optional[int]:
					super().__init__(*UpperCAmelCase__   ,     **UpperCAmelCase__			)




	def 				_lowerCamelCase				(					self   ,     UpperCAmelCase__   ,     UpperCAmelCase__			)       ->				Optional[int]:
					_A :				Union[str, Any]				=  (
					    next_prime(value % self.size_table			)
					    if not is_prime(value % self.size_table			)
					    else value % self.size_table
					)  # gt = bigger than
					return next_prime_gt - (data % next_prime_gt)




	def 				_lowerCamelCase				(					self   ,     UpperCAmelCase__   ,     UpperCAmelCase__   ,     UpperCAmelCase__			)       ->				Union[str, Any]:
					return (increment * self.__hash_function_a(UpperCAmelCase__   ,     UpperCAmelCase__			)) % self.size_table




	def 				_lowerCamelCase				(					self   ,     UpperCAmelCase__   ,     UpperCAmelCase__=None			)       ->				List[Any]:
					_A :				Optional[int]				=  1
					_A :				Optional[int]				=  self.hash_function(UpperCAmelCase__			)

					while self.values[new_key] is not None and self.values[new_key] != key:
									_A :				int				=  (
									    self.__hash_double_function(UpperCAmelCase__   ,     UpperCAmelCase__   ,     UpperCAmelCase__			)
									    if self.balanced_factor() >= self.lim_charge
									    else None
									)
									if new_key is None:
													break
									else:
													i += 1

					return new_key
