a
    ˜¥»ab  ã                	   @   s¢   d dl Zdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Z	eeeeeeee	dœZ
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ ZdS )#é    Nc                 C   s   |  S )N© ©Úrr   r   ú^/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/scipy/interpolate/_rbfinterp_pythran.pyÚlinear   s    r   c                 C   s"   | dkrdS | d t  | ¡ S d S )Nr   ç        é   )ÚnpÚlogr   r   r   r   Úthin_plate_spline   s    r   c                 C   s   | d S )Né   r   r   r   r   r   Úcubic   s    r   c                 C   s
   | d  S )Né   r   r   r   r   r   Úquintic   s    r   c                 C   s   t  | d d ¡ S )Nr   é   ©r	   Úsqrtr   r   r   r   Úmultiquadric   s    r   c                 C   s   dt  | d d ¡ S ©Nr   r   r   r   r   r   r   Úinverse_multiquadric   s    r   c                 C   s   d| d d  S r   r   r   r   r   r   Úinverse_quadratic   s    r   c                 C   s   t  | d  ¡S )Nr   )r	   Úexpr   r   r   r   Úgaussian#   s    r   )r   r   r   r   r   r   r   r   c                 C   s4   t |jd ƒD ] }|tj | ||  ¡ƒ||< qdS )z5Evaluate RBFs, with centers at `y`, at the point `x`.r   N©ÚrangeÚshaper	   ZlinalgZnorm)ÚxÚyÚkernel_funcÚoutÚir   r   r   Úkernel_vector3   s    r!   c                 C   s.   t |jd ƒD ]}t | ||  ¡||< qdS )zCEvaluate monomials, with exponents from `powers`, at the point `x`.r   N©r   r   r	   Úprod)r   Úpowersr   r    r   r   r   Úpolynomial_vector9   s    r%   c                 C   sb   t | jd ƒD ]N}t |d ƒD ]<}|tj | | | |  ¡ƒ|||f< |||f |||f< qqdS )z+Evaluate RBFs, with centers at `x`, at `x`.r   r   Nr   )r   r   r   r    Újr   r   r   Úkernel_matrix?   s    $r'   c                 C   sJ   t | jd ƒD ]6}t |jd ƒD ]"}t | | ||  ¡|||f< q qdS )z9Evaluate monomials, with exponents from `powers`, at `x`.r   Nr"   )r   r$   r   r    r&   r   r   r   Úpolynomial_matrixG   s    r(   c                 C   s6   t j| jd | jd ftd�}t| }t| ||ƒ |S )z3Return RBFs, with centers at `x`, evaluated at `x`.r   ©Zdtype)r	   Úemptyr   ÚfloatÚNAME_TO_FUNCr'   )r   Úkernelr   r   r   r   r   Ú_kernel_matrixO   s    r.   c                 C   s.   t j| jd |jd ftd�}t| ||ƒ |S )zAReturn monomials, with exponents from `powers`, evaluated at `x`.r   r)   )r	   r*   r   r+   r(   )r   r$   r   r   r   r   Ú_polynomial_matrixX   s    r/   c                 C   sl  |j d }|j d }|j d }t| }	tj| dd�}
tj| dd�}||
 d }||
 d }d||dk< | | }| | | }tj|| || ftd�j}t||	|d|…d|…f ƒ t	|||d|…|d…f ƒ |d|…|d…f j||d…d|…f< d||d…|d…f< t
|ƒD ]}|||f  || 7  < �qtj||| ftd�j}||d|…< d||d…< ||||fS )	a=  Build the system used to solve for the RBF interpolant coefficients.

    Parameters
    ----------
    y : (P, N) float ndarray
        Data point coordinates.
    d : (P, S) float ndarray
        Data values at `y`.
    smoothing : (P,) float ndarray
        Smoothing parameter for each data point.
    kernel : str
        Name of the RBF.
    epsilon : float
        Shape parameter.
    powers : (R, N) int ndarray
        The exponents for each monomial in the polynomial.

    Returns
    -------
    lhs : (P + R, P + R) float ndarray
        Left-hand side matrix.
    rhs : (P + R, S) float ndarray
        Right-hand side matrix.
    shift : (N,) float ndarray
        Domain shift used to create the polynomial matrix.
    scale : (N,) float ndarray
        Domain scaling used to create the polynomial matrix.

    r   r   )Zaxisr   g      ð?r   r)   N)r   r,   r	   ÚminÚmaxr*   r+   ÚTr'   r(   r   )r   ÚdZ	smoothingr-   Úepsilonr$   ÚpÚsr   r   ZminsZmaxsÚshiftÚscaleÚyepsZyhatÚlhsr    Úrhsr   r   r   Ú_build_systeme   s,    


&r<   c              	   C   sú   | j d }|j d }	|j d }
|j d }t| }|| }| | }| | | }tj||ftd�}tj|	|
 ftd�}t|ƒD ]z}t|| |||d|	… ƒ t|| |||	d… ƒ t|ƒD ]:}t|	|
 ƒD ](}|||f  |||f ||  7  < qÈq¸qz|S )a½  Evaluate the RBF interpolant at `x`.

    Parameters
    ----------
    x : (Q, N) float ndarray
        Evaluation point coordinates.
    y : (P, N) float ndarray
        Data point coordinates.
    kernel : str
        Name of the RBF.
    epsilon : float
        Shape parameter.
    powers : (R, N) int ndarray
        The exponents for each monomial in the polynomial.
    shift : (N,) float ndarray
        Shifts the polynomial domain for numerical stability.
    scale : (N,) float ndarray
        Scales the polynomial domain for numerical stability.
    coeffs : (P + R, S) float ndarray
        Coefficients for each RBF and monomial.

    Returns
    -------
    (Q, S) float ndarray

    r   r   r)   N)	r   r,   r	   Úzerosr+   r*   r   r!   r%   )r   r   r-   r4   r$   r7   r8   ZcoeffsÚqr5   r   r6   r   r9   ZxepsZxhatr   Zvecr    r&   Úkr   r   r   Ú	_evaluate¯   s"    



*r@   )Únumpyr	   r   r   r   r   r   r   r   r   r,   r!   r%   r'   r(   r.   r/   r<   r@   r   r   r   r   Ú<module>   s2   ø	J