




'''simple docstring'''




import warnings

from ...utils import is_sklearn_available, requires_backends


if is_sklearn_available():
   from scipy.stats import pearsonr, spearmanr
   from sklearn.metrics import fa_score, matthews_corrcoef


_a   :	List[Any] 							=   (
    "This metric will be removed from the library soon, metrics should be handled with the 🤗 Evaluate "
    "library. You can have a look at this example script for pointers: "
    "https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_glue.py"
)

def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__						)					->       int:





       """simple docstring"""


       warnings.warn(lowerCAmelCase__							,    lowerCAmelCase__						)
       requires_backends(lowerCAmelCase__							,    "sklearn"						)
       return (preds == labels).mean()

def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__						)					->       int:





       """simple docstring"""


       warnings.warn(lowerCAmelCase__							,    lowerCAmelCase__						)
       requires_backends(lowerCAmelCase__							,    "sklearn"						)
       __UpperCAmelCase  :				Optional[Any]       				=		simple_accuracy(lowerCAmelCase__							,    lowerCAmelCase__						)
       __UpperCAmelCase  :				Optional[Any]       				=		fa_score(y_true=lowerCAmelCase__							,    y_pred=lowerCAmelCase__						)
       return {
           "acc": acc,
           "f1": fa,
           "acc_and_f1": (acc + fa) / 2,
       }

def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__						)					->       int:





       """simple docstring"""


       warnings.warn(lowerCAmelCase__							,    lowerCAmelCase__						)
       requires_backends(lowerCAmelCase__							,    "sklearn"						)
       __UpperCAmelCase  :				int       				=		pearsonr(lowerCAmelCase__							,    lowerCAmelCase__						)[0]
       __UpperCAmelCase  :				int       				=		spearmanr(lowerCAmelCase__							,    lowerCAmelCase__						)[0]
       return {
           "pearson": pearson_corr,
           "spearmanr": spearman_corr,
           "corr": (pearson_corr + spearman_corr) / 2,
       }

def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__							,    lowerCamelCase__						)					->       Union[str, Any]:





       """simple docstring"""


       warnings.warn(lowerCAmelCase__							,    lowerCAmelCase__						)
       requires_backends(lowerCAmelCase__							,    "sklearn"						)
       assert len(lowerCAmelCase__						) == len(lowerCAmelCase__						), f"""Predictions and labels have mismatched lengths {len(lowerCAmelCase__						)} and {len(lowerCAmelCase__						)}"""
       if task_name == "cola":
              return {"mcc": matthews_corrcoef(lowerCAmelCase__							,    lowerCAmelCase__						)}
       elif task_name == "sst-2":
              return {"acc": simple_accuracy(lowerCAmelCase__							,    lowerCAmelCase__						)}
       elif task_name == "mrpc":
              return acc_and_fa(lowerCAmelCase__							,    lowerCAmelCase__						)
       elif task_name == "sts-b":
              return pearson_and_spearman(lowerCAmelCase__							,    lowerCAmelCase__						)
       elif task_name == "qqp":
              return acc_and_fa(lowerCAmelCase__							,    lowerCAmelCase__						)
       elif task_name == "mnli":
              return {"mnli/acc": simple_accuracy(lowerCAmelCase__							,    lowerCAmelCase__						)}
       elif task_name == "mnli-mm":
              return {"mnli-mm/acc": simple_accuracy(lowerCAmelCase__							,    lowerCAmelCase__						)}
       elif task_name == "qnli":
              return {"acc": simple_accuracy(lowerCAmelCase__							,    lowerCAmelCase__						)}
       elif task_name == "rte":
              return {"acc": simple_accuracy(lowerCAmelCase__							,    lowerCAmelCase__						)}
       elif task_name == "wnli":
              return {"acc": simple_accuracy(lowerCAmelCase__							,    lowerCAmelCase__						)}
       elif task_name == "hans":
              return {"acc": simple_accuracy(lowerCAmelCase__							,    lowerCAmelCase__						)}
       else:
              raise KeyError(lowerCAmelCase__						)


def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__							,    lowerCamelCase__						)					->       int:





       """simple docstring"""


       warnings.warn(lowerCAmelCase__							,    lowerCAmelCase__						)
       requires_backends(lowerCAmelCase__							,    "sklearn"						)
       if len(lowerCAmelCase__						) != len(lowerCAmelCase__						):
              raise ValueError(f"""Predictions and labels have mismatched lengths {len(lowerCAmelCase__						)} and {len(lowerCAmelCase__						)}"""						)
       if task_name == "xnli":
              return {"acc": simple_accuracy(lowerCAmelCase__							,    lowerCAmelCase__						)}
       else:
              raise KeyError(lowerCAmelCase__						)







'''simple docstring'''




def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__							,    lowerCamelCase__						)					->       bool:





       """simple docstring"""


       return not any(
           neighbour == 1 and colored_vertices[i] == color
           for i, neighbour in enumerate(lowerCamelCase__						)						)

def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__							,    lowerCamelCase__							,    lowerCamelCase__						)					->       bool:





       """simple docstring"""


       if index == len(lowerCamelCase__						):
              return True

       # Recursive Step
       for i in range(lowerCamelCase__						):
              if valid_coloring(graph[index]							,    lowerCamelCase__							,    lowerCamelCase__						):
                     # Color current vertex
                     __UpperCAmelCase  :				List[str]       				=		i
                     # Validate coloring
                     if util_color(lowerCamelCase__							,    lowerCamelCase__							,    lowerCamelCase__							,    index + 1						):
                            return True
                     # Backtrack
                     __UpperCAmelCase  :				Any       				=		-1
       return False


def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__						)					->       list[int]:





       """simple docstring"""


       __UpperCAmelCase  :				Optional[Any]       				=		[-1] * len(lowerCamelCase__						)

       if util_color(lowerCamelCase__							,    lowerCamelCase__							,    lowerCamelCase__							,    0						):
              return colored_vertices

       return []






