
    _Mhl                         d dl Z d dlZd dlZd dlZddgZ G d d          Z G d de          Z G d de          ZdS )    NAAAFloaterHormannInterpolatorc                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
_BarycentricRationalzABase class for Barycentric representation of a rational function.c                 D   t          j        |          }t          j        |          } | j        ||fi | t           j                            t          j        |          t          j        |           z                      |j        d         d          d          }||df         }||         }t          j	        |d          \  }}||df         }|j        dd          | _
         | j        ||fi |\  | _        | _        | _        d | _        d | _        d | _        d S )Nr   axis.T)return_index   )npasarray_input_validationlogical_andreduceisfiniteisnanreshapeshapeunique_shape_compute_weights_support_points_support_valuesweights_poles	_residues_roots)selfxykwargszfto_keepunis           `/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/interpolate/_bary_rational.py__init__z_BarycentricRational.__init__&   s!   JqMMJqMMq!..v... .''k!nn"(1++.77
BGG ( 
 
 gslOgJ140003c3hKgabbk!D!!Q11&11 	Ad2DL
     c                 "   |j         dk    rt          d          |j         dk    st          d          |j        |j        d         k    rt          d          t	          j        t	          j        |                    st          d          d S )Nr   z`x` must be 1-D.z`y` must be at least 1-D.r   z3`x` be the same size as the first dimension of `y`.z`x` must be finite.)ndim
ValueErrorsizer   r   allr   )r   r    r!   r"   s       r'   r   z&_BarycentricRational._input_validationA   s    6Q;;/000v{{89996QWQZRSSSvbk!nn%% 	42333	4 	4r)   c                     t           N)NotImplementedError)r#   r$   r"   s      r'   r   z%_BarycentricRational._compute_weightsN   s    !!r)   c                    t          j        |          }t          j        |          }| j                            | j        j        d         df          }| j        dt           j        f         }t          j        dd          5  dt           j	        
                    || j                  z  }|||z  z  ||z  z  }ddd           n# 1 swxY w Y   t          j        t          j        |                    rAt          j        ||z            t          j        |          z  |t          j        |          <   t          j        t          j        |                    d         }|D ]l}t          j        ||                   s#t          j        ||         | j        k              s@|||         | j        k                                             ||<   mt          j        ||j        | j        z             S )zEvaluate the rational approximation at given values.

        Parameters
        ----------
        z : array_like
            Input values.
        r   r   .ignore)invaliddivider   N)r   r   ravelr   r   r   r   newaxiserrstatesubtractouterr   anyisinfsumnonzeror   squeezer   )	r   r#   zvsupport_valuesr   CCriijjs	            r'   __call__z_BarycentricRational.__call__Q   s    JqMMXa[[-55!'*B/
 
 ,sBJ/ [(;;; 	A 	AR[&&r4+?@@@Bg./2<@A	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 6"(2,, 	2!vg&>??!# 1AbhrllO Z$$Q' 	Q 	QBx2 Qrvbf8L.L'M'M Q  'r"v1E'EFNNPP"z!QWt{2333s   7CCCc                    | j         | j        j        }t          j        |dz   | j        j                  }d|d<   t          j        |t          j        | j        | j                            }| j        |dddf<   d|dddf<   t          j	        |ddddf         | j                   t          j                            ||          }|t          j        |                   | _         | j         S )zCompute the poles of the rational approximation.

        Returns
        -------
        poles : array
            Poles of the AAA approximation, repeated according to their multiplicity
            but not in any specific order.
        Nr   dtyper   r   r   )r   r   r-   r   eyerI   
zeros_likeresult_typer   fill_diagonalscipylinalgeigvalsr   )r   mBEpols        r'   polesz_BarycentricRational.poles|   s     ;!Aq1uDL$6777AAdGar~dl6:6J(L (L M M MA|AaeHAabb!eHQqrr122vY(<===,&&q!,,Cbk#../DK{r)   c                    | j         t          j        dd          5  dt          j                            |                                 | j                  z  | j        | j        z  z  }dt          j                            |                                 | j                  z  dz   | j        z  }||z  | _         ddd           n# 1 swxY w Y   | j         S )zCompute the residues of the poles of the approximation.

        Returns
        -------
        residues : array
            Residues associated with the `poles` of the approximation
        Nr3   r5   r4   r      )	r   r   r8   r9   r:   rV   r   r   r   )r   NDdiffs      r'   residuesz_BarycentricRational.residues   s    >!Hh??? + +))$**,,8LMMN(4<7 **4::<<9MNNNQRRSl#  "#U+ + + + + + + + + + + + + + + ~s   BCC	C	c                     | j         | j        j        }t          j        |dz   | j        j                  }d|d<   t          j        |t          j        | j        | j        | j	                            }| j        | j        z  |dddf<   d|dddf<   t          j
        |ddddf         | j	                   t          j                            ||          }|t          j        |                   | _         | j         S )zCompute the zeros of the rational approximation.

        Returns
        -------
        zeros : array
            Zeros of the AAA approximation, repeated according to their multiplicity
            but not in any specific order.
        Nr   rH   r   rJ   )r   r   r-   r   rK   rI   rL   rM   r   r   rN   rO   rP   rQ   r   )r   rR   rS   rT   zers        r'   rootsz_BarycentricRational.roots   s     ;!Aq1uDL$6777AAdGar~dl6:6J6:6J(L (L M M MA |d&::AaeHAabb!eHQqrr122vY(<===,&&q!,,Cbk#../DK{r)   N)__name__
__module____qualname____doc__r(   r   r   rF   rV   r\   r_    r)   r'   r   r   $   s        KK  64 4 4" " ")4 )4 )4V  2  *    r)   r   c                   x     e Zd ZdZddddd fd
Z	 	 d fd	Zed	             Zed
             Zd Z	ddZ
 xZS )r   u
%  
    AAA real or complex rational approximation.

    As described in [1]_, the AAA algorithm is a greedy algorithm for approximation by
    rational functions on a real or complex set of points. The rational approximation is
    represented in a barycentric form from which the roots (zeros), poles, and residues
    can be computed.

    Parameters
    ----------
    x : 1D array_like, shape (n,)
        1-D array containing values of the independent variable. Values may be real or
        complex but must be finite.
    y : 1D array_like, shape (n,)
        Function values ``f(x)``. Infinite and NaN values of `values` and
        corresponding values of `points` will be discarded.
    rtol : float, optional
        Relative tolerance, defaults to ``eps**0.75``. If a small subset of the entries
        in `values` are much larger than the rest the default tolerance may be too
        loose. If the tolerance is too tight then the approximation may contain
        Froissart doublets or the algorithm may fail to converge entirely.
    max_terms : int, optional
        Maximum number of terms in the barycentric representation, defaults to ``100``.
        Must be greater than or equal to one.
    clean_up : bool, optional
        Automatic removal of Froissart doublets, defaults to ``True``. See notes for
        more details.
    clean_up_tol : float, optional
        Poles with residues less than this number times the geometric mean
        of `values` times the minimum distance to `points` are deemed spurious by the
        cleanup procedure, defaults to 1e-13. See notes for more details.

    Attributes
    ----------
    support_points : array
        Support points of the approximation. These are a subset of the provided `x` at
        which the approximation strictly interpolates `y`.
        See notes for more details.
    support_values : array
        Value of the approximation at the `support_points`.
    weights : array
        Weights of the barycentric approximation.
    errors : array
        Error :math:`|f(z) - r(z)|_\infty` over `points` in the successive iterations
        of AAA.

    Warns
    -----
    RuntimeWarning
        If `rtol` is not achieved in `max_terms` iterations.

    See Also
    --------
    FloaterHormannInterpolator : Floater-Hormann barycentric rational interpolation.
    pade : Padé approximation.

    Notes
    -----
    At iteration :math:`m` (at which point there are :math:`m` terms in the both the
    numerator and denominator of the approximation), the
    rational approximation in the AAA algorithm takes the barycentric form

    .. math::

        r(z) = n(z)/d(z) =
        \frac{\sum_{j=1}^m\ w_j f_j / (z - z_j)}{\sum_{j=1}^m w_j / (z - z_j)},

    where :math:`z_1,\dots,z_m` are real or complex support points selected from
    `x`, :math:`f_1,\dots,f_m` are the corresponding real or complex data values
    from `y`, and :math:`w_1,\dots,w_m` are real or complex weights.

    Each iteration of the algorithm has two parts: the greedy selection the next support
    point and the computation of the weights. The first part of each iteration is to
    select the next support point to be added :math:`z_{m+1}` from the remaining
    unselected `x`, such that the nonlinear residual
    :math:`|f(z_{m+1}) - n(z_{m+1})/d(z_{m+1})|` is maximised. The algorithm terminates
    when this maximum is less than ``rtol * np.linalg.norm(f, ord=np.inf)``. This means
    the interpolation property is only satisfied up to a tolerance, except at the
    support points where approximation exactly interpolates the supplied data.

    In the second part of each iteration, the weights :math:`w_j` are selected to solve
    the least-squares problem

    .. math::

        \text{minimise}_{w_j}|fd - n| \quad \text{subject to} \quad
        \sum_{j=1}^{m+1} w_j = 1,

    over the unselected elements of `x`.

    One of the challenges with working with rational approximations is the presence of
    Froissart doublets, which are either poles with vanishingly small residues or
    pole-zero pairs that are close enough together to nearly cancel, see [2]_. The
    greedy nature of the AAA algorithm means Froissart doublets are rare. However, if
    `rtol` is set too tight then the approximation will stagnate and many Froissart
    doublets will appear. Froissart doublets can usually be removed by removing support
    points and then resolving the least squares problem. The support point :math:`z_j`,
    which is the closest support point to the pole :math:`a` with residue
    :math:`\alpha`, is removed if the following is satisfied

    .. math::

        |\alpha| / |z_j - a| < \verb|clean_up_tol| \cdot \tilde{f},

    where :math:`\tilde{f}` is the geometric mean of `support_values`.


    References
    ----------
    .. [1] Y. Nakatsukasa, O. Sete, and L. N. Trefethen, "The AAA algorithm for
            rational approximation", SIAM J. Sci. Comp. 40 (2018), A1494-A1522.
            :doi:`10.1137/16M1106122`
    .. [2] J. Gilewicz and M. Pindor, Pade approximants and noise: rational functions,
           J. Comp. Appl. Math. 105 (1999), pp. 285-297.
           :doi:`10.1016/S0377-0427(02)00674-X`

    Examples
    --------

    Here we reproduce a number of the numerical examples from [1]_ as a demonstration
    of the functionality offered by this method.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.interpolate import AAA
    >>> import warnings

    For the first example we approximate the gamma function on ``[-3.5, 4.5]`` by
    extrapolating from 100 samples in ``[-1.5, 1.5]``.

    >>> from scipy.special import gamma
    >>> sample_points = np.linspace(-1.5, 1.5, num=100)
    >>> r = AAA(sample_points, gamma(sample_points))
    >>> z = np.linspace(-3.5, 4.5, num=1000)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(z, gamma(z), label="Gamma")
    >>> ax.plot(sample_points, gamma(sample_points), label="Sample points")
    >>> ax.plot(z, r(z).real, '--', label="AAA approximation")
    >>> ax.set(xlabel="z", ylabel="r(z)", ylim=[-8, 8], xlim=[-3.5, 4.5])
    >>> ax.legend()
    >>> plt.show()

    We can also view the poles of the rational approximation and their residues:

    >>> order = np.argsort(r.poles())
    >>> r.poles()[order]
    array([-3.81591039e+00+0.j        , -3.00269049e+00+0.j        ,
           -1.99999988e+00+0.j        , -1.00000000e+00+0.j        ,
            5.85842812e-17+0.j        ,  4.77485458e+00-3.06919376j,
            4.77485458e+00+3.06919376j,  5.29095868e+00-0.97373072j,
            5.29095868e+00+0.97373072j])
    >>> r.residues()[order]
    array([ 0.03658074 +0.j        , -0.16915426 -0.j        ,
            0.49999915 +0.j        , -1.         +0.j        ,
            1.         +0.j        , -0.81132013 -2.30193429j,
           -0.81132013 +2.30193429j,  0.87326839+10.70148546j,
            0.87326839-10.70148546j])

    For the second example, we call `AAA` with a spiral of 1000 points that wind 7.5
    times around the origin in the complex plane.

    >>> z = np.exp(np.linspace(-0.5, 0.5 + 15j*np.pi, 1000))
    >>> r = AAA(z, np.tan(np.pi*z/2), rtol=1e-13)

    We see that AAA takes 12 steps to converge with the following errors:

    >>> r.errors.size
    12
    >>> r.errors
    array([2.49261500e+01, 4.28045609e+01, 1.71346935e+01, 8.65055336e-02,
           1.27106444e-02, 9.90889874e-04, 5.86910543e-05, 1.28735561e-06,
           3.57007424e-08, 6.37007837e-10, 1.67103357e-11, 1.17112299e-13])

    We can also plot the computed poles:

    >>> fig, ax = plt.subplots()
    >>> ax.plot(z.real, z.imag, '.', markersize=2, label="Sample points")
    >>> ax.plot(r.poles().real, r.poles().imag, '.', markersize=5,
    ...         label="Computed poles")
    >>> ax.set(xlim=[-3.5, 3.5], ylim=[-3.5, 3.5], aspect="equal")
    >>> ax.legend()
    >>> plt.show()

    We now demonstrate the removal of Froissart doublets using the `clean_up` method
    using an example from [1]_. Here we approximate the function
    :math:`f(z)=\log(2 + z^4)/(1 + 16z^4)` by sampling it at 1000 roots of unity. The
    algorithm is run with ``rtol=0`` and ``clean_up=False`` to deliberately cause
    Froissart doublets to appear.

    >>> z = np.exp(1j*2*np.pi*np.linspace(0,1, num=1000))
    >>> def f(z):
    ...     return np.log(2 + z**4)/(1 - 16*z**4)
    >>> with warnings.catch_warnings():  # filter convergence warning due to rtol=0
    ...     warnings.simplefilter('ignore', RuntimeWarning)
    ...     r = AAA(z, f(z), rtol=0, max_terms=50, clean_up=False)
    >>> mask = np.abs(r.residues()) < 1e-13
    >>> fig, axs = plt.subplots(ncols=2)
    >>> axs[0].plot(r.poles().real[~mask], r.poles().imag[~mask], '.')
    >>> axs[0].plot(r.poles().real[mask], r.poles().imag[mask], 'r.')

    Now we call the `clean_up` method to remove Froissart doublets.

    >>> with warnings.catch_warnings():
    ...     warnings.simplefilter('ignore', RuntimeWarning)
    ...     r.clean_up()
    4
    >>> mask = np.abs(r.residues()) < 1e-13
    >>> axs[1].plot(r.poles().real[~mask], r.poles().imag[~mask], '.')
    >>> axs[1].plot(r.poles().real[mask], r.poles().imag[mask], 'r.')
    >>> plt.show()

    The left image shows the poles prior of the approximation ``clean_up=False`` with
    poles with residue less than ``10^-13`` in absolute value shown in red. The right
    image then shows the poles after the `clean_up` method has been called.
    Nd   TvIh%<=)rtol	max_termsclean_upclean_up_tolc                    t                                          ||||           |r|                     |           d S d S )N)rh   ri   )superr(   rj   r   r    r!   rh   ri   rj   rk   	__class__s          r'   r(   zAAA.__init__  sN    ADI>>> 	(MM,'''''	( 	(r)   c                     t          j        |          }|dk     rt          d          |j        dk    rt          d          t	                                          ||           d S )Nr   zB`max_terms` must be an integer value greater than or equal to one.z`y` must be 1-D.)operatorindexr,   r+   rm   r   rn   s          r'   r   zAAA._input_validation  sn    N9--	q== - . . . 6Q;;/000!!!Q'''''r)   c                     | j         S r0   )r   r   s    r'   support_pointszAAA.support_points      ##r)   c                     | j         S r0   )r   rt   s    r'   rA   zAAA.support_values  rv   r)   c                 D
   t          j        |          }t          j        |t           j                  }t          j        ||d          }|t          j        |          j        dz  n|}|t           j                            |t           j	                  z  }t          j
        ||          }	t          j
        ||          }
t          j
        ||f|          }t          j
        ||f|          }t          j
        ||j        j                  }t          j        t          j        |          |          }t          |          D ]U}t          j        t          j        ||         ||         z
                      }||         |         |	|<   ||         |         |
|<   t          j        dd          5  d|||         |         z
  z  |d d |f<   d d d            n# 1 swxY w Y   d|t          j        |          d	         |         <   t          j        d
          5  ||
|         z
  |d d |f         z  |d d |f<   d d d            n# 1 swxY w Y   |                                }||dz   k    rt*          j                            ||d |dz   f         dd          \  }}}|t          j        |          k    }|                                |d d f                             d	          t          j        |                                          z                      |          }nft*          j                            ||d |dz   f         d          }|j        d         }|                    d          t          j        |          z  }|d	k    }t          j        d
          5  |d d d |dz   f         d d |f         ||         |
d |dz            |         z  z  }|d d d |dz   f         d d |f         ||         z  }d d d            n# 1 swxY w Y   t          j        |          t          j        |          z  }d||<   ||         ||<   ||z  }t           j                            ||z
  t           j	                  }|||<   ||k    r nW||dz
  k    r t?          j         d| dtB          d           |	d |dz            }	|
d |dz            }
|d	k    }|d |dz            | _"        || _#        || _$        |	|         |
|         ||         fS )NrH         ?g      ?)ordr3   rX   r   Fr   )r4   )full_matricescheck_finiter	   r|   r   zAAA failed to converge within z iterations.rY   
stacklevel)%r   r-   onesbool_rM   finfoepsrP   norminfemptyrealrI   repeatmeanrangeargmaxabsr8   r>   r=   rO   svdminconjsqrtastype
null_spacer   r<   r   warningswarnRuntimeWarningerrors_points_values)r   r#   r$   rh   ri   MmaskrI   atolzjfjCAr   RrR   rE   rows_sVmmwjnmi0rZ   DD_inf	max_error
i_non_zeros                                 r'   r   zAAA._compute_weights  s   GAJJwq)))q!S)),0Lrx"D((dbinnQBFn333Xiu---Xiu---Ha^5111Ha^5111)16<888Ibgajj!$$ y!! 8	 8	A 26!D'AdG"34455BdGBKBqEdGBKBqE Hh??? 0 0q1T72;/!!!Q$0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2DD!!!$R() X... 0 0r!u9!!!Q$/!!!Q$0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 88::Dq1u}},**dGa!eGm$E +  1a "&))^ffhhr111uo))q)11BGBFFHH4E4EEMMeTT L++AdGa!eGm,<5+QQWR[UUU^^bgbkk1 qBX... 2 2aaa1q5jM!!!R%(BrFR!a%[_,DEaaa1q5jM!!!R%(2b61	2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 HQKK"(1++-EAeHxAeHAA 	q1u"&99I!F1ID   ! 	AMR9RRR(Q8 8 8 8 !a%[!a%[ 1W
Wq1uWo*~r*~r*~==s7   ;G##G'	*G'	& II	I	3APP 	#P 	c           	         t           j                            t          j        | j                            }t          j        t          j        t          j                            | 	                                | j
                            d          }t          j        dd          5  t          j        t          j        |                                           |z  ||z  k               }ddd           n# 1 swxY w Y   |d         j        }|dk    r|S t          j        | dt"          d	           t          j        t          j        t          j                            | j        | 	                                |                             d          }t          j        | j        |          | _        t          j        | j        |          | _        t          j                            t          j                            | j
        | j                  d          }| j        |         }| j
        |         }	| j        j        }
dt          j                            |	| j                  z  }|ddt          j        f         |z  || j        z  z
  }t           j                            |d
          \  }}}t          j        ||
dz
  ddf                   | _        d| _        d| _        d| _         |S )a  Automatic removal of Froissart doublets.

        Parameters
        ----------
        cleanup_tol : float, optional
            Poles with residues less than this number times the geometric mean
            of `values` times the minimum distance to `points` are deemed spurious by
            the cleanup procedure, defaults to 1e-13.

        Returns
        -------
        int
            Number of Froissart doublets detected
        r   r	   r3   rX   Nr   z Froissart doublets detected.rY   r~   Fr}   )!rO   statsgmeanr   r   r   r   r9   r:   rV   r   r8   r>   r\   r-   r   r   r   argminr   deleter   r   r   	not_equalr7   rP   r   r   r   r   r   r   )r   cleanup_tolgeom_mean_abs_fZ_distancesrD   niclosest_spt_pointr   r$   r#   rR   r   r   r   r   s                  r'   rj   zAAA.clean_up  s      +++BF4<,@,@AAfF2;$$TZZ\\4<@@AA
 
 
 [(;;; 	 	t}}''+5o8UU B	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 UZ77I:::N#$	& 	& 	& 	& IF2;$$T%94::<<;KLLMMTU
 
 
  "y)=?PQQ!y)=?PQQ ~$$Lt|T-ABB % 
 
 LL
  % !!!T%9:::aaamq 1t';#;; ,""15"991awqQqqqz** 	s   *AC99C= C=)Nrf   Trg   )rg   )r`   ra   rb   rc   r(   r   propertyru   rA   r   rj   __classcell__ro   s   @r'   r   r      s        V Vn &*S4#( ( ( ( ( ( ( JN',
( 
( 
( 
( 
( 
( $ $ X$ $ $ X$X> X> X>tC C C C C C C Cr)   c                   8     e Zd ZdZdd fd
Z fdZd Z xZS )r   u   
    Floater-Hormann barycentric rational interpolation.

    As described in [1]_, the method of Floater and Hormann computes weights for a
    Barycentric rational interpolant with no poles on the real axis.

    Parameters
    ----------
    x : 1D array_like, shape (n,)
        1-D array containing values of the independent variable. Values may be real or
        complex but must be finite.
    y : array_like, shape (n, ...)
        Array containing values of the dependent variable. Infinite and NaN values
        of `values` and corresponding values of `x` will be discarded.
    d : int, optional
        Blends ``n - d`` degree `d` polynomials together. For ``d = n - 1`` it is
        equivalent to polynomial interpolation. Must satisfy ``0 <= d < n``,
        defaults to 3.

    Attributes
    ----------
    weights : array
        Weights of the barycentric approximation.

    See Also
    --------
    AAA : Barycentric rational approximation of real and complex functions.
    pade : Padé approximation.

    Notes
    -----
    The Floater-Hormann interpolant is a rational function that interpolates the data
    with approximation order :math:`O(h^{d+1})`. The rational function blends ``n - d``
    polynomials of degree `d` together to produce a rational interpolant that contains
    no poles on the real axis, unlike `AAA`. The interpolant is given
    by

    .. math::

        r(x) = \frac{\sum_{i=0}^{n-d} \lambda_i(x) p_i(x)}
        {\sum_{i=0}^{n-d} \lambda_i(x)},

    where :math:`p_i(x)` is an interpolating polynomials of at most degree `d` through
    the points :math:`(x_i,y_i),\dots,(x_{i+d},y_{i+d}), and :math:`\lambda_i(z)` are
    blending functions defined by

    .. math::

        \lambda_i(x) = \frac{(-1)^i}{(x - x_i)\cdots(x - x_{i+d})}.

    When ``d = n - 1`` this reduces to polynomial interpolation.

    Due to its stability following barycentric representation of the above equation
    is used instead for computation

    .. math::

        r(z) = \frac{\sum_{k=1}^m\ w_k f_k / (x - x_k)}{\sum_{k=1}^m w_k / (x - x_k)},

    where the weights :math:`w_j` are computed as

    .. math::

        w_k &= (-1)^{k - d} \sum_{i \in J_k} \prod_{j = i, j \neq k}^{i + d}
        1/|x_k - x_j|, \\
        J_k &= \{ i \in I: k - d \leq i \leq k\},\\
        I &= \{0, 1, \dots, n - d\}.

    References
    ----------
    .. [1] M.S. Floater and K. Hormann, "Barycentric rational interpolation with no
           poles and high rates of approximation", Numer. Math. 107, 315 (2007).
           :doi:`10.1007/s00211-007-0093-y`

    Examples
    --------

    Here we compare the method against polynomial interpolation for an example where
    the polynomial interpolation fails due to Runge's phenomenon.

    >>> import numpy as np
    >>> from scipy.interpolate import (FloaterHormannInterpolator,
    ...                                BarycentricInterpolator)
    >>> def f(z):
    ...     return 1/(1 + z**2)
    >>> z = np.linspace(-5, 5, num=15)
    >>> r = FloaterHormannInterpolator(z, f(z))
    >>> p = BarycentricInterpolator(z, f(z))
    >>> zz = np.linspace(-5, 5, num=1000)
    >>> import matplotlib.pyplot as plt
    >>> fig, ax = plt.subplots()
    >>> ax.plot(zz, r(zz), label="Floater=Hormann")
    >>> ax.plot(zz, p(zz), label="Polynomial")
    >>> ax.legend()
    >>> plt.show()
       dc                P    t                                          |||           d S )Nr   )rm   r(   )r   pointsvaluesr   ro   s       r'   r(   z#FloaterHormannInterpolator.__init__  s(    1-----r)   c                     t          j        |          }d|cxk    rt          |          k     sn t          d          t	                                          ||           d S )Nr   z`d` must satisfy 0 <= d < n)rq   rr   lenr,   rm   r   )r   r    r!   r   ro   s       r'   r   z,FloaterHormannInterpolator._input_validation  s^    N1QQ:;;;!!!Q'''''r)   c                    t          j        |t          j        |d                    }|j        }t	          |          D ]}t	          t          ||z
  d          t          |dz   ||z
                      D ]f}||xx         dt          j        t          j        t          j	        ||         ||||z   dz            z
  ||z
                                z  z  cc<   g|dt          j
        |          |z
  z  z  }|||fS )Nry   rH   r   r   g      )r   rL   rM   r-   r   maxr   prodr   r   arange)r   r#   r$   r   wnkis           r'   r   z+FloaterHormannInterpolator._compute_weights  s    M!2>!S#9#9:::Fq 	U 	UA3qsA;;AaC166 U U!"'"&1Q4!AA	M:J3JAPQE)R)R"S"STTTTU	cRYq\\A%&&!Qwr)   )r`   ra   rb   rc   r(   r   r   r   r   s   @r'   r   r   W  s|        _ _@ -. . . . . . . .( ( ( ( (	 	 	 	 	 	 	r)   )	r   rq   numpyr   rO   __all__r   r   r   rd   r)   r'   <module>r      s   4        .
/] ] ] ] ] ] ] ]@P P P P P
 P P Pft t t t t!5 t t t t tr)   