





import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


__lowerCamelCase	:					List[Any]			  =					threading.Lock()
__lowerCamelCase	:					Optional[logging.Handler]			  =					None

__lowerCamelCase	:					int			  =					{
    """debug""": logging.DEBUG,
    """info""": logging.INFO,
    """warning""": logging.WARNING,
    """error""": logging.ERROR,
    """critical""": logging.CRITICAL,
}

__lowerCamelCase	:					List[Any]			  =					logging.WARNING

__lowerCamelCase	:					Any			  =					True



def 		A_    (					)						->			Optional[Any]:
 UpperCamelCase     : str	     =       os.getenv("TRANSFORMERS_VERBOSITY"							,       _lowerCAmelCase					)
 if env_level_str:
  if env_level_str in log_levels:
   return log_levels[env_level_str]
  else:
   logging.getLogger().warning(
       F"""Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, """
       F"""has to be one of: { ", ".join(log_levels.keys()					) }"""					)
 return _default_log_level



def 		A_    (					)						->			str:
 return __name__.split("."					)[0]



def 		A_    (					)						->			logging.Logger:
 return logging.getLogger(_get_library_name()					)



def 		A_    (					)						->			None:
 global _default_handler

 with _lock:
  if _default_handler:
   # This library has already configured the library root logger.
   return
  UpperCamelCase     : str	     =       logging.StreamHandler()  # Set sys.stderr as stream.
  UpperCamelCase     : Dict	     =       sys.stderr.flush

  # Apply our default configuration to the library root logger.
  UpperCamelCase     : List[Any]	     =       _get_library_root_logger()
  library_root_logger.addHandler(_default_handler					)
  library_root_logger.setLevel(_get_default_logging_level()					)
  UpperCamelCase     : List[str]	     =       False



def 		A_    (					)						->			None:
 global _default_handler

 with _lock:
  if not _default_handler:
   return

  UpperCamelCase     : Optional[int]	     =       _get_library_root_logger()
  library_root_logger.removeHandler(_default_handler					)
  library_root_logger.setLevel(logging.NOTSET					)
  UpperCamelCase     : Optional[int]	     =       None



def 		A_    (					)						->			Optional[Any]:
 return log_levels



def 		A_    (					_lowerCAmelCase = None					)						->			logging.Logger:

 if name is None:
  UpperCamelCase     : Optional[Any]	     =       _get_library_name()

 _configure_library_root_logger()
 return logging.getLogger(_lowerCAmelCase					)



def 		A_    (					)						->			int:
 _configure_library_root_logger()
 return _get_library_root_logger().getEffectiveLevel()



def 		A_    (					_lowerCAmelCase					)						->			None:
 _configure_library_root_logger()
 _get_library_root_logger().setLevel(_lowerCAmelCase					)



def 		A_    (					)						->			Any:
 return set_verbosity(_lowerCAmelCase					)



def 		A_    (					)						->			Any:
 return set_verbosity(_lowerCAmelCase					)



def 		A_    (					)						->			int:
 return set_verbosity(_lowerCAmelCase					)



def 		A_    (					)						->			Dict:
 return set_verbosity(_lowerCAmelCase					)



def 		A_    (					)						->			None:
 _configure_library_root_logger()

 assert _default_handler is not None
 _get_library_root_logger().removeHandler(_default_handler					)



def 		A_    (					)						->			None:
 _configure_library_root_logger()

 assert _default_handler is not None
 _get_library_root_logger().addHandler(_default_handler					)



def 		A_    (					_lowerCAmelCase					)						->			None:
 _configure_library_root_logger()

 assert handler is not None
 _get_library_root_logger().addHandler(_lowerCAmelCase					)



def 		A_    (					_lowerCAmelCase					)						->			None:
 _configure_library_root_logger()

 assert handler is not None and handler not in _get_library_root_logger().handlers
 _get_library_root_logger().removeHandler(_lowerCAmelCase					)



def 		A_    (					)						->			None:
 _configure_library_root_logger()
 UpperCamelCase     : Tuple	     =       False



def 		A_    (					)						->			None:
 _configure_library_root_logger()
 UpperCamelCase     : int	     =       True



def 		A_    (					)						->			None:
 UpperCamelCase     : Tuple	     =       _get_library_root_logger().handlers

 for handler in handlers:
  UpperCamelCase     : int	     =       logging.Formatter("[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"					)
  handler.setFormatter(_lowerCAmelCase					)



def 		A_    (					)						->			None:
 UpperCamelCase     : str	     =       _get_library_root_logger().handlers

 for handler in handlers:
  handler.setFormatter(_lowerCAmelCase					)



def 		A_    (					self							,       *_lowerCAmelCase							,       **_lowerCAmelCase					)						->			Optional[Any]:
 UpperCamelCase     : int	     =       os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS"							,       _lowerCAmelCase					)
 if no_advisory_warnings:
  return
 self.warning(*_lowerCAmelCase							,       **_lowerCAmelCase					)


__lowerCamelCase	:					Optional[Any]			  =					warning_advice



@functools.lru_cache(_lowerCAmelCase					)
def 		A_    (					self							,       *_lowerCAmelCase							,       **_lowerCAmelCase					)						->			Optional[int]:
 self.warning(*_lowerCAmelCase							,       **_lowerCAmelCase					)


__lowerCamelCase	:					Dict			  =					warning_once



class  A__       :





      def __init__(			self	,							*A_	,							**A_       ):  # pylint: disable=unused-argument
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       args[0] if args else None





      def __iter__(			self       ):
       '''simple docstring'''




       return iter(self._iterator       )





      def __getattr__(			self	,							A_       ):
       '''simple docstring'''




       def empty_fn(*A_	,							**A_       ):  # pylint: disable=unused-argument
        return

       return empty_fn





      def __enter__(			self       ):
       '''simple docstring'''




       return self





      def __exit__(			self	,							A_	,							A_	,							A_       ):
       '''simple docstring'''




       return



class  A__       :





      def __call__(			self	,							*A_	,							**A_       ):
       '''simple docstring'''




       if _tqdm_active:
        return tqdm_lib.tqdm(*A_	,							**A_       )
       else:
        return EmptyTqdm(*A_	,							**A_       )





      def 	__UpperCamelCase(			self	,							*A_	,							**A_       ):
       '''simple docstring'''




       UpperCamelCase     : Dict	     =       None
       if _tqdm_active:
        return tqdm_lib.tqdm.set_lock(*A_	,							**A_       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       if _tqdm_active:
        return tqdm_lib.tqdm.get_lock()


__lowerCamelCase	:					str			  =					_tqdm_cls()



def 		A_    (					)						->			bool:
 global _tqdm_active
 return bool(_tqdm_active					)



def 		A_    (					)						->			List[str]:
 global _tqdm_active
 UpperCamelCase     : Tuple	     =       True
 hf_hub_utils.enable_progress_bars()



def 		A_    (					)						->			List[str]:
 global _tqdm_active
 UpperCamelCase     : List[Any]	     =       False
 hf_hub_utils.disable_progress_bars()







from scipy.stats import spearmanr

import datasets


__lowerCamelCase	:					List[str]			  =					"""
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
"""

__lowerCamelCase	:					List[Any]			  =					"""
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {'spearmanr': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results['spearmanr'])
        -0.7
        >>> print(round(results['spearmanr_pvalue'], 2))
        0.19
"""

__lowerCamelCase	:					Optional[int]			  =					r"""\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
"""



@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION	,       _KWARGS_DESCRIPTION      )
class  A__       (	datasets.Metric      ):





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       return datasets.MetricInfo(
           description=_DESCRIPTION	,							citation=_CITATION	,							inputs_description=_KWARGS_DESCRIPTION	,							features=datasets.Features(
               {
                   "predictions": datasets.Value("float"       ),
                   "references": datasets.Value("float"       ),
               }       )	,							reference_urls=["https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html"]	,							)





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_=False       ):
       '''simple docstring'''




       UpperCamelCase     : Tuple	     =       spearmanr(A_	,							A_       )
       if return_pvalue:
        return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
       else:
        return {"spearmanr": results[0]}
