o
    5ήc                  	   @   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   K/tmp/pip-target-vg8gfxp4/lib/python/scipy/interpolate/_rbfinterp_pythran.pylinear   s   r   c                 C   s   | dkrdS | d t |  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      r   c                 C   s   t | d  S )Nr   )r	   expr   r   r   r   gaussian#   r   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	   linalg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 ]'}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 ]}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   dtype)r	   emptyr   floatNAME_TO_FUNCr*   )r   kernelr"   r!   r   r   r   _kernel_matrixO   s   r2   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   r3   c                 C   sj  |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  < qt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   )axisr   g      ?r   r,   N)r   r0   r	   minmaxr.   r/   Tr*   r+   r   )r    d	smoothingr1   epsilonr'   psr   r!   minsmaxsshiftscaleyepsyhatlhsr#   rhsr   r   r   _build_systeme   s,   


&rE   c              	   C   s   | j d }|j d }|j d }	t| }
|| }| | }| | | }tj|||	 ftd}t|D ]}t|| ||
||d|f  t|| ||||df  q0|S )a  Construct the coefficients needed to evaluate
    the RBF.

    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.

    Returns
    -------
    (Q, P + R) float ndarray

    r   r,   N)r   r0   r	   r.   r/   r   r$   r(   )r   r    r1   r:   r'   r?   r@   qr;   r   r!   rA   xepsxhatvecr#   r   r   r   _build_evaluation_coefficients   s   


rJ   )numpyr	   r   r   r   r   r   r   r   r   r0   r$   r(   r*   r+   r2   r3   rE   rJ   r   r   r   r   <module>   s4    	I