o
    ְi                     @   s^   d dl Z d dlZd dlZd dlZd dlmZ dddddZddd	Z		dddddZdS )    N)_coreTdtypec          	      C   s   |dus|durt dt t| |||d}zt|}W n ty*   ||  Y S w t|j}||dddf  }||dddf  }tj	|jdd|jd t
|r`tj	|jdd|jd |S )a:  Returns the Pearson product-moment correlation coefficients of an array.

    Args:
        a (cupy.ndarray): Array to compute the Pearson product-moment
            correlation coefficients.
        y (cupy.ndarray): An additional set of variables and observations.
        rowvar (bool): If ``True``, then each row represents a variable, with
            observations in the columns. Otherwise, the relationship is
            transposed.
        bias (None): Has no effect, do not use.
        ddof (None): Has no effect, do not use.
        dtype: Data type specifier. By default, the return data-type will have
            at least `numpy.float64` precision.

    Returns:
        cupy.ndarray: The Pearson product-moment correlation coefficients of
        the input array.

    .. seealso:: :func:`numpy.corrcoef`

    Nz/bias and ddof have no effect and are deprecatedr      )out)warningswarnDeprecationWarningcovcupydiag
ValueErrorsqrtrealclipiscomplexobjimag)	ayrowvarbiasddofr   r   dstddev r   P/home/ubuntu/.local/lib/python3.10/site-packages/cupy/_statistics/correlation.pycorrcoef
   s"   
r   validc                 C   s   | j dks
|j dkrtd| jdks|jdkrtdtjj| ||}|dkr;tjj| | ddd |}|S |dkrQtjj	| | ddd |}|S td	)
ad  Returns the cross-correlation of two 1-dimensional sequences.

    Args:
        a (cupy.ndarray): first 1-dimensional input.
        v (cupy.ndarray): second 1-dimensional input.
        mode (str, optional): `valid`, `same`, `full`

    Returns:
        cupy.ndarray: Discrete cross-correlation of a and v.

    .. seealso:: :func:`numpy.correlate`

    r   zArray arguments cannot be emptyr   z!object too deep for desired arraydirectNr   fftzUnsupported method)
sizer   ndimr   _mathmisc_choose_conv_method_dot_convolveconj_fft_convolve)r   vmodemethodr   r   r   r   	correlate5   s     r,   Fc                C   s  |dur|t |krtd| jdkrtd|du r>|du r(t| jtj}n|jdkr1tdttj| j|jtjf}t	j
| d|d}|sR|jd dkrR|j}|jd dkrbt	
g ddS |durt	j
|d	d|d
}|s{|jd dkr{|j}tj||fdd}|du r|rdnd}d}	|durt|t	jstd|jjdvrtd|jtd}|jdkrtd|jd |jd krtd|}	|durt|t	jstd|jtd}|jdkrtd|jd |jd krtd|	du r|}	n|	|9 }	t	j|d|	dd\}
}|d }|	du r|jd | }n|dkr!|}n|du r+|| }n||t|	|  |  }|dkrFtjdtdd d}||jdddddf 8 }|	du r]|j}n||	 j}|| dt	|  }| S )ap  Returns the covariance matrix of an array.

    This function currently does not support ``fweights`` and ``aweights``
    options.

    Args:
        a (cupy.ndarray): Array to compute covariance matrix.
        y (cupy.ndarray): An additional set of variables and observations.
        rowvar (bool): If ``True``, then each row represents a variable, with
            observations in the columns. Otherwise, the relationship is
            transposed.
        bias (bool): If ``False``, normalization is by ``(N - 1)``, where N is
            the number of observations given (unbiased estimate). If ``True``,
            then normalization is by ``N``.
        ddof (int): If not ``None`` the default value implied by bias is
            overridden. Note that ``ddof=1`` will return the unbiased estimate
            and ``ddof=0`` will return the simple average.

        fweights (cupy.ndarray, int): 1-D array of integer frequency weights.
            the number of times each observation vector should be repeated.
            It is required that fweights >= 0. However, the function will not
            error when fweights < 0 for performance reasons.
        aweights (cupy.ndarray): 1-D array of observation vector weights.
            These relative weights are typically large for observations
            considered "important" and smaller for observations considered
            less "important". If ``ddof=0`` the array of weights can be used
            to assign probabilities to observation vectors.
            It is required that aweights >= 0. However, the function will not
            error when aweights < 0 for performance reasons.
        dtype: Data type specifier. By default, the return data-type will have
            at least `numpy.float64` precision.

    Returns:
        cupy.ndarray: The covariance matrix of the input array.

    .. seealso:: :func:`numpy.cov`

    Nzddof must be integer   zInput must be <= 2-dzy must be <= 2-d)ndminr   r   r   F)copyr.   r   )axiszfweights must be a cupy.ndarray
bBhHiIlLqQzfweights must be integerr   z'cannot handle multidimensional fweightsz,incompatible numbers of samples and fweightszaweights must be a cupy.ndarrayz'cannot handle multidimensional aweightsz,incompatible numbers of samples and aweightsT)r0   weightsreturnedz!Degrees of freedom <= 0 for slice)
stacklevelg        ) intr   r"   numpypromote_typesr   float64	functoolsreducer   arrayshapeTreshaper   concatenate_method
isinstancendarray	TypeErrorcharastypefloatRuntimeErroraveragesumr   r	   RuntimeWarningmeandotr'   squeeze)r   r   r   r   r   fweightsaweightsr   Xwavgw_sumfactX_Tr   r   r   r   r   S   s   (










r   )NTNN)r   )NTFNNN)r9   r   r6   r   r   r   r,   r   r   r   r   r   <module>   s    
+