


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


__lowerCAmelCase	: str  				=(
    '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        _UpperCamelCase							(      lowercase__    ,       lowercase__      ):
						warnings.warn(lowercase__    ,       lowercase__      )
						requires_backends(lowercase__    ,       '''sklearn'''      )
						return (preds == labels).mean()


def        _UpperCamelCase							(      lowercase__    ,       lowercase__      ):
						warnings.warn(lowercase__    ,       lowercase__      )
						requires_backends(lowercase__    ,       '''sklearn'''      )
						__SCREAMING_SNAKE_CASE						:     str					=		simple_accuracy(lowercase__    ,       lowercase__      )
						__SCREAMING_SNAKE_CASE						:     Dict					=		fa_score(y_true=lowercase__    ,       y_pred=lowercase__      )
						return {
						    "acc": acc,
						    "f1": fa,
						    "acc_and_f1": (acc + fa) / 2,
						}


def        _UpperCamelCase							(      lowercase__    ,       lowercase__      ):
						warnings.warn(lowercase__    ,       lowercase__      )
						requires_backends(lowercase__    ,       '''sklearn'''      )
						__SCREAMING_SNAKE_CASE						:     List[str]					=		pearsonr(lowercase__    ,       lowercase__      )[0]
						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		spearmanr(lowercase__    ,       lowercase__      )[0]
						return {
						    "pearson": pearson_corr,
						    "spearmanr": spearman_corr,
						    "corr": (pearson_corr + spearman_corr) / 2,
						}


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


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




import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812






def 							__lowercase   ( ):
							print('Making key files...'   )
							make_key_files('rsa'					,    1_0_2_4   )
							print('Key files generation successful.'   )






def 							__lowercase   ( __lowerCAmelCase							:				int   ):
							print('Generating prime p...'   )
							a__             =     rabinMiller.generate_large_prime(__lowerCAmelCase   )
							print('Generating prime q...'   )
							a__             =     rabinMiller.generate_large_prime(__lowerCAmelCase   )
							a__             =     p * q

							print('Generating e that is relatively prime to (p - 1) * (q - 1)...'   )
							while True:
														a__             =     random.randrange(2 ** (key_size - 1)					,    2 ** (key_size)   )
														if cryptoMath.gcd(__lowerCAmelCase					,    (p - 1) * (q - 1)   ) == 1:
																					break

							print('Calculating d that is mod inverse of e...'   )
							a__             =     cryptoMath.find_mod_inverse(__lowerCAmelCase					,    (p - 1) * (q - 1)   )

							a__             =     (n, e)
							a__             =     (n, d)
							return (public_key, private_key)






def 							__lowercase   ( __lowerCAmelCase							:				str					,    __lowerCAmelCase							:				int   ):
							if os.path.exists(F'{name}_pubkey.txt'   ) or os.path.exists(F'{name}_privkey.txt'   ):
														print('\nWARNING:'   )
														print(
														    F'"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'
														    'Use a different name or delete these files and re-run this program.'   )
														sys.exit()

							a__      ,					a__             =     generate_key(__lowerCAmelCase   )
							print(F'\nWriting public key to file {name}_pubkey.txt...'   )
							with open(F'{name}_pubkey.txt'					,    'w'   ) as out_file:
														out_file.write(F'{key_size},{public_key[0]},{public_key[1]}'   )

							print(F'Writing private key to file {name}_privkey.txt...'   )
							with open(F'{name}_privkey.txt'					,    'w'   ) as out_file:
														out_file.write(F'{key_size},{private_key[0]},{private_key[1]}'   )


if __name__ == "__main__":
						main()




