
"""simple docstring"""






import tempfile

import torch

from diffusers import PNDMScheduler

from .test_schedulers import SchedulerCommonTest




class 			_SCREAMING_SNAKE_CASE					(			SCREAMING_SNAKE_CASE__							):
			UpperCAmelCase_  :Tuple				 =						(PNDMScheduler,)
			UpperCAmelCase_  :Optional[Any]				 =						(("num_inference_steps", 50),)






			def  __lowerCAmelCase (					self       ,   **__A       )			->     int:
						lowerCAmelCase_    :Optional[int]			     =  {
						    """num_train_timesteps""": 1000,
						    """beta_start""": 0.0_0_0_1,
						    """beta_end""": 0.0_2,
						    """beta_schedule""": """linear""",
						}

						config.update(**lowerCamelCase__       )
						return config






			def  __lowerCAmelCase (					self       ,   __A=0       ,   **__A       )			->     Tuple:
						lowerCAmelCase_    :Optional[Any]			     =  dict(self.forward_default_kwargs       )
						lowerCAmelCase_    :str			     =  kwargs.pop("""num_inference_steps"""       ,   lowerCamelCase__       )
						lowerCAmelCase_    :int			     =  self.dummy_sample
						lowerCAmelCase_    :int			     =  0.1 * sample
						lowerCAmelCase_    :int			     =  [residual + 0.2, residual + 0.1_5, residual + 0.1, residual + 0.0_5]

						for scheduler_class in self.scheduler_classes:
									lowerCAmelCase_    :Tuple			     =  self.get_scheduler_config(**lowerCamelCase__       )
									lowerCAmelCase_    :Optional[Any]			     =  scheduler_class(**lowerCamelCase__       )
									scheduler.set_timesteps(lowerCamelCase__       )
									# copy over dummy past residuals
									lowerCAmelCase_    :List[Any]			     =  dummy_past_residuals[:]

									with tempfile.TemporaryDirectory() as tmpdirname:
												scheduler.save_config(lowerCamelCase__       )
												lowerCAmelCase_    :Optional[Any]			     =  scheduler_class.from_pretrained(lowerCamelCase__       )
												new_scheduler.set_timesteps(lowerCamelCase__       )
												# copy over dummy past residuals
												lowerCAmelCase_    :int			     =  dummy_past_residuals[:]

									lowerCAmelCase_    :Dict			     =  scheduler.step_prk(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample
									lowerCAmelCase_    :Tuple			     =  new_scheduler.step_prk(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample

									assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"

									lowerCAmelCase_    :Union[str, Any]			     =  scheduler.step_plms(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample
									lowerCAmelCase_    :List[str]			     =  new_scheduler.step_plms(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample

									assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"






			def  __lowerCAmelCase (					self       )			->     List[str]:
						pass






			def  __lowerCAmelCase (					self       ,   __A=0       ,   **__A       )			->     Optional[int]:
						lowerCAmelCase_    :int			     =  dict(self.forward_default_kwargs       )
						lowerCAmelCase_    :Tuple			     =  kwargs.pop("""num_inference_steps"""       ,   lowerCamelCase__       )
						lowerCAmelCase_    :List[str]			     =  self.dummy_sample
						lowerCAmelCase_    :Any			     =  0.1 * sample
						lowerCAmelCase_    :List[str]			     =  [residual + 0.2, residual + 0.1_5, residual + 0.1, residual + 0.0_5]

						for scheduler_class in self.scheduler_classes:
									lowerCAmelCase_    :Optional[int]			     =  self.get_scheduler_config()
									lowerCAmelCase_    :Any			     =  scheduler_class(**lowerCamelCase__       )
									scheduler.set_timesteps(lowerCamelCase__       )

									# copy over dummy past residuals (must be after setting timesteps)
									lowerCAmelCase_    :Optional[int]			     =  dummy_past_residuals[:]

									with tempfile.TemporaryDirectory() as tmpdirname:
												scheduler.save_config(lowerCamelCase__       )
												lowerCAmelCase_    :Dict			     =  scheduler_class.from_pretrained(lowerCamelCase__       )
												# copy over dummy past residuals
												new_scheduler.set_timesteps(lowerCamelCase__       )

												# copy over dummy past residual (must be after setting timesteps)
												lowerCAmelCase_    :int			     =  dummy_past_residuals[:]

									lowerCAmelCase_    :Any			     =  scheduler.step_prk(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample
									lowerCAmelCase_    :Dict			     =  new_scheduler.step_prk(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample

									assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"

									lowerCAmelCase_    :Optional[int]			     =  scheduler.step_plms(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample
									lowerCAmelCase_    :Any			     =  new_scheduler.step_plms(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample

									assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"






			def  __lowerCAmelCase (					self       ,   **__A       )			->     Dict:
						lowerCAmelCase_    :List[str]			     =  self.scheduler_classes[0]
						lowerCAmelCase_    :str			     =  self.get_scheduler_config(**lowerCamelCase__       )
						lowerCAmelCase_    :List[Any]			     =  scheduler_class(**lowerCamelCase__       )

						lowerCAmelCase_    :Optional[Any]			     =  10
						lowerCAmelCase_    :Union[str, Any]			     =  self.dummy_model()
						lowerCAmelCase_    :Any			     =  self.dummy_sample_deter
						scheduler.set_timesteps(lowerCamelCase__       )

						for i, t in enumerate(scheduler.prk_timesteps       ):
									lowerCAmelCase_    :str			     =  model(lowerCamelCase__       ,   lowerCamelCase__       )
									lowerCAmelCase_    :Optional[int]			     =  scheduler.step_prk(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ).prev_sample

						for i, t in enumerate(scheduler.plms_timesteps       ):
									lowerCAmelCase_    :str			     =  model(lowerCamelCase__       ,   lowerCamelCase__       )
									lowerCAmelCase_    :List[Any]			     =  scheduler.step_plms(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ).prev_sample

						return sample






			def  __lowerCAmelCase (					self       )			->     Optional[Any]:
						lowerCAmelCase_    :Optional[Any]			     =  dict(self.forward_default_kwargs       )

						lowerCAmelCase_    :List[Any]			     =  kwargs.pop("""num_inference_steps"""       ,   lowerCamelCase__       )

						for scheduler_class in self.scheduler_classes:
									lowerCAmelCase_    :List[str]			     =  self.get_scheduler_config()
									lowerCAmelCase_    :Any			     =  scheduler_class(**lowerCamelCase__       )

									lowerCAmelCase_    :Optional[int]			     =  self.dummy_sample
									lowerCAmelCase_    :List[str]			     =  0.1 * sample

									if num_inference_steps is not None and hasattr(lowerCamelCase__       ,   """set_timesteps"""       ):
												scheduler.set_timesteps(lowerCamelCase__       )
									elif num_inference_steps is not None and not hasattr(lowerCamelCase__       ,   """set_timesteps"""       ):
												lowerCAmelCase_    :Optional[int]			     =  num_inference_steps

									# copy over dummy past residuals (must be done after set_timesteps)
									lowerCAmelCase_    :Dict			     =  [residual + 0.2, residual + 0.1_5, residual + 0.1, residual + 0.0_5]
									lowerCAmelCase_    :Any			     =  dummy_past_residuals[:]

									lowerCAmelCase_    :Optional[Any]			     =  scheduler.step_prk(lowerCamelCase__       ,   0       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample
									lowerCAmelCase_    :List[Any]			     =  scheduler.step_prk(lowerCamelCase__       ,   1       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample

									self.assertEqual(output_a.shape       ,   sample.shape       )
									self.assertEqual(output_a.shape       ,   output_a.shape       )

									lowerCAmelCase_    :List[str]			     =  scheduler.step_plms(lowerCamelCase__       ,   0       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample
									lowerCAmelCase_    :int			     =  scheduler.step_plms(lowerCamelCase__       ,   1       ,   lowerCamelCase__       ,   **lowerCamelCase__       ).prev_sample

									self.assertEqual(output_a.shape       ,   sample.shape       )
									self.assertEqual(output_a.shape       ,   output_a.shape       )






			def  __lowerCAmelCase (					self       )			->     Union[str, Any]:
						for timesteps in [100, 1000]:
									self.check_over_configs(num_train_timesteps=lowerCamelCase__       )






			def  __lowerCAmelCase (					self       )			->     Any:
						for steps_offset in [0, 1]:
									self.check_over_configs(steps_offset=lowerCamelCase__       )

						lowerCAmelCase_    :Optional[Any]			     =  self.scheduler_classes[0]
						lowerCAmelCase_    :str			     =  self.get_scheduler_config(steps_offset=1       )
						lowerCAmelCase_    :Any			     =  scheduler_class(**lowerCamelCase__       )
						scheduler.set_timesteps(10       )
						assert torch.equal(
						    scheduler.timesteps       ,   torch.LongTensor(
						        [901, 851, 851, 801, 801, 751, 751, 701, 701, 651, 651, 601, 601, 501, 401, 301, 201, 101, 1]       )       ,   )






			def  __lowerCAmelCase (					self       )			->     Union[str, Any]:
						for beta_start, beta_end in zip([0.0_0_0_1, 0.0_0_1]       ,   [0.0_0_2, 0.0_2]       ):
									self.check_over_configs(beta_start=lowerCamelCase__       ,   beta_end=lowerCamelCase__       )






			def  __lowerCAmelCase (					self       )			->     Any:
						for schedule in ["linear", "squaredcos_cap_v2"]:
									self.check_over_configs(beta_schedule=lowerCamelCase__       )






			def  __lowerCAmelCase (					self       )			->     Dict:
						for prediction_type in ["epsilon", "v_prediction"]:
									self.check_over_configs(prediction_type=lowerCamelCase__       )






			def  __lowerCAmelCase (					self       )			->     Optional[Any]:
						for t in [1, 5, 10]:
									self.check_over_forward(time_step=lowerCamelCase__       )






			def  __lowerCAmelCase (					self       )			->     int:
						for t, num_inference_steps in zip([1, 5, 10]       ,   [10, 50, 100]       ):
									self.check_over_forward(num_inference_steps=lowerCamelCase__       )






			def  __lowerCAmelCase (					self       )			->     Any:
						# earlier version of set_timesteps() caused an error indexing alpha's with inference steps as power of 3
						lowerCAmelCase_    :Optional[Any]			     =  27

						for scheduler_class in self.scheduler_classes:
									lowerCAmelCase_    :str			     =  self.dummy_sample
									lowerCAmelCase_    :str			     =  0.1 * sample

									lowerCAmelCase_    :List[str]			     =  self.get_scheduler_config()
									lowerCAmelCase_    :Dict			     =  scheduler_class(**lowerCamelCase__       )

									scheduler.set_timesteps(lowerCamelCase__       )

									# before power of 3 fix, would error on first step, so we only need to do two
									for i, t in enumerate(scheduler.prk_timesteps[:2]       ):
												lowerCAmelCase_    :Optional[int]			     =  scheduler.step_prk(lowerCamelCase__       ,   lowerCamelCase__       ,   lowerCamelCase__       ).prev_sample






			def  __lowerCAmelCase (					self       )			->     Optional[Any]:
						with self.assertRaises(lowerCamelCase__       ):
									lowerCAmelCase_    :Tuple			     =  self.scheduler_classes[0]
									lowerCAmelCase_    :Any			     =  self.get_scheduler_config()
									lowerCAmelCase_    :Optional[Any]			     =  scheduler_class(**lowerCamelCase__       )

									scheduler.step_plms(self.dummy_sample       ,   1       ,   self.dummy_sample       ).prev_sample






			def  __lowerCAmelCase (					self       )			->     Optional[Any]:
						lowerCAmelCase_    :List[str]			     =  self.full_loop()
						lowerCAmelCase_    :Union[str, Any]			     =  torch.sum(torch.abs(lowerCamelCase__       )       )
						lowerCAmelCase_    :Tuple			     =  torch.mean(torch.abs(lowerCamelCase__       )       )

						assert abs(result_sum.item() - 1_9_8.1_3_1_8       ) < 1E-2
						assert abs(result_mean.item() - 0.2_5_8_0       ) < 1E-3






			def  __lowerCAmelCase (					self       )			->     Optional[int]:
						lowerCAmelCase_    :Any			     =  self.full_loop(prediction_type="""v_prediction"""       )
						lowerCAmelCase_    :int			     =  torch.sum(torch.abs(lowerCamelCase__       )       )
						lowerCAmelCase_    :Union[str, Any]			     =  torch.mean(torch.abs(lowerCamelCase__       )       )

						assert abs(result_sum.item() - 6_7.3_9_8_6       ) < 1E-2
						assert abs(result_mean.item() - 0.0_8_7_8       ) < 1E-3






			def  __lowerCAmelCase (					self       )			->     Union[str, Any]:
						# We specify different beta, so that the first alpha is 0.99
						lowerCAmelCase_    :Any			     =  self.full_loop(set_alpha_to_one=lowerCamelCase__       ,   beta_start=0.0_1       )
						lowerCAmelCase_    :List[Any]			     =  torch.sum(torch.abs(lowerCamelCase__       )       )
						lowerCAmelCase_    :Dict			     =  torch.mean(torch.abs(lowerCamelCase__       )       )

						assert abs(result_sum.item() - 2_3_0.0_3_9_9       ) < 1E-2
						assert abs(result_mean.item() - 0.2_9_9_5       ) < 1E-3






			def  __lowerCAmelCase (					self       )			->     Dict:
						# We specify different beta, so that the first alpha is 0.99
						lowerCAmelCase_    :Union[str, Any]			     =  self.full_loop(set_alpha_to_one=lowerCamelCase__       ,   beta_start=0.0_1       )
						lowerCAmelCase_    :List[str]			     =  torch.sum(torch.abs(lowerCamelCase__       )       )
						lowerCAmelCase_    :Any			     =  torch.mean(torch.abs(lowerCamelCase__       )       )

						assert abs(result_sum.item() - 1_8_6.9_4_8_2       ) < 1E-2
						assert abs(result_mean.item() - 0.2_4_3_4       ) < 1E-3











def 	__UpperCamelCase	(  _lowerCAmelCase      ,     _lowerCAmelCase		)       ->  int:



    """simple docstring"""






    while second != 0:
        A :       int          =   first & second
        first ^= second
        A :       Tuple          =   c << 1
    return first


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     SCREAMING_SNAKE_CASE_:int             =						int(input("""Enter the first number: """).strip())
     SCREAMING_SNAKE_CASE_:Optional[int]             =						int(input("""Enter the second number: """).strip())
     print(F"""{add(first, second) = }""")


