






'''simple docstring'''




from scipy.stats import spearmanr

import datasets


__lowerCamelCase   :					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   :					int   							=					'''
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   :					List[str]   							=					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							):
							"""simple docstring"""




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


										'''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 							_A	(		self			:Optional[int]       ,							lowerCAmelCase__			:Optional[Any]       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:Optional[Any]=False				)				->  List[Any]:


										'''simple docstring'''




										snake_case_				:					Optional[Any]   =       spearmanr(lowerCAmelCase__       ,							lowerCAmelCase__				)
										if return_pvalue:
													return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
										else:
													return {"spearmanr": results[0]}













'''simple docstring'''




from collections import deque
from math import floor
from random import random
from time import time







class    A_	:
							"""simple docstring"""




							def __init__(		self			:Dict				)				->  List[str]:


										'''simple docstring'''




										snake_case_				:					int   =       {}

							def 							_A	(		self			:Any       ,							lowerCAmelCase__			:Optional[Any]       ,							lowerCAmelCase__			:Tuple       ,							lowerCAmelCase__			:Optional[Any]=1				)				->  Any:


										'''simple docstring'''




										if self.graph.get(lowerCAmelCase__				):
													if self.graph[u].count([w, v]				) == 0:
																self.graph[u].append([w, v]				)
										else:
													snake_case_				:					Optional[int]   =       [[w, v]]
										if not self.graph.get(lowerCAmelCase__				):
													snake_case_				:					Dict   =       []

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


										'''simple docstring'''




										return list(self.graph				)

							def 							_A	(		self			:str       ,							lowerCAmelCase__			:Any       ,							lowerCAmelCase__			:int				)				->  List[Any]:


										'''simple docstring'''




										if self.graph.get(lowerCAmelCase__				):
													for _ in self.graph[u]:
																if _[1] == v:
																			self.graph[u].remove(lowerCAmelCase__				)

							def 							_A	(		self			:List[str]       ,							lowerCAmelCase__			:Optional[Any]=-2       ,							lowerCAmelCase__			:str=-1				)				->  str:


										'''simple docstring'''




										if s == d:
													return []
										snake_case_				:					str   =       []
										snake_case_				:					Optional[int]   =       []
										if s == -2:
													snake_case_				:					List[Any]   =       list(self.graph				)[0]
										stack.append(lowerCAmelCase__				)
										visited.append(lowerCAmelCase__				)
										snake_case_				:					Dict   =       s

										while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]				) != 0:
																snake_case_				:					str   =       s
																for node in self.graph[s]:
																			if visited.count(node[1]				) < 1:
																						if node[1] == d:
																									visited.append(lowerCAmelCase__				)
																									return visited
																						else:
																									stack.append(node[1]				)
																									visited.append(node[1]				)
																									snake_case_				:					str   =       node[1]
																									break

            # check if all the children are visited
													if s == ss:
																stack.pop()
																if len(lowerCAmelCase__				) != 0:
																			snake_case_				:					Union[str, Any]   =       stack[len(lowerCAmelCase__				) - 1]
													else:
																snake_case_				:					Optional[Any]   =       ss

													# check if se have reached the starting point
													if len(lowerCAmelCase__				) == 0:
																return visited

							def 							_A	(		self			:Tuple       ,							lowerCAmelCase__			:int=-1				)				->  int:


										'''simple docstring'''




										if c == -1:
													snake_case_				:					Any   =       floor(random() * 10_000				) + 10
										for i in range(lowerCAmelCase__				):
													# every vertex has max 100 edges
													for _ in range(floor(random() * 102				) + 1				):
																snake_case_				:					Optional[Any]   =       floor(random() * c				) + 1
																if n != i:
																			self.add_pair(lowerCAmelCase__       ,							lowerCAmelCase__       ,							1				)

							def 							_A	(		self			:Tuple       ,							lowerCAmelCase__			:Dict=-2				)				->  Dict:


										'''simple docstring'''




										snake_case_				:					Union[str, Any]   =       deque()
										snake_case_				:					Optional[Any]   =       []
										if s == -2:
													snake_case_				:					Tuple   =       list(self.graph				)[0]
										d.append(lowerCAmelCase__				)
										visited.append(lowerCAmelCase__				)
										while d:
													snake_case_				:					Optional[int]   =       d.popleft()
													if len(self.graph[s]				) != 0:
																for node in self.graph[s]:
																			if visited.count(node[1]				) < 1:
																						d.append(node[1]				)
																						visited.append(node[1]				)
										return visited

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


										'''simple docstring'''




										snake_case_				:					Tuple   =       0
										for x in self.graph:
													for y in self.graph[x]:
																if y[1] == u:
																			count += 1
										return count

							def 							_A	(		self			:Any       ,							lowerCAmelCase__			:int				)				->  Optional[Any]:


										'''simple docstring'''




										return len(self.graph[u]				)

							def 							_A	(		self			:Tuple       ,							lowerCAmelCase__			:List[str]=-2				)				->  Optional[Any]:


										'''simple docstring'''




										snake_case_				:					str   =       []
										snake_case_				:					str   =       []
										if s == -2:
													snake_case_				:					Optional[Any]   =       list(self.graph				)[0]
										stack.append(lowerCAmelCase__				)
										visited.append(lowerCAmelCase__				)
										snake_case_				:					int   =       s
										snake_case_				:					Optional[int]   =       []

										while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]				) != 0:
																snake_case_				:					List[Any]   =       s
																for node in self.graph[s]:
																			if visited.count(node[1]				) < 1:
																						stack.append(node[1]				)
																						visited.append(node[1]				)
																						snake_case_				:					List[str]   =       node[1]
																						break

            # check if all the children are visited
													if s == ss:
																sorted_nodes.append(stack.pop()				)
																if len(lowerCAmelCase__				) != 0:
																			snake_case_				:					int   =       stack[len(lowerCAmelCase__				) - 1]
													else:
																snake_case_				:					Union[str, Any]   =       ss

													# check if se have reached the starting point
													if len(lowerCAmelCase__				) == 0:
																return sorted_nodes

							def 							_A	(		self			:Dict				)				->  Any:


										'''simple docstring'''




										snake_case_				:					Dict   =       []
										snake_case_				:					Any   =       []
										snake_case_				:					str   =       list(self.graph				)[0]
										stack.append(lowerCAmelCase__				)
										visited.append(lowerCAmelCase__				)
										snake_case_				:					Optional[int]   =       -2
										snake_case_				:					Any   =       []
										snake_case_				:					List[Any]   =       s
										snake_case_				:					int   =       False
										snake_case_				:					Optional[int]   =       set()

										while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]				) != 0:
																snake_case_				:					List[Any]   =       s
																for node in self.graph[s]:
																			if (
																			    visited.count(node[1]				) > 0
																			    and node[1] != parent
																			    and indirect_parents.count(node[1]				) > 0
																			    and not on_the_way_back
																			):
																						snake_case_				:					Any   =       len(lowerCAmelCase__				) - 1
																						while len_stack >= 0:
																									if stack[len_stack] == node[1]:
																												anticipating_nodes.add(node[1]				)
																												break
																									else:
																												anticipating_nodes.add(stack[len_stack]				)
																												len_stack -= 1
																			if visited.count(node[1]				) < 1:
																						stack.append(node[1]				)
																						visited.append(node[1]				)
																						snake_case_				:					Optional[int]   =       node[1]
																						break

            # check if all the children are visited
													if s == ss:
																stack.pop()
																snake_case_				:					Optional[Any]   =       True
																if len(lowerCAmelCase__				) != 0:
																			snake_case_				:					Optional[Any]   =       stack[len(lowerCAmelCase__				) - 1]
													else:
																snake_case_				:					str   =       False
																indirect_parents.append(lowerCAmelCase__				)
																snake_case_				:					List[str]   =       s
																snake_case_				:					Optional[int]   =       ss

													# check if se have reached the starting point
													if len(lowerCAmelCase__				) == 0:
																return list(lowerCAmelCase__				)

							def 							_A	(		self			:Tuple				)				->  List[str]:


										'''simple docstring'''




										snake_case_				:					List[Any]   =       []
										snake_case_				:					Tuple   =       []
										snake_case_				:					List[str]   =       list(self.graph				)[0]
										stack.append(lowerCAmelCase__				)
										visited.append(lowerCAmelCase__				)
										snake_case_				:					str   =       -2
										snake_case_				:					List[str]   =       []
										snake_case_				:					List[Any]   =       s
										snake_case_				:					List[str]   =       False
										snake_case_				:					Dict   =       set()

										while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]				) != 0:
																snake_case_				:					List[Any]   =       s
																for node in self.graph[s]:
																			if (
																			    visited.count(node[1]				) > 0
																			    and node[1] != parent
																			    and indirect_parents.count(node[1]				) > 0
																			    and not on_the_way_back
																			):
																						snake_case_				:					Any   =       len(lowerCAmelCase__				) - 1
																						while len_stack_minus_one >= 0:
																									if stack[len_stack_minus_one] == node[1]:
																												anticipating_nodes.add(node[1]				)
																												break
																									else:
																												return True
																			if visited.count(node[1]				) < 1:
																						stack.append(node[1]				)
																						visited.append(node[1]				)
																						snake_case_				:					str   =       node[1]
																						break

            # check if all the children are visited
													if s == ss:
																stack.pop()
																snake_case_				:					Tuple   =       True
																if len(lowerCAmelCase__				) != 0:
																			snake_case_				:					List[Any]   =       stack[len(lowerCAmelCase__				) - 1]
													else:
																snake_case_				:					Optional[int]   =       False
																indirect_parents.append(lowerCAmelCase__				)
																snake_case_				:					int   =       s
																snake_case_				:					Union[str, Any]   =       ss

													# check if se have reached the starting point
													if len(lowerCAmelCase__				) == 0:
																return False

							def 							_A	(		self			:Optional[int]       ,							lowerCAmelCase__			:Optional[int]=-2       ,							lowerCAmelCase__			:Tuple=-1				)				->  str:


										'''simple docstring'''




										snake_case_				:					Optional[int]   =       time()
										self.dfs(lowerCAmelCase__       ,							lowerCAmelCase__				)
										snake_case_				:					Optional[Any]   =       time()
										return end - begin






							def 							_A	(		self			:Any       ,							lowerCAmelCase__			:Tuple=-2				)				->  Optional[Any]:


										'''simple docstring'''




										snake_case_				:					Any   =       time()
										self.bfs(lowerCAmelCase__				)
										snake_case_				:					Any   =       time()
										return end - begin







class    A_	:
							"""simple docstring"""




							def __init__(		self			:Tuple				)				->  List[str]:


										'''simple docstring'''




										snake_case_				:					Optional[Any]   =       {}

							def 							_A	(		self			:str       ,							lowerCAmelCase__			:Dict       ,							lowerCAmelCase__			:List[Any]       ,							lowerCAmelCase__			:Union[str, Any]=1				)				->  str:


										'''simple docstring'''




										if self.graph.get(lowerCAmelCase__				):
													# if there already is a edge
													if self.graph[u].count([w, v]				) == 0:
																self.graph[u].append([w, v]				)
										else:
													# if u does not exist
													snake_case_				:					str   =       [[w, v]]
										# add the other way
										if self.graph.get(lowerCAmelCase__				):
													# if there already is a edge
													if self.graph[v].count([w, u]				) == 0:
																self.graph[v].append([w, u]				)
										else:
													# if u does not exist
													snake_case_				:					List[str]   =       [[w, u]]

							def 							_A	(		self			:Dict       ,							lowerCAmelCase__			:Tuple       ,							lowerCAmelCase__			:Optional[Any]				)				->  Optional[Any]:


										'''simple docstring'''




										if self.graph.get(lowerCAmelCase__				):
													for _ in self.graph[u]:
																if _[1] == v:
																			self.graph[u].remove(lowerCAmelCase__				)
        # the other way round
										if self.graph.get(lowerCAmelCase__				):
													for _ in self.graph[v]:
																if _[1] == u:
																			self.graph[v].remove(lowerCAmelCase__				)

							def 							_A	(		self			:Optional[Any]       ,							lowerCAmelCase__			:Optional[Any]=-2       ,							lowerCAmelCase__			:Optional[int]=-1				)				->  int:


										'''simple docstring'''




										if s == d:
													return []
										snake_case_				:					Any   =       []
										snake_case_				:					Dict   =       []
										if s == -2:
													snake_case_				:					Optional[int]   =       list(self.graph				)[0]
										stack.append(lowerCAmelCase__				)
										visited.append(lowerCAmelCase__				)
										snake_case_				:					Tuple   =       s

										while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]				) != 0:
																snake_case_				:					List[str]   =       s
																for node in self.graph[s]:
																			if visited.count(node[1]				) < 1:
																						if node[1] == d:
																									visited.append(lowerCAmelCase__				)
																									return visited
																						else:
																									stack.append(node[1]				)
																									visited.append(node[1]				)
																									snake_case_				:					str   =       node[1]
																									break

            # check if all the children are visited
													if s == ss:
																stack.pop()
																if len(lowerCAmelCase__				) != 0:
																			snake_case_				:					Optional[Any]   =       stack[len(lowerCAmelCase__				) - 1]
													else:
																snake_case_				:					str   =       ss

													# check if se have reached the starting point
													if len(lowerCAmelCase__				) == 0:
																return visited

							def 							_A	(		self			:Optional[int]       ,							lowerCAmelCase__			:str=-1				)				->  List[Any]:


										'''simple docstring'''




										if c == -1:
													snake_case_				:					Optional[int]   =       floor(random() * 10_000				) + 10
										for i in range(lowerCAmelCase__				):
													# every vertex has max 100 edges
													for _ in range(floor(random() * 102				) + 1				):
																snake_case_				:					str   =       floor(random() * c				) + 1
																if n != i:
																			self.add_pair(lowerCAmelCase__       ,							lowerCAmelCase__       ,							1				)

							def 							_A	(		self			:Any       ,							lowerCAmelCase__			:Optional[Any]=-2				)				->  List[Any]:


										'''simple docstring'''




										snake_case_				:					List[str]   =       deque()
										snake_case_				:					Optional[Any]   =       []
										if s == -2:
													snake_case_				:					List[Any]   =       list(self.graph				)[0]
										d.append(lowerCAmelCase__				)
										visited.append(lowerCAmelCase__				)
										while d:
													snake_case_				:					Optional[int]   =       d.popleft()
													if len(self.graph[s]				) != 0:
																for node in self.graph[s]:
																			if visited.count(node[1]				) < 1:
																						d.append(node[1]				)
																						visited.append(node[1]				)
										return visited

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


										'''simple docstring'''




										return len(self.graph[u]				)

							def 							_A	(		self			:Union[str, Any]				)				->  Dict:


										'''simple docstring'''




										snake_case_				:					Any   =       []
										snake_case_				:					Optional[Any]   =       []
										snake_case_				:					Optional[Any]   =       list(self.graph				)[0]
										stack.append(lowerCAmelCase__				)
										visited.append(lowerCAmelCase__				)
										snake_case_				:					Tuple   =       -2
										snake_case_				:					Optional[int]   =       []
										snake_case_				:					Tuple   =       s
										snake_case_				:					Optional[Any]   =       False
										snake_case_				:					Optional[int]   =       set()

										while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]				) != 0:
																snake_case_				:					Optional[Any]   =       s
																for node in self.graph[s]:
																			if (
																			    visited.count(node[1]				) > 0
																			    and node[1] != parent
																			    and indirect_parents.count(node[1]				) > 0
																			    and not on_the_way_back
																			):
																						snake_case_				:					Optional[int]   =       len(lowerCAmelCase__				) - 1
																						while len_stack >= 0:
																									if stack[len_stack] == node[1]:
																												anticipating_nodes.add(node[1]				)
																												break
																									else:
																												anticipating_nodes.add(stack[len_stack]				)
																												len_stack -= 1
																			if visited.count(node[1]				) < 1:
																						stack.append(node[1]				)
																						visited.append(node[1]				)
																						snake_case_				:					Tuple   =       node[1]
																						break

            # check if all the children are visited
													if s == ss:
																stack.pop()
																snake_case_				:					Optional[int]   =       True
																if len(lowerCAmelCase__				) != 0:
																			snake_case_				:					Optional[Any]   =       stack[len(lowerCAmelCase__				) - 1]
													else:
																snake_case_				:					Optional[int]   =       False
																indirect_parents.append(lowerCAmelCase__				)
																snake_case_				:					List[Any]   =       s
																snake_case_				:					Dict   =       ss

													# check if se have reached the starting point
													if len(lowerCAmelCase__				) == 0:
																return list(lowerCAmelCase__				)

							def 							_A	(		self			:Optional[Any]				)				->  Tuple:


										'''simple docstring'''




										snake_case_				:					Optional[Any]   =       []
										snake_case_				:					int   =       []
										snake_case_				:					List[str]   =       list(self.graph				)[0]
										stack.append(lowerCAmelCase__				)
										visited.append(lowerCAmelCase__				)
										snake_case_				:					Tuple   =       -2
										snake_case_				:					int   =       []
										snake_case_				:					int   =       s
										snake_case_				:					Optional[Any]   =       False
										snake_case_				:					List[Any]   =       set()

										while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]				) != 0:
																snake_case_				:					Union[str, Any]   =       s
																for node in self.graph[s]:
																			if (
																			    visited.count(node[1]				) > 0
																			    and node[1] != parent
																			    and indirect_parents.count(node[1]				) > 0
																			    and not on_the_way_back
																			):
																						snake_case_				:					Tuple   =       len(lowerCAmelCase__				) - 1
																						while len_stack_minus_one >= 0:
																									if stack[len_stack_minus_one] == node[1]:
																												anticipating_nodes.add(node[1]				)
																												break
																									else:
																												return True
																			if visited.count(node[1]				) < 1:
																						stack.append(node[1]				)
																						visited.append(node[1]				)
																						snake_case_				:					Optional[Any]   =       node[1]
																						break

            # check if all the children are visited
													if s == ss:
																stack.pop()
																snake_case_				:					Optional[Any]   =       True
																if len(lowerCAmelCase__				) != 0:
																			snake_case_				:					Tuple   =       stack[len(lowerCAmelCase__				) - 1]
													else:
																snake_case_				:					Optional[int]   =       False
																indirect_parents.append(lowerCAmelCase__				)
																snake_case_				:					Union[str, Any]   =       s
																snake_case_				:					Tuple   =       ss

													# check if se have reached the starting point
													if len(lowerCAmelCase__				) == 0:
																return False

							def 							_A	(		self			:Any				)				->  Tuple:


										'''simple docstring'''




										return list(self.graph				)

							def 							_A	(		self			:Optional[Any]       ,							lowerCAmelCase__			:Tuple=-2       ,							lowerCAmelCase__			:Optional[int]=-1				)				->  str:


										'''simple docstring'''




										snake_case_				:					List[str]   =       time()
										self.dfs(lowerCAmelCase__       ,							lowerCAmelCase__				)
										snake_case_				:					List[Any]   =       time()
										return end - begin






							def 							_A	(		self			:Union[str, Any]       ,							lowerCAmelCase__			:List[Any]=-2				)				->  int:


										'''simple docstring'''




										snake_case_				:					List[str]   =       time()
										self.bfs(lowerCAmelCase__				)
										snake_case_				:					Tuple   =       time()
										return end - begin




