


"""simple docstring"""






from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload


class 			__lowerCamelCase     :

     '''simple docstring'''


     def __init__(					self			, __UpperCAmelCase = None							)				->							Tuple:
          if components is None:
               _a					= []
          _a					= list(__UpperCAmelCase							)


     def __len__(					self							)				->							Union[str, Any]:
          return len(self.__components							)


     def __str__(					self							)				->							List[str]:
          return "(" + ",".join(map(__UpperCAmelCase			, self.__components							)							) + ")"


     def __add__(					self			, __UpperCAmelCase							)				->							List[Any]:
          _a					= len(self							)
          if size == len(__UpperCAmelCase							):
               _a					= [self.__components[i] + other.component(__UpperCAmelCase							) for i in range(__UpperCAmelCase							)]
               return Vector(__UpperCAmelCase							)
          else:
               raise Exception('''must have the same size'''							)


     def __sub__(					self			, __UpperCAmelCase							)				->							Union[str, Any]:
          _a					= len(self							)
          if size == len(__UpperCAmelCase							):
               _a					= [self.__components[i] - other.component(__UpperCAmelCase							) for i in range(__UpperCAmelCase							)]
               return Vector(__UpperCAmelCase							)
          else:  # error case
               raise Exception('''must have the same size'''							)


     @overload
     def __mul__(					self			, __UpperCAmelCase							)				->							List[Any]:
          ...


     @overload
     def __mul__(					self			, __UpperCAmelCase							)				->							str:
          ...


     def __mul__(					self			, __UpperCAmelCase							)				->							Union[str, Any]:
          if isinstance(__UpperCAmelCase			, (float, int)							):
               _a					= [c * other for c in self.__components]
               return Vector(__UpperCAmelCase							)
          elif isinstance(__UpperCAmelCase			, __UpperCAmelCase							) and len(self							) == len(__UpperCAmelCase							):
               _a					= len(self							)
               _a					= [self.__components[i] * other.component(__UpperCAmelCase							) for i in range(__UpperCAmelCase							)]
               return sum(__UpperCAmelCase							)
          else:  # error case
               raise Exception('''invalid operand!'''							)


     def 							_UpperCAmelCase					(					self							)				->							Optional[Any]:
          return Vector(self.__components							)


     def 							_UpperCAmelCase					(					self			, __UpperCAmelCase							)				->							Any:
          if isinstance(__UpperCAmelCase			, __UpperCAmelCase							) and -len(self.__components							) <= i < len(self.__components							):
               return self.__components[i]
          else:
               raise Exception('''index out of range'''							)


     def 							_UpperCAmelCase					(					self			, __UpperCAmelCase			, __UpperCAmelCase							)				->							str:
          assert -len(self.__components							) <= pos < len(self.__components							)
          _a					= value


     def 							_UpperCAmelCase					(					self							)				->							Union[str, Any]:
          if len(self.__components							) == 0:
               raise Exception('''Vector is empty'''							)
          _a					= [c**2 for c in self.__components]
          return math.sqrt(sum(__UpperCAmelCase							)							)





     def 							_UpperCAmelCase					(					self			, __UpperCAmelCase			, __UpperCAmelCase = False							)				->							Optional[int]:
          _a					= self * other
          _a					= self.euclidean_length() * other.euclidean_length()
          if deg:
               return math.degrees(math.acos(num / den							)							)
          else:
               return math.acos(num / den							)







def 					A_      (      _lowerCAmelCase   :    int				):






     """simple docstring"""

     assert isinstance(_lowerCAmelCase,   _lowerCAmelCase				)
     return Vector([0] * dimension				)
def 					A_      (      _lowerCAmelCase   :    List[Any],   _lowerCAmelCase   :    List[Any]				):






     """simple docstring"""

     assert isinstance(_lowerCAmelCase,   _lowerCAmelCase				) and (isinstance(_lowerCAmelCase,   _lowerCAmelCase				))
     _a					= [0] * dimension
     _a					= 1
     return Vector(_lowerCAmelCase				)
def 					A_      (      _lowerCAmelCase   :    Tuple,   _lowerCAmelCase   :    Any,   _lowerCAmelCase   :    Optional[Any]				):






     """simple docstring"""

     assert (
         isinstance(_lowerCAmelCase,   _lowerCAmelCase				)
         and isinstance(_lowerCAmelCase,   _lowerCAmelCase				)
         and (isinstance(_lowerCAmelCase,   (int, float)				))
     )
     return x * scalar + y
def 					A_      (      _lowerCAmelCase   :    int,   _lowerCAmelCase   :    Tuple,   _lowerCAmelCase   :    Union[str, Any]				):






     """simple docstring"""

     random.seed(_lowerCAmelCase				)
     _a					= [random.randint(_lowerCAmelCase,   _lowerCAmelCase				) for _ in range(_lowerCAmelCase				)]
     return Vector(_lowerCAmelCase				)


class 			__lowerCamelCase     :

     '''simple docstring'''


     def __init__(					self			, __UpperCAmelCase			, __UpperCAmelCase			, __UpperCAmelCase							)				->							Optional[Any]:
          _a					= matrix
          _a					= w
          _a					= h


     def __str__(					self							)				->							Union[str, Any]:
          _a					= """"""
          for i in range(self.__height							):
               ans += "|"
               for j in range(self.__width							):
                    if j < self.__width - 1:
                         ans += str(self.__matrix[i][j]							) + ","
                    else:
                         ans += str(self.__matrix[i][j]							) + "|\n"
          return ans


     def __add__(					self			, __UpperCAmelCase							)				->							List[Any]:
          if self.__width == other.width() and self.__height == other.height():
               _a					= []
               for i in range(self.__height							):
                    _a					= [
                        self.__matrix[i][j] + other.component(__UpperCAmelCase			, __UpperCAmelCase							)
                        for j in range(self.__width							)
                    ]
                    matrix.append(__UpperCAmelCase							)
               return Matrix(__UpperCAmelCase			, self.__width			, self.__height							)
          else:
               raise Exception('''matrix must have the same dimension!'''							)


     def __sub__(					self			, __UpperCAmelCase							)				->							List[Any]:
          if self.__width == other.width() and self.__height == other.height():
               _a					= []
               for i in range(self.__height							):
                    _a					= [
                        self.__matrix[i][j] - other.component(__UpperCAmelCase			, __UpperCAmelCase							)
                        for j in range(self.__width							)
                    ]
                    matrix.append(__UpperCAmelCase							)
               return Matrix(__UpperCAmelCase			, self.__width			, self.__height							)
          else:
               raise Exception('''matrices must have the same dimension!'''							)


     @overload
     def __mul__(					self			, __UpperCAmelCase							)				->							Dict:
          ...


     @overload
     def __mul__(					self			, __UpperCAmelCase							)				->							int:
          ...


     def __mul__(					self			, __UpperCAmelCase							)				->							Optional[Any]:
          if isinstance(__UpperCAmelCase			, __UpperCAmelCase							):  # matrix-vector
               if len(__UpperCAmelCase							) == self.__width:
                    _a					= zero_vector(self.__height							)
                    for i in range(self.__height							):
                         _a					= [
                             self.__matrix[i][j] * other.component(__UpperCAmelCase							)
                             for j in range(self.__width							)
                         ]
                         ans.change_component(__UpperCAmelCase			, sum(__UpperCAmelCase							)							)
                    return ans
               else:
                    raise Exception(
                        '''vector must have the same size as the '''
                        '''number of columns of the matrix!'''							)
          elif isinstance(__UpperCAmelCase			, (int, float)							):  # matrix-scalar
               _a					= [
                   [self.__matrix[i][j] * other for j in range(self.__width							)]
                   for i in range(self.__height							)
               ]
               return Matrix(__UpperCAmelCase			, self.__width			, self.__height							)
          return None


     def 							_UpperCAmelCase					(					self							)				->							Tuple:
          return self.__height


     def 							_UpperCAmelCase					(					self							)				->							str:
          return self.__width


     def 							_UpperCAmelCase					(					self			, __UpperCAmelCase			, __UpperCAmelCase							)				->							int:
          if 0 <= x < self.__height and 0 <= y < self.__width:
               return self.__matrix[x][y]
          else:
               raise Exception('''change_component: indices out of bounds'''							)


     def 							_UpperCAmelCase					(					self			, __UpperCAmelCase			, __UpperCAmelCase			, __UpperCAmelCase							)				->							Optional[Any]:
          if 0 <= x < self.__height and 0 <= y < self.__width:
               _a					= value
          else:
               raise Exception('''change_component: indices out of bounds'''							)


     def 							_UpperCAmelCase					(					self			, __UpperCAmelCase			, __UpperCAmelCase							)				->							Dict:
          if self.__height != self.__width:
               raise Exception('''Matrix is not square'''							)
          _a					= self.__matrix[:x] + self.__matrix[x + 1 :]
          for i in range(len(__UpperCAmelCase							)							):
               _a					= minor[i][:y] + minor[i][y + 1 :]
          return Matrix(__UpperCAmelCase			, self.__width - 1			, self.__height - 1							).determinant()


     def 							_UpperCAmelCase					(					self			, __UpperCAmelCase			, __UpperCAmelCase							)				->							Tuple:
          if self.__height != self.__width:
               raise Exception('''Matrix is not square'''							)
          if 0 <= x < self.__height and 0 <= y < self.__width:
               return (-1) ** (x + y) * self.minor(__UpperCAmelCase			, __UpperCAmelCase							)
          else:
               raise Exception('''Indices out of bounds'''							)





     def 							_UpperCAmelCase					(					self							)				->							str:
          if self.__height != self.__width:
               raise Exception('''Matrix is not square'''							)
          if self.__height < 1:
               raise Exception('''Matrix has no element'''							)
          elif self.__height == 1:
               return self.__matrix[0][0]
          elif self.__height == 2:
               return (
                   self.__matrix[0][0] * self.__matrix[1][1]
                   - self.__matrix[0][1] * self.__matrix[1][0]
               )
          else:
               _a					= [
                   self.__matrix[0][y] * self.cofactor(0			, __UpperCAmelCase							) for y in range(self.__width							)
               ]
               return sum(__UpperCAmelCase							)







def 					A_      (      _lowerCAmelCase   :    int				):






     """simple docstring"""

     _a					= [[0] * n for _ in range(_lowerCAmelCase				)]
     return Matrix(_lowerCAmelCase,   _lowerCAmelCase,   _lowerCAmelCase				)

def 					A_      (      _lowerCAmelCase   :    Dict,   _lowerCAmelCase   :    Optional[Any],   _lowerCAmelCase   :    Optional[int],   _lowerCAmelCase   :    Any				):






     """simple docstring"""

     random.seed(_lowerCAmelCase				)
     _a					= [
         [random.randint(_lowerCAmelCase,   _lowerCAmelCase				) for _ in range(_lowerCAmelCase				)] for _ in range(_lowerCAmelCase				)
     ]
     return Matrix(_lowerCAmelCase,   _lowerCAmelCase,   _lowerCAmelCase				)

from scipy.stats import pearsonr

import datasets


_lowerCamelCase					   ="""
Pearson correlation coefficient and p-value for testing non-correlation.
The Pearson correlation coefficient measures the linear relationship between two datasets. The calculation of the p-value relies on the assumption that each dataset is normally distributed. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply an exact linear relationship. Positive correlations imply that as x increases, so does y. Negative correlations imply that as x increases, y decreases.
The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets.
"""


_lowerCamelCase					   ="""
Args:
    predictions (`list` of `int`): Predicted class labels, as returned by a model.
    references (`list` of `int`): Ground truth labels.
    return_pvalue (`boolean`): If `True`, returns the p-value, along with the correlation coefficient. If `False`, returns only the correlation coefficient. Defaults to `False`.

Returns:
    pearsonr (`float`): Pearson correlation coefficient. Minimum possible value is -1. Maximum possible value is 1. Values of 1 and -1 indicate exact linear positive and negative relationships, respectively. A value of 0 implies no correlation.
    p-value (`float`): P-value, which roughly indicates the probability of an The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets. Minimum possible value is 0. Maximum possible value is 1. Higher values indicate higher probabilities.

Examples:

    Example 1-A simple example using only predictions and references.
        >>> pearsonr_metric = datasets.load_metric(\"pearsonr\")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5])
        >>> print(round(results['pearsonr'], 2))
        -0.74

    Example 2-The same as Example 1, but that also returns the `p-value`.
        >>> pearsonr_metric = datasets.load_metric(\"pearsonr\")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5], return_pvalue=True)
        >>> print(sorted(list(results.keys())))
        ['p-value', 'pearsonr']
        >>> print(round(results['pearsonr'], 2))
        -0.74
        >>> print(round(results['p-value'], 2))
        0.15
"""


_lowerCamelCase					   ="""
@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, Ilhan 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, Antonio 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      ):
       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.pearsonr.html"""]    ,  )






      def 						UpperCamelCase__							(      self    ,  __magic_name__    ,  __magic_name__    ,  __magic_name__=False      ):
       if return_pvalue:
        lowerCamelCase		:	Optional[Any]							=      pearsonr(__magic_name__    ,  __magic_name__      )
        return {"pearsonr": results[0], "p-value": results[1]}
       else:
        return {"pearsonr": float(pearsonr(__magic_name__    ,  __magic_name__      )[0]      )}




