
import torch

from diffusers import HeunDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest



class       a_   ( _a						):
			a  : str				      =       (HeunDiscreteScheduler,)
			a  : str				      =       1_0






			def       UpperCamelCase_							(			self							, **__UpperCamelCase     ):
									_lowercase									=				{
									    """num_train_timesteps""": 1_100,
									    """beta_start""": 0.00_01,
									    """beta_end""": 0.02,
									    """beta_schedule""": """linear""",
									}

									config.update(**__UpperCamelCase     )
									return config






			def       UpperCamelCase_							(			self     ):
									for timesteps in [10, 50, 100, 1_000]:
															self.check_over_configs(num_train_timesteps=__UpperCamelCase     )






			def       UpperCamelCase_							(			self     ):
									for beta_start, beta_end in zip([0.0_00_01, 0.00_01, 0.0_01]							, [0.00_02, 0.0_02, 0.02]     ):
															self.check_over_configs(beta_start=__UpperCamelCase							, beta_end=__UpperCamelCase     )






			def       UpperCamelCase_							(			self     ):
									for schedule in ["linear", "scaled_linear", "exp"]:
															self.check_over_configs(beta_schedule=__UpperCamelCase     )






			def       UpperCamelCase_							(			self     ):
									for clip_sample_range in [1.0, 2.0, 3.0]:
															self.check_over_configs(clip_sample_range=__UpperCamelCase							, clip_sample=__UpperCamelCase     )






			def       UpperCamelCase_							(			self     ):
									for prediction_type in ["epsilon", "v_prediction", "sample"]:
															self.check_over_configs(prediction_type=__UpperCamelCase     )






			def       UpperCamelCase_							(			self     ):
									_lowercase									=				self.scheduler_classes[0]
									_lowercase									=				self.get_scheduler_config()
									_lowercase									=				scheduler_class(**__UpperCamelCase     )

									scheduler.set_timesteps(self.num_inference_steps     )

									_lowercase									=				self.dummy_model()
									_lowercase									=				self.dummy_sample_deter * scheduler.init_noise_sigma
									_lowercase									=				sample.to(__UpperCamelCase     )

									for i, t in enumerate(scheduler.timesteps     ):
															_lowercase									=				scheduler.scale_model_input(__UpperCamelCase							, __UpperCamelCase     )

															_lowercase									=				model(__UpperCamelCase							, __UpperCamelCase     )

															_lowercase									=				scheduler.step(__UpperCamelCase							, __UpperCamelCase							, __UpperCamelCase     )
															_lowercase									=				output.prev_sample

									_lowercase									=				torch.sum(torch.abs(__UpperCamelCase     )     )
									_lowercase									=				torch.mean(torch.abs(__UpperCamelCase     )     )

									if torch_device in ["cpu", "mps"]:
															assert abs(result_sum.item() - 0.12_33     ) < 1E-2
															assert abs(result_mean.item() - 0.00_02     ) < 1E-3
									else:
															# CUDA
															assert abs(result_sum.item() - 0.12_33     ) < 1E-2
															assert abs(result_mean.item() - 0.00_02     ) < 1E-3






			def       UpperCamelCase_							(			self     ):
									_lowercase									=				self.scheduler_classes[0]
									_lowercase									=				self.get_scheduler_config(prediction_type="""v_prediction"""     )
									_lowercase									=				scheduler_class(**__UpperCamelCase     )

									scheduler.set_timesteps(self.num_inference_steps     )

									_lowercase									=				self.dummy_model()
									_lowercase									=				self.dummy_sample_deter * scheduler.init_noise_sigma
									_lowercase									=				sample.to(__UpperCamelCase     )

									for i, t in enumerate(scheduler.timesteps     ):
															_lowercase									=				scheduler.scale_model_input(__UpperCamelCase							, __UpperCamelCase     )

															_lowercase									=				model(__UpperCamelCase							, __UpperCamelCase     )

															_lowercase									=				scheduler.step(__UpperCamelCase							, __UpperCamelCase							, __UpperCamelCase     )
															_lowercase									=				output.prev_sample

									_lowercase									=				torch.sum(torch.abs(__UpperCamelCase     )     )
									_lowercase									=				torch.mean(torch.abs(__UpperCamelCase     )     )

									if torch_device in ["cpu", "mps"]:
															assert abs(result_sum.item() - 4.6_934E-07     ) < 1E-2
															assert abs(result_mean.item() - 6.1_112E-10     ) < 1E-3
									else:
															# CUDA
															assert abs(result_sum.item() - 4.693_428_650_170_972E-07     ) < 1E-2
															assert abs(result_mean.item() - 0.00_02     ) < 1E-3






			def       UpperCamelCase_							(			self     ):
									_lowercase									=				self.scheduler_classes[0]
									_lowercase									=				self.get_scheduler_config()
									_lowercase									=				scheduler_class(**__UpperCamelCase     )

									scheduler.set_timesteps(self.num_inference_steps							, device=__UpperCamelCase     )

									_lowercase									=				self.dummy_model()
									_lowercase									=				self.dummy_sample_deter.to(__UpperCamelCase     ) * scheduler.init_noise_sigma

									for t in scheduler.timesteps:
															_lowercase									=				scheduler.scale_model_input(__UpperCamelCase							, __UpperCamelCase     )

															_lowercase									=				model(__UpperCamelCase							, __UpperCamelCase     )

															_lowercase									=				scheduler.step(__UpperCamelCase							, __UpperCamelCase							, __UpperCamelCase     )
															_lowercase									=				output.prev_sample

									_lowercase									=				torch.sum(torch.abs(__UpperCamelCase     )     )
									_lowercase									=				torch.mean(torch.abs(__UpperCamelCase     )     )

									if str(__UpperCamelCase     ).startswith("""cpu"""     ):
															# The following sum varies between 148 and 156 on mps. Why?
															assert abs(result_sum.item() - 0.12_33     ) < 1E-2
															assert abs(result_mean.item() - 0.00_02     ) < 1E-3
									elif str(__UpperCamelCase     ).startswith("""mps"""     ):
															# Larger tolerance on mps
															assert abs(result_mean.item() - 0.00_02     ) < 1E-2
									else:
															# CUDA
															assert abs(result_sum.item() - 0.12_33     ) < 1E-2
															assert abs(result_mean.item() - 0.00_02     ) < 1E-3






			def       UpperCamelCase_							(			self     ):
									_lowercase									=				self.scheduler_classes[0]
									_lowercase									=				self.get_scheduler_config()
									_lowercase									=				scheduler_class(**__UpperCamelCase							, use_karras_sigmas=__UpperCamelCase     )

									scheduler.set_timesteps(self.num_inference_steps							, device=__UpperCamelCase     )

									_lowercase									=				self.dummy_model()
									_lowercase									=				self.dummy_sample_deter.to(__UpperCamelCase     ) * scheduler.init_noise_sigma
									_lowercase									=				sample.to(__UpperCamelCase     )

									for t in scheduler.timesteps:
															_lowercase									=				scheduler.scale_model_input(__UpperCamelCase							, __UpperCamelCase     )

															_lowercase									=				model(__UpperCamelCase							, __UpperCamelCase     )

															_lowercase									=				scheduler.step(__UpperCamelCase							, __UpperCamelCase							, __UpperCamelCase     )
															_lowercase									=				output.prev_sample

									_lowercase									=				torch.sum(torch.abs(__UpperCamelCase     )     )
									_lowercase									=				torch.mean(torch.abs(__UpperCamelCase     )     )

									assert abs(result_sum.item() - 0.0_00_15     ) < 1E-2
									assert abs(result_mean.item() - 1.9_869_554_535_034_695E-07     ) < 1E-2

from math import sqrt




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    list[int]:
						_lowercase									=				[1]
						for i in range(2		,      int(sqrt(SCREAMING_SNAKE_CASE_					)					) + 1		,      1					):
												if number % i == 0:
																		values.append(SCREAMING_SNAKE_CASE_					)
																		if int(number // i					) != i:
																								values.append(int(number // i					)					)
						return sorted(SCREAMING_SNAKE_CASE_					)




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    bool:
						return sum(factors(SCREAMING_SNAKE_CASE_					)					) > n




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    bool:
						_lowercase									=				factors(SCREAMING_SNAKE_CASE_					)
						_lowercase									=				len(SCREAMING_SNAKE_CASE_					)
						_lowercase									=				[[0 for i in range(number + 1					)] for j in range(r + 1					)]
						for i in range(r + 1					):
												_lowercase									=				True

						for i in range(1		,      number + 1					):
												_lowercase									=				False

						for i in range(1		,      r + 1					):
												for j in range(1		,      number + 1					):
																		if j < values[i - 1]:
																								_lowercase									=				subset[i - 1][j]
																		else:
																								_lowercase									=				subset[i - 1][j] or subset[i - 1][j - values[i - 1]]

						return subset[r][number] != 0




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    bool:
						return abundant(SCREAMING_SNAKE_CASE_					) and not semi_perfect(SCREAMING_SNAKE_CASE_					)


if __name__ == "__main__":
		import doctest

		doctest.testmod(verbose=True)
		for number in (69, 70, 71):
				print(F'{number} is {"" if weird(number) else "not "}weird.')