






'''simple docstring'''


from sklearn.metrics import matthews_corrcoef

import datasets


lowerCamelCase_				: List[str]    	=							"\nCompute the Matthews correlation coefficient (MCC)\n\nThe Matthews correlation coefficient is used in machine learning as a\nmeasure of the quality of binary and multiclass classifications. It takes\ninto account true and false positives and negatives and is generally\nregarded as a balanced measure which can be used even if the classes are of\nvery different sizes. The MCC is in essence a correlation coefficient value\nbetween -1 and +1. A coefficient of +1 represents a perfect prediction, 0\nan average random prediction and -1 an inverse prediction.  The statistic\nis also known as the phi coefficient. [source: Wikipedia]\n"

lowerCamelCase_				: Optional[int]    	=							"\nArgs:\n    predictions (list of int): Predicted labels, as returned by a model.\n    references (list of int): Ground truth labels.\n    sample_weight (list of int, float, or bool): Sample weights. Defaults to `None`.\nReturns:\n    matthews_correlation (dict containing float): Matthews correlation.\nExamples:\n    Example 1, a basic example with only predictions and references as inputs:\n        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")\n        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],\n        ...                                     predictions=[1, 2, 2, 0, 3, 3])\n        >>> print(round(results['matthews_correlation'], 2))\n        0.54\n\n    Example 2, the same example as above, but also including sample weights:\n        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")\n        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],\n        ...                                     predictions=[1, 2, 2, 0, 3, 3],\n        ...                                     sample_weight=[0.5, 3, 1, 1, 1, 2])\n        >>> print(round(results['matthews_correlation'], 2))\n        0.1\n\n    Example 3, the same example as above, but with sample weights that cause a negative correlation:\n        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")\n        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],\n        ...                                     predictions=[1, 2, 2, 0, 3, 3],\n        ...                                     sample_weight=[0.5, 1, 0, 0, 0, 1])\n        >>> print(round(results['matthews_correlation'], 2))\n        -0.25\n"

lowerCamelCase_				: Any    	=							"\\n@article{scikit-learn,\n  title={Scikit-learn: Machine Learning in {P}ython},\n  author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.\n         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.\n         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and\n         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},\n  journal={Journal of Machine Learning Research},\n  volume={12},\n  pages={2825--2830},\n  year={2011}\n}\n"
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION       ,_KWARGS_DESCRIPTION	)
class    _SCREAMING_SNAKE_CASE							(		datasets.Metric	):


			'''simple docstring'''





			def 				A      (   self							:						Dict			)							->    Optional[Any]:

									'''simple docstring'''







									return datasets.MetricInfo(
									    description=_DESCRIPTION ,      citation=_CITATION ,      inputs_description=_KWARGS_DESCRIPTION ,      features=datasets.Features(
									        {
									            """predictions""": datasets.Value("""int32"""			),
									            """references""": datasets.Value("""int32"""			),
									        }			) ,      reference_urls=[
									        """https://scikit-learn.org/stable/modules/generated/sklearn.metrics.matthews_corrcoef.html"""
									    ] ,      )







			def 				A      (   self							:						str ,      lowercase							:						List[Any] ,      lowercase							:						Optional[Any] ,      lowercase							:						Optional[int]=None			)							->    List[Any]:

									'''simple docstring'''







									return {
									    "matthews_correlation": float(matthews_corrcoef(lowercase ,      lowercase ,      sample_weight=lowercase			)			),
									}












'''simple docstring'''


import tempfile

import torch

from diffusers import (
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    DPMSolverSinglestepScheduler,
    UniPCMultistepScheduler,
)

from .test_schedulers import SchedulerCommonTest
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			__a							:							Dict					     =					(DPMSolverSinglestepScheduler,)
			__a							:							List[Any]					     =					(("num_inference_steps", 25),)






			def 				A      (   self							:						List[Any] ,      **lowercase							:						Any			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = {
									    """num_train_timesteps""": 1_0_0_0,
									    """beta_start""": 0.0_0_0_1,
									    """beta_end""": 0.0_2,
									    """beta_schedule""": """linear""",
									    """solver_order""": 2,
									    """prediction_type""": """epsilon""",
									    """thresholding""": False,
									    """sample_max_value""": 1.0,
									    """algorithm_type""": """dpmsolver++""",
									    """solver_type""": """midpoint""",
									    """lambda_min_clipped""": -float("""inf"""			),
									    """variance_type""": None,
									}

									config.update(**lowercase			)
									return config






			def 				A      (   self							:						List[Any] ,      lowercase							:						Tuple=0 ,      **lowercase							:						Optional[Any]			)							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = dict(self.forward_default_kwargs			)
									UpperCamelCase__         = kwargs.pop("""num_inference_steps""" ,      lowercase			)
									UpperCamelCase__         = self.dummy_sample
									UpperCamelCase__         = 0.1 * sample
									UpperCamelCase__         = [residual + 0.2, residual + 0.1_5, residual + 0.1_0]

									for scheduler_class in self.scheduler_classes:
															UpperCamelCase__         = self.get_scheduler_config(**lowercase			)
															UpperCamelCase__         = scheduler_class(**lowercase			)
															scheduler.set_timesteps(lowercase			)
															# copy over dummy past residuals
															UpperCamelCase__         = dummy_past_residuals[: scheduler.config.solver_order]

															with tempfile.TemporaryDirectory() as tmpdirname:
																					scheduler.save_config(lowercase			)
																					UpperCamelCase__         = scheduler_class.from_pretrained(lowercase			)
																					new_scheduler.set_timesteps(lowercase			)
																					# copy over dummy past residuals
																					UpperCamelCase__         = dummy_past_residuals[: new_scheduler.config.solver_order]

															UpperCamelCase__    ,   UpperCamelCase__         = sample, sample
															for t in range(lowercase ,      time_step + scheduler.config.solver_order + 1			):
																					UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase ,      **lowercase			).prev_sample
																					UpperCamelCase__         = new_scheduler.step(lowercase ,      lowercase ,      lowercase ,      **lowercase			).prev_sample

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






			def 				A      (   self							:						List[str]			)							->    Any:

									'''simple docstring'''







									pass






			def 				A      (   self							:						Any ,      lowercase							:						List[Any]=0 ,      **lowercase							:						Optional[int]			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = dict(self.forward_default_kwargs			)
									UpperCamelCase__         = kwargs.pop("""num_inference_steps""" ,      lowercase			)
									UpperCamelCase__         = self.dummy_sample
									UpperCamelCase__         = 0.1 * sample
									UpperCamelCase__         = [residual + 0.2, residual + 0.1_5, residual + 0.1_0]

									for scheduler_class in self.scheduler_classes:
															UpperCamelCase__         = self.get_scheduler_config()
															UpperCamelCase__         = scheduler_class(**lowercase			)
															scheduler.set_timesteps(lowercase			)

															# copy over dummy past residuals (must be after setting timesteps)
															UpperCamelCase__         = dummy_past_residuals[: scheduler.config.solver_order]

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

																					# copy over dummy past residual (must be after setting timesteps)
																					UpperCamelCase__         = dummy_past_residuals[: new_scheduler.config.solver_order]

															UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase ,      **lowercase			).prev_sample
															UpperCamelCase__         = new_scheduler.step(lowercase ,      lowercase ,      lowercase ,      **lowercase			).prev_sample

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






			def 				A      (   self							:						Union[str, Any] ,      lowercase							:						Any=None ,      **lowercase							:						List[Any]			)							->    Dict:

									'''simple docstring'''







									if scheduler is None:
															UpperCamelCase__         = self.scheduler_classes[0]
															UpperCamelCase__         = self.get_scheduler_config(**lowercase			)
															UpperCamelCase__         = scheduler_class(**lowercase			)

									UpperCamelCase__         = self.scheduler_classes[0]
									UpperCamelCase__         = self.get_scheduler_config(**lowercase			)
									UpperCamelCase__         = scheduler_class(**lowercase			)

									UpperCamelCase__         = 1_0
									UpperCamelCase__         = self.dummy_model()
									UpperCamelCase__         = self.dummy_sample_deter
									scheduler.set_timesteps(lowercase			)

									for i, t in enumerate(scheduler.timesteps			):
															UpperCamelCase__         = model(lowercase ,      lowercase			)
															UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase			).prev_sample

									return sample






			def 				A      (   self							:						Any			)							->    List[Any]:

									'''simple docstring'''







									UpperCamelCase__         = DPMSolverSinglestepScheduler(**self.get_scheduler_config()			)
									UpperCamelCase__         = 5_0
									UpperCamelCase__         = self.dummy_model()
									UpperCamelCase__         = self.dummy_sample_deter
									scheduler.set_timesteps(lowercase			)

									# make sure that the first t is uneven
									for i, t in enumerate(scheduler.timesteps[3:]			):
															UpperCamelCase__         = model(lowercase ,      lowercase			)
															UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase			).prev_sample

									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_5_7_4			) < 1e-3






			def 				A      (   self							:						int			)							->    Union[str, Any]:

									'''simple docstring'''







									for timesteps in [2_5, 5_0, 1_0_0, 9_9_9, 1_0_0_0]:
															self.check_over_configs(num_train_timesteps=lowercase			)






			def 				A      (   self							:						Optional[int]			)							->    List[Any]:

									'''simple docstring'''







									UpperCamelCase__         = DPMSolverSinglestepScheduler(**self.get_scheduler_config()			)
									UpperCamelCase__         = self.full_loop(scheduler=lowercase			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_7_9_1			) < 1e-3

									UpperCamelCase__         = DEISMultistepScheduler.from_config(scheduler.config			)
									UpperCamelCase__         = DPMSolverMultistepScheduler.from_config(scheduler.config			)
									UpperCamelCase__         = UniPCMultistepScheduler.from_config(scheduler.config			)
									UpperCamelCase__         = DPMSolverSinglestepScheduler.from_config(scheduler.config			)

									UpperCamelCase__         = self.full_loop(scheduler=lowercase			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_7_9_1			) < 1e-3






			def 				A      (   self							:						Tuple			)							->    Union[str, Any]:

									'''simple docstring'''







									self.check_over_configs(thresholding=lowercase			)
									for order in [1, 2, 3]:
															for solver_type in ["midpoint", "heun"]:
																					for threshold in [0.5, 1.0, 2.0]:
																											for prediction_type in ["epsilon", "sample"]:
																																	self.check_over_configs(
																																	    thresholding=lowercase ,      prediction_type=lowercase ,      sample_max_value=lowercase ,      algorithm_type="""dpmsolver++""" ,      solver_order=lowercase ,      solver_type=lowercase ,      )






			def 				A      (   self							:						Optional[int]			)							->    Tuple:

									'''simple docstring'''







									for prediction_type in ["epsilon", "v_prediction"]:
															self.check_over_configs(prediction_type=lowercase			)






			def 				A      (   self							:						Optional[int]			)							->    int:

									'''simple docstring'''







									for algorithm_type in ["dpmsolver", "dpmsolver++"]:
															for solver_type in ["midpoint", "heun"]:
																					for order in [1, 2, 3]:
																											for prediction_type in ["epsilon", "sample"]:
																																	self.check_over_configs(
																																	    solver_order=lowercase ,      solver_type=lowercase ,      prediction_type=lowercase ,      algorithm_type=lowercase ,      )
																																	UpperCamelCase__         = self.full_loop(
																																	    solver_order=lowercase ,      solver_type=lowercase ,      prediction_type=lowercase ,      algorithm_type=lowercase ,      )
																																	assert not torch.isnan(lowercase			).any(), "Samples have nan numbers"






			def 				A      (   self							:						List[str]			)							->    Union[str, Any]:

									'''simple docstring'''







									self.check_over_configs(lower_order_final=lowercase			)
									self.check_over_configs(lower_order_final=lowercase			)






			def 				A      (   self							:						Tuple			)							->    Optional[int]:

									'''simple docstring'''







									self.check_over_configs(lambda_min_clipped=-float("""inf"""			)			)
									self.check_over_configs(lambda_min_clipped=-5.1			)






			def 				A      (   self							:						List[Any]			)							->    int:

									'''simple docstring'''







									self.check_over_configs(variance_type=lowercase			)
									self.check_over_configs(variance_type="""learned_range"""			)






			def 				A      (   self							:						Tuple			)							->    int:

									'''simple docstring'''







									for num_inference_steps in [1, 2, 3, 5, 1_0, 5_0, 1_0_0, 9_9_9, 1_0_0_0]:
															self.check_over_forward(num_inference_steps=lowercase ,      time_step=0			)






			def 				A      (   self							:						List[str]			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = self.full_loop()
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_7_9_1			) < 1e-3






			def 				A      (   self							:						str			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.full_loop(use_karras_sigmas=lowercase			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_2_4_8			) < 1e-3






			def 				A      (   self							:						List[Any]			)							->    List[str]:

									'''simple docstring'''







									UpperCamelCase__         = self.full_loop(prediction_type="""v_prediction"""			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.1_4_5_3			) < 1e-3






			def 				A      (   self							:						int			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.full_loop(prediction_type="""v_prediction""" ,      use_karras_sigmas=lowercase			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.0_6_4_9			) < 1e-3







			def 				A      (   self							:						Optional[Any]			)							->    Union[str, Any]:

									'''simple docstring'''







									UpperCamelCase__         = self.scheduler_classes[0]
									UpperCamelCase__         = self.get_scheduler_config(thresholding=lowercase ,      dynamic_thresholding_ratio=0			)
									UpperCamelCase__         = scheduler_class(**lowercase			)

									UpperCamelCase__         = 1_0
									UpperCamelCase__         = self.dummy_model()
									UpperCamelCase__         = self.dummy_sample_deter.half()
									scheduler.set_timesteps(lowercase			)

									for i, t in enumerate(scheduler.timesteps			):
															UpperCamelCase__         = model(lowercase ,      lowercase			)
															UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase			).prev_sample

									assert sample.dtype == torch.floataa
