ó
î&]\c           @` s:  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l m	 Z	 d  d l
 m Z m Z m Z m Z d d l m Z d d l m Z d d l m Z d	 d
 d g Z d „  Z d „  Z e d „ Z d	 e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d e e d  e  d „ Z! d e d  e  d „ Z" d S(   i    (   t   divisiont   print_functiont   absolute_importN(   t   string_types(   t   get_lapack_funcst   LinAlgErrort   cholesky_bandedt   cho_solve_bandedi   (   t   _bspl(   t   _fitpack_impl(   t   _fitpackt   BSplinet   make_interp_splinet   make_lsq_splinec         C` s)   t  |  ƒ d k r d St j t j |  ƒ S(   sF   Product of a list of numbers; ~40x faster vs np.prod for Python tuplesi    i   (   t   lent	   functoolst   reducet   operatort   mul(   t   x(    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   prod   s    c         C` s'   t  j |  t  j ƒ r t  j St  j Sd S(   s>   Return np.complex128 for complex dtypes, np.float64 otherwise.N(   t   npt
   issubdtypet   complexfloatingt   complex_t   float_(   t   dtype(    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt
   _get_dtype   s    c         C` sb   t  j |  ƒ }  t |  j ƒ } |  j | d t ƒ}  | r^ t  j |  ƒ j ƒ  r^ t d ƒ ‚ n  |  S(   s   Convert the input into a C contiguous float array.

    NB: Upcasts half- and single-precision floats to double precision.
    t   copys$   Array must not contain infs or nans.(	   R   t   ascontiguousarrayR   R   t   astypet   Falset   isfinitet   allt
   ValueError(   R   t   check_finitet   dtyp(    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   _as_float_array!   s    c           B` s˜   e  Z d  Z e d d „ Z e e d d „ ƒ Z e d „  ƒ Z e e d „ ƒ Z	 d d d „ Z d „  Z d „  Z d	 d
 „ Z d	 d „ Z d d „ Z RS(   s  Univariate spline in the B-spline basis.

    .. math::

        S(x) = \sum_{j=0}^{n-1} c_j  B_{j, k; t}(x)

    where :math:`B_{j, k; t}` are B-spline basis functions of degree `k`
    and knots `t`.

    Parameters
    ----------
    t : ndarray, shape (n+k+1,)
        knots
    c : ndarray, shape (>=n, ...)
        spline coefficients
    k : int
        B-spline order
    extrapolate : bool or 'periodic', optional
        whether to extrapolate beyond the base interval, ``t[k] .. t[n]``,
        or to return nans.
        If True, extrapolates the first and last polynomial pieces of b-spline
        functions active on the base interval.
        If 'periodic', periodic extrapolation is used.
        Default is True.
    axis : int, optional
        Interpolation axis. Default is zero.

    Attributes
    ----------
    t : ndarray
        knot vector
    c : ndarray
        spline coefficients
    k : int
        spline degree
    extrapolate : bool
        If True, extrapolates the first and last polynomial pieces of b-spline
        functions active on the base interval.
    axis : int
        Interpolation axis.
    tck : tuple
        A read-only equivalent of ``(self.t, self.c, self.k)``

    Methods
    -------
    __call__
    basis_element
    derivative
    antiderivative
    integrate
    construct_fast

    Notes
    -----
    B-spline basis elements are defined via

    .. math::

        B_{i, 0}(x) = 1, \textrm{if $t_i \le x < t_{i+1}$, otherwise $0$,}

        B_{i, k}(x) = \frac{x - t_i}{t_{i+k} - t_i} B_{i, k-1}(x)
                 + \frac{t_{i+k+1} - x}{t_{i+k+1} - t_{i+1}} B_{i+1, k-1}(x)

    **Implementation details**

    - At least ``k+1`` coefficients are required for a spline of degree `k`,
      so that ``n >= k+1``. Additional coefficients, ``c[j]`` with
      ``j > n``, are ignored.

    - B-spline basis elements of degree `k` form a partition of unity on the
      *base interval*, ``t[k] <= x <= t[n]``.


    Examples
    --------

    Translating the recursive definition of B-splines into Python code, we have:

    >>> def B(x, k, i, t):
    ...    if k == 0:
    ...       return 1.0 if t[i] <= x < t[i+1] else 0.0
    ...    if t[i+k] == t[i]:
    ...       c1 = 0.0
    ...    else:
    ...       c1 = (x - t[i])/(t[i+k] - t[i]) * B(x, k-1, i, t)
    ...    if t[i+k+1] == t[i+1]:
    ...       c2 = 0.0
    ...    else:
    ...       c2 = (t[i+k+1] - x)/(t[i+k+1] - t[i+1]) * B(x, k-1, i+1, t)
    ...    return c1 + c2

    >>> def bspline(x, t, c, k):
    ...    n = len(t) - k - 1
    ...    assert (n >= k+1) and (len(c) >= n)
    ...    return sum(c[i] * B(x, k, i, t) for i in range(n))

    Note that this is an inefficient (if straightforward) way to
    evaluate B-splines --- this spline class does it in an equivalent,
    but much more efficient way.

    Here we construct a quadratic spline function on the base interval
    ``2 <= x <= 4`` and compare with the naive way of evaluating the spline:

    >>> from scipy.interpolate import BSpline
    >>> k = 2
    >>> t = [0, 1, 2, 3, 4, 5, 6]
    >>> c = [-1, 2, 0, -1]
    >>> spl = BSpline(t, c, k)
    >>> spl(2.5)
    array(1.375)
    >>> bspline(2.5, t, c, k)
    1.375

    Note that outside of the base interval results differ. This is because
    `BSpline` extrapolates the first and last polynomial pieces of b-spline
    functions active on the base interval.

    >>> import matplotlib.pyplot as plt
    >>> fig, ax = plt.subplots()
    >>> xx = np.linspace(1.5, 4.5, 50)
    >>> ax.plot(xx, [bspline(x, t, c ,k) for x in xx], 'r-', lw=3, label='naive')
    >>> ax.plot(xx, spl(xx), 'b-', lw=4, alpha=0.7, label='BSpline')
    >>> ax.grid(True)
    >>> ax.legend(loc='best')
    >>> plt.show()


    References
    ----------
    .. [1] Tom Lyche and Knut Morken, Spline methods,
        http://www.uio.no/studier/emner/matnat/ifi/INF-MAT5340/v05/undervisningsmateriale/
    .. [2] Carl de Boor, A practical guide to splines, Springer, 2001.

    i    c         C` su  t  t |  ƒ j ƒ  t j | ƒ |  _ t j | ƒ |  _ t j	 | d t j
 ƒ|  _ | d k rj | |  _ n t | ƒ |  _ |  j j d |  j d } d | k o± |  j j k  n sÒ t d | | j f ƒ ‚ n  | |  _ | d k rt j |  j | ƒ |  _ n  | d k  rt d ƒ ‚ n  |  j j d k r>t d ƒ ‚ n  | |  j d k  rrt d d	 | d	 | f ƒ ‚ n  t j |  j ƒ d k  j ƒ  rŸt d
 ƒ ‚ n  t t j |  j | | d !ƒ ƒ d	 k  r×t d ƒ ‚ n  t j |  j ƒ j ƒ  sþt d ƒ ‚ n  |  j j d k  rt d ƒ ‚ n  |  j j d | k  rDt d ƒ ‚ n  t |  j j ƒ } t j	 |  j d | ƒ|  _ d  S(   NR   t   periodici    i   s   %s must be between 0 and %ss    Spline order cannot be negative.s$   Knot vector must be one-dimensional.s$   Need at least %d knots for degree %di   s(   Knots must be in a non-decreasing order.s!   Need at least two internal knots.s#   Knots should not have nans or infs.s,   Coefficients must be at least 1-dimensional.s0   Knots, coefficients and degree are inconsistent.(   t   superR   t   __init__R   t   indext   kR   t   asarrayt   cR   t   float64t   tt   extrapolatet   boolt   shapet   ndimR"   t   axist   rollaxist   difft   anyR   t   uniqueR    R!   R   R   (   t   selfR.   R,   R*   R/   R3   t   nt   dt(    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyR(   µ   s@    "	)c         C` sB   t  j |  ƒ } | | | | _ | _ | _ | | _ | | _ | S(   s±   Construct a spline without making checks.

        Accepts same parameters as the regular constructor. Input arrays
        `t` and `c` must of correct shape and dtype.
        (   t   objectt   __new__R.   R,   R*   R/   R3   (   t   clsR.   R,   R*   R/   R3   R8   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   construct_fastä   s
    		c         C` s   |  j  |  j |  j f S(   s@   Equivalent to ``(self.t, self.c, self.k)`` (read-only).
        (   R.   R,   R*   (   R8   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   tckñ   s    c         C` s   t  | ƒ d } t | ƒ } t j | d d f | | | d d f | f } t j | ƒ } d | | <|  j | | | | ƒ S(   s_  Return a B-spline basis element ``B(x | t[0], ..., t[k+1])``.

        Parameters
        ----------
        t : ndarray, shape (k+1,)
            internal knots
        extrapolate : bool or 'periodic', optional
            whether to extrapolate beyond the base interval, ``t[0] .. t[k+1]``,
            or to return nans.
            If 'periodic', periodic extrapolation is used.
            Default is True.

        Returns
        -------
        basis_element : callable
            A callable representing a B-spline basis element for the knot
            vector `t`.

        Notes
        -----
        The order of the b-spline, `k`, is inferred from the length of `t` as
        ``len(t)-2``. The knot vector is constructed by appending and prepending
        ``k+1`` elements to internal knots `t`.

        Examples
        --------

        Construct a cubic b-spline:

        >>> from scipy.interpolate import BSpline
        >>> b = BSpline.basis_element([0, 1, 2, 3, 4])
        >>> k = b.k
        >>> b.t[k:-k]
        array([ 0.,  1.,  2.,  3.,  4.])
        >>> k
        3

        Construct a second order b-spline on ``[0, 1, 1, 2]``, and compare
        to its explicit form:

        >>> t = [-1, 0, 1, 1, 2]
        >>> b = BSpline.basis_element(t[1:])
        >>> def f(x):
        ...     return np.where(x < 1, x*x, (2. - x)**2)

        >>> import matplotlib.pyplot as plt
        >>> fig, ax = plt.subplots()
        >>> x = np.linspace(0, 2, 51)
        >>> ax.plot(x, b(x), 'g', lw=3)
        >>> ax.plot(x, f(x), 'r', lw=8, alpha=0.4)
        >>> ax.grid(True)
        >>> plt.show()

        i   i    i   iÿÿÿÿg      ð?(   R   R%   R   t   r_t
   zeros_likeR>   (   R=   R.   R/   R*   R,   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   basis_element÷   s    84
c   	      C` s˜  | d k r |  j } n  t j | ƒ } | j | j } } t j | j ƒ  d t j ƒ} | d k r¿ |  j	 j
 |  j d } |  j	 |  j | |  j	 |  j |  j	 | |  j	 |  j } t } n  t j t | ƒ t |  j j d ƒ f d |  j j ƒ} |  j ƒ  |  j | | | | ƒ | j | |  j j d ƒ } |  j d k r”t t | j ƒ ƒ } | | | |  j !| |  | | |  j } | j | ƒ } n  | S(   s‘  
        Evaluate a spline function.

        Parameters
        ----------
        x : array_like
            points to evaluate the spline at.
        nu: int, optional
            derivative to evaluate (default is 0).
        extrapolate : bool or 'periodic', optional
            whether to extrapolate based on the first and last intervals
            or return nans. If 'periodic', periodic extrapolation is used.
            Default is `self.extrapolate`.

        Returns
        -------
        y : array_like
            Shape is determined by replacing the interpolation axis
            in the coefficient array with the shape of `x`.

        R   R&   i   i    N(   t   NoneR/   R   R+   R1   R2   R   t   ravelR   R.   t   sizeR*   R   t   emptyR   R   R,   R   t   _ensure_c_contiguoust	   _evaluatet   reshapeR3   t   listt   ranget	   transpose(	   R8   R   t   nuR/   t   x_shapet   x_ndimR9   t   outt   l(    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   __call__6  s&    (	7
+c         C` sB   t  j |  j |  j j |  j j d d ƒ |  j | | | | ƒ d  S(   Ni    iÿÿÿÿ(   R   t   evaluate_splineR.   R,   RI   R1   R*   (   R8   t   xpRM   R/   RP   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyRH   e  s    (c         C` sL   |  j  j j s$ |  j  j ƒ  |  _  n  |  j j j sH |  j j ƒ  |  _ n  d S(   ss   
        c and t may be modified by the user. The Cython code expects
        that they are C contiguous.

        N(   R.   t   flagst   c_contiguousR   R,   (   R8   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyRG   i  s    i   c         C` s›   |  j  } t |  j ƒ t | ƒ } | d k r[ t j | t j | f | j d ƒ f } n  t j |  j | |  j	 f | ƒ } |  j
 d |  j d |  j | Œ S(   sd  Return a b-spline representing the derivative.

        Parameters
        ----------
        nu : int, optional
            Derivative order.
            Default is 1.

        Returns
        -------
        b : BSpline object
            A new instance representing the derivative.

        See Also
        --------
        splder, splantider

        i    i   R/   R3   (   R,   R   R.   R   R@   t   zerosR1   R	   t   splderR*   R>   R/   R3   (   R8   RM   R,   t   ctR?   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt
   derivativet  s    	-!c         C` s¹   |  j  } t |  j ƒ t | ƒ } | d k r[ t j | t j | f | j d ƒ f } n  t j |  j | |  j	 f | ƒ } |  j
 d k r” t } n	 |  j
 } |  j d | d |  j | Œ S(   s¨  Return a b-spline representing the antiderivative.

        Parameters
        ----------
        nu : int, optional
            Antiderivative order. Default is 1.

        Returns
        -------
        b : BSpline object
            A new instance representing the antiderivative.

        Notes
        -----
        If antiderivative is computed and ``self.extrapolate='periodic'``,
        it will be set to False for the returned instance. This is done because
        the antiderivative is no longer periodic and its correct evaluation
        outside of the initially given x interval is difficult.

        See Also
        --------
        splder, splantider

        i    i   R&   R/   R3   (   R,   R   R.   R   R@   RW   R1   R	   t
   splantiderR*   R/   R   R>   R3   (   R8   RM   R,   RY   R?   R/   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   antiderivative  s    	-!		c         C` s  | d k r |  j } n  |  j ƒ  d } | | k  rJ | | } } d } n  |  j j |  j d } | d k ró | ró t | |  j |  j ƒ } t | |  j | ƒ } |  j j	 d k ró |  j
 \ } } } t j | | | | | ƒ \ }	 }
 |	 | Sn  t j d t |  j j d ƒ f d |  j j ƒ} |  j } t |  j ƒ t | ƒ } | d k rt j | t j | f | j d ƒ f } n  t j |  j | |  j f d ƒ \ } } } | d k r|  j |  j |  j | } } | | } | | } t | | ƒ \ } } | d k rwt j | | g d t j ƒ} t j | | j | j d d ƒ | | d t | ƒ | d | d }	 |	 | 9}	 n1 t j d t |  j j d ƒ f d |  j j ƒ}	 | | | | } | | } | | k r9t j | | g d t j ƒ} t j | | j | j d d ƒ | | d t | ƒ |	 | d | d 7}	 qrt j | | g d t j ƒ} t j | | j | j d d ƒ | | d t | ƒ |	 | d | d 7}	 t j | | | | g d t j ƒ} t j | | j | j d d ƒ | | d t | ƒ |	 | d | d 7}	 nb t j | | g d t j ƒ} t j | | j | j d d ƒ | | d | | ƒ | d | d }	 |	 | 9}	 |	 j | j d ƒ S(   sô  Compute a definite integral of the spline.

        Parameters
        ----------
        a : float
            Lower limit of integration.
        b : float
            Upper limit of integration.
        extrapolate : bool or 'periodic', optional
            whether to extrapolate beyond the base interval,
            ``t[k] .. t[-k-1]``, or take the spline to be zero outside of the
            base interval. If 'periodic', periodic extrapolation is used.
            If None (default), use `self.extrapolate`.

        Returns
        -------
        I : array_like
            Definite integral of the spline over the interval ``[a, b]``.

        Examples
        --------
        Construct the linear spline ``x if x < 1 else 2 - x`` on the base
        interval :math:`[0, 2]`, and integrate it

        >>> from scipy.interpolate import BSpline
        >>> b = BSpline.basis_element([0, 1, 2])
        >>> b.integrate(0, 1)
        array(0.5)

        If the integration limits are outside of the base interval, the result
        is controlled by the `extrapolate` parameter

        >>> b.integrate(-1, 1)
        array(0.0)
        >>> b.integrate(-1, 1, extrapolate=False)
        array(0.5)

        >>> import matplotlib.pyplot as plt
        >>> fig, ax = plt.subplots()
        >>> ax.grid(True)
        >>> ax.axvline(0, c='r', lw=5, alpha=0.5)  # base interval
        >>> ax.axvline(2, c='r', lw=5, alpha=0.5)
        >>> xx = [-1, 1, 2]
        >>> ax.plot(xx, b(xx))
        >>> plt.show()

        i   iÿÿÿÿR&   i   R   i    N(   RC   R/   RG   R.   RE   R*   t   maxt   minR,   R2   R?   t   _dierckxt   _splintR   RF   R   R1   R   R   R@   RW   R	   R[   t   divmodR+   R   R   RS   RI   R   (   R8   t   at   bR/   t   signR9   R.   R,   R*   t   integralt   wrkRP   RY   t   tat   cat   kat   tst   tet   periodt   intervalt	   n_periodst   leftR   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt	   integrate¸  sn    0
	!1	-*

"
&
N(   t   __name__t
   __module__t   __doc__t   TrueR(   t   classmethodR>   t   propertyR?   RB   RC   RR   RH   RG   RZ   R\   Rp   (    (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyR   .   s   †/>/		(c         C` sŽ   t  j |  ƒ }  | d d k r2 t d | ƒ ‚ n  | d d } |  | d | d !} t  j |  d f | d | |  d f | d f } | S(   sS   Given data x, construct the knot vector w/ not-a-knot BC.
    cf de Boor, XIII(12).i   i   s    Odd degree for now only. Got %s.i    iÿÿÿÿ(   R   R+   R"   R@   (   R   R*   t   mR.   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   _not_a_knotB  s    4c         C` s*   t  j |  d f | |  |  d f | f S(   sB   Construct a knot vector appropriate for the order-k interpolation.i    iÿÿÿÿ(   R   R@   (   R   R*   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   _augkntO  s    c         C` st   t  |  t ƒ rp |  d k r6 d t j | ƒ f g }  qp |  d k r] d t j | ƒ f g }  qp t d |  ƒ ‚ n  |  S(   Nt   clampedi   t   naturali   s   Unknown boundary condition : %s(   t
   isinstanceR   R   RW   R"   (   t   derivt   target_shape(    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   _convert_string_aliasesT  s    c         C` sh   |  d  k	 rK y t |  Œ  \ } } WqX t k
 rG d } t | ƒ ‚ qX Xn g  g  } } t j | | ƒ S(   Ns^   Derivatives, `bc_type`, should be specified as a pair of iterables of pairs of (order, value).(   RC   t   zipt	   TypeErrorR"   R   t
   atleast_1d(   R}   t   ordst   valst   msg(    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   _process_deriv_spec_  s    i   c         C` sƒ  | d k s | d k r' d \ } } nS t | t ƒ rF | | } } n4 y | \ } } Wn! t k
 ry t d | ƒ ‚ n Xt j | ƒ } | j | k o§ | j k  n sÄ t d j | ƒ ƒ ‚ n  | d k  rà | | j 7} n  | d k r˜t	 d „  | | | f Dƒ ƒ rt d ƒ ‚ n  t
 |  | ƒ }  t j |  |  d f } t j | ƒ }	 t j |	 | ƒ }	 t j |	 d t |	 j ƒ ƒ}	 t j | |	 | d	 | ƒS| d
 k r\| d k r\| d k oÅ| d k s×t d ƒ ‚ n  t
 |  | ƒ }  t j |  d |  |  d f } t j | ƒ }	 t j |	 | ƒ }	 t j |	 d t |	 j ƒ ƒ}	 t j | |	 | d	 | ƒSt
 |  | ƒ }  t
 | | ƒ } t j | ƒ } | d k r1| d k r| d k r| d k r|  d
 |  d  d } t j |  d f | d
 | d
 d !|  d f | d
 f } q.t |  | ƒ } q1t |  | ƒ } n  t
 | | ƒ } t j | | ƒ } |  j d
 k s~t j	 |  d
 |  d  k ƒ rt d ƒ ‚ n  | d k  r¨t d ƒ ‚ n  | j d
 k sÔt j	 | d
 | d  k  ƒ rãt d ƒ ‚ n  |  j | j d k rt d ƒ ‚ n  | j |  j | d
 k  rIt d | j |  j | d
 f ƒ ‚ n  |  d | | k  sr|  d | | k r…t d |  ƒ ‚ n  t | | j d
 ƒ } t | ƒ \ }
 } |
 j d } t | | j d
 ƒ } t | ƒ \ } } | j d } |  j } | j | d
 } | | | | k r=t d | | | | f ƒ ‚ n  | } } t j d | | d
 | f d t j d d ƒ} t j |  | | | d | ƒ| d k rÅt j | | |  d | | | |
 ƒ n  | d k rt j | | |  d | | | | d | | ƒn  t | j d
 ƒ } t j  | | f d | j ƒ} | d k rW| j! d | ƒ | | *n  | j! d | ƒ | | | | +| d k r| j! d | ƒ | | | )n  | rÄt" t j# | | f ƒ \ } } n  t$ d | | f ƒ \ } | | | | | d t% d t% ƒ\ } } }	 } | d k r$t& d ƒ ‚ n  | d k  rDt d | ƒ ‚ n  t j |	 j! | f | j d
 ƒ ƒ }	 t j | |	 | d	 | ƒS(    sµ  Compute the (coefficients of) interpolating B-spline.

    Parameters
    ----------
    x : array_like, shape (n,)
        Abscissas.
    y : array_like, shape (n, ...)
        Ordinates.
    k : int, optional
        B-spline degree. Default is cubic, k=3.
    t : array_like, shape (nt + k + 1,), optional.
        Knots.
        The number of knots needs to agree with the number of datapoints and
        the number of derivatives at the edges. Specifically, ``nt - n`` must
        equal ``len(deriv_l) + len(deriv_r)``.
    bc_type : 2-tuple or None
        Boundary conditions.
        Default is None, which means choosing the boundary conditions
        automatically. Otherwise, it must be a length-two tuple where the first
        element sets the boundary conditions at ``x[0]`` and the second
        element sets the boundary conditions at ``x[-1]``. Each of these must
        be an iterable of pairs ``(order, value)`` which gives the values of
        derivatives of specified orders at the given edge of the interpolation
        interval.
        Alternatively, the following string aliases are recognized:

        * ``"clamped"``: The first derivatives at the ends are zero. This is
           equivalent to ``bc_type=([(1, 0.0)], [(1, 0.0)])``.
        * ``"natural"``: The second derivatives at ends are zero. This is
          equivalent to ``bc_type=([(2, 0.0)], [(2, 0.0)])``.
        * ``"not-a-knot"`` (default): The first and second segments are the same
          polynomial. This is equivalent to having ``bc_type=None``.

    axis : int, optional
        Interpolation axis. Default is 0.
    check_finite : bool, optional
        Whether to check that the input arrays contain only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.
        Default is True.

    Returns
    -------
    b : a BSpline object of the degree ``k`` and with knots ``t``.

    Examples
    --------

    Use cubic interpolation on Chebyshev nodes:

    >>> def cheb_nodes(N):
    ...     jj = 2.*np.arange(N) + 1
    ...     x = np.cos(np.pi * jj / 2 / N)[::-1]
    ...     return x

    >>> x = cheb_nodes(20)
    >>> y = np.sqrt(1 - x**2)

    >>> from scipy.interpolate import BSpline, make_interp_spline
    >>> b = make_interp_spline(x, y)
    >>> np.allclose(b(x), y)
    True

    Note that the default is a cubic spline with a not-a-knot boundary condition

    >>> b.k
    3

    Here we use a 'natural' spline, with zero 2nd derivatives at edges:

    >>> l, r = [(2, 0.0)], [(2, 0.0)]
    >>> b_n = make_interp_spline(x, y, bc_type=(l, r))  # or, bc_type="natural"
    >>> np.allclose(b_n(x), y)
    True
    >>> x0, x1 = x[0], x[-1]
    >>> np.allclose([b_n(x0, 2), b_n(x1, 2)], [0, 0])
    True

    Interpolation of parametric curves is also supported. As an example, we
    compute a discretization of a snail curve in polar coordinates

    >>> phi = np.linspace(0, 2.*np.pi, 40)
    >>> r = 0.3 + np.cos(phi)
    >>> x, y = r*np.cos(phi), r*np.sin(phi)  # convert to Cartesian coordinates

    Build an interpolating curve, parameterizing it by the angle

    >>> from scipy.interpolate import make_interp_spline
    >>> spl = make_interp_spline(phi, np.c_[x, y])

    Evaluate the interpolant on a finer grid (note that we transpose the result
    to unpack it into a pair of x- and y-arrays)

    >>> phi_new = np.linspace(0, 2.*np.pi, 100)
    >>> x_new, y_new = spl(phi_new).T

    Plot the result

    >>> import matplotlib.pyplot as plt
    >>> plt.plot(x, y, 'o')
    >>> plt.plot(x_new, y_new, '-')
    >>> plt.show()

    See Also
    --------
    BSpline : base class representing the B-spline objects
    CubicSpline : a cubic spline in the polynomial basis
    make_lsq_spline : a similar factory function for spline fitting
    UnivariateSpline : a wrapper over FITPACK spline fitting routines
    splrep : a wrapper over FITPACK spline fitting routines

    s
   not-a-knots   Unknown boundary condition: %ss   axis {} is out of boundsi    c         s` s   |  ] } | d  k	 Vq d  S(   N(   RC   (   t   .0t   _(    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pys	   <genexpr>ò  s    s6   Too much info for k=0: t and bc_type can only be None.iÿÿÿÿR   R3   i   s0   Too much info for k=1: bc_type can only be None.i   g       @s'   Expect x to be a 1-D sorted array_like.s   Expect non-negative k.s'   Expect t to be a 1-D sorted array_like.s   x and y are incompatible.s   Got %d knots, need at least %d.s   Out of bounds w/ x = %s.sN   The number of derivatives at boundaries does not match: expected %s, got %s+%st   ordert   Ft   offsett   gbsvt   overwrite_abt   overwrite_bs   Collocation matix is singular.s0   illegal value in %d-th argument of internal gbsvN(   NN(   RŒ   ('   RC   R|   R   R   R"   R   R+   R2   t   formatR6   R%   R@   R4   R   R   R   R   R>   R   R)   Rx   Ry   RE   R1   R   R†   RW   R   R   t   _colloct   _handle_lhs_derivativesR   RF   RI   t   mapt   asarray_chkfiniteR   Rt   R   (   R   t   yR*   R.   t   bc_typeR3   R#   t   deriv_lt   deriv_rR,   t   deriv_l_ordst   deriv_l_valst   nleftt   deriv_r_ordst   deriv_r_valst   nrightR9   t   ntt   klt   kut   abt   extradimt   rhsRŒ   t   lut   pivt   info(    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyR   l  s¾    s#
,,!)	
0&"!&c         C` sC  t  |  | ƒ }  t  | | ƒ } t  | | ƒ } | d k	 rK t  | | ƒ } n t j |  ƒ } t j | ƒ } | j | k o‡ | j k  n s¤ t d j | ƒ ƒ ‚ n  | d k  rÀ | | j 7} n  t j	 | | ƒ } |  j d k st j
 |  d |  d  d k ƒ rt d ƒ ‚ n  |  j d | d k  r7t d ƒ ‚ n  | d k  rRt d ƒ ‚ n  | j d k s‚t j
 | d | d  d k  ƒ r‘t d ƒ ‚ n  |  j | j d k r¶t d	 ƒ ‚ n  | d k rýt j
 |  | | k  |  | | k Bƒ rýt d
 |  ƒ ‚ n  |  j | j k rt d ƒ ‚ n  | j | d } t } t | j d ƒ }	 t j | d | f d t j d d ƒ}
 t j | |	 f d | j d d ƒ} t j |  | | | j d |	 ƒ | |
 | ƒ | j | f | j d ƒ } t |
 d t d | d | ƒ} t | | f | d t d | ƒ} t j | ƒ } t j | | | d | ƒS(   s  Compute the (coefficients of) an LSQ B-spline.

    The result is a linear combination

    .. math::

            S(x) = \sum_j c_j B_j(x; t)

    of the B-spline basis elements, :math:`B_j(x; t)`, which minimizes

    .. math::

        \sum_{j} \left( w_j \times (S(x_j) - y_j) \right)^2

    Parameters
    ----------
    x : array_like, shape (m,)
        Abscissas.
    y : array_like, shape (m, ...)
        Ordinates.
    t : array_like, shape (n + k + 1,).
        Knots.
        Knots and data points must satisfy Schoenberg-Whitney conditions.
    k : int, optional
        B-spline degree. Default is cubic, k=3.
    w : array_like, shape (n,), optional
        Weights for spline fitting. Must be positive. If ``None``,
        then weights are all equal.
        Default is ``None``.
    axis : int, optional
        Interpolation axis. Default is zero.
    check_finite : bool, optional
        Whether to check that the input arrays contain only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.
        Default is True.

    Returns
    -------
    b : a BSpline object of the degree `k` with knots `t`.

    Notes
    -----

    The number of data points must be larger than the spline degree `k`.

    Knots `t` must satisfy the Schoenberg-Whitney conditions,
    i.e., there must be a subset of data points ``x[j]`` such that
    ``t[j] < x[j] < t[j+k+1]``, for ``j=0, 1,...,n-k-2``.

    Examples
    --------
    Generate some noisy data:

    >>> x = np.linspace(-3, 3, 50)
    >>> y = np.exp(-x**2) + 0.1 * np.random.randn(50)

    Now fit a smoothing cubic spline with a pre-defined internal knots.
    Here we make the knot vector (k+1)-regular by adding boundary knots:

    >>> from scipy.interpolate import make_lsq_spline, BSpline
    >>> t = [-1, 0, 1]
    >>> k = 3
    >>> t = np.r_[(x[0],)*(k+1),
    ...           t,
    ...           (x[-1],)*(k+1)]
    >>> spl = make_lsq_spline(x, y, t, k)

    For comparison, we also construct an interpolating spline for the same
    set of data:

    >>> from scipy.interpolate import make_interp_spline
    >>> spl_i = make_interp_spline(x, y)

    Plot both:

    >>> import matplotlib.pyplot as plt
    >>> xs = np.linspace(-3, 3, 100)
    >>> plt.plot(x, y, 'ro', ms=5)
    >>> plt.plot(xs, spl(xs), 'g-', lw=3, label='LSQ spline')
    >>> plt.plot(xs, spl_i(xs), 'b-', lw=3, alpha=0.7, label='interp spline')
    >>> plt.legend(loc='best')
    >>> plt.show()

    **NaN handling**: If the input arrays contain ``nan`` values, the result is
    not useful since the underlying spline fitting routines cannot deal with
    ``nan``. A workaround is to use zero weights for not-a-number data points:

    >>> y[8] = np.nan
    >>> w = np.isnan(y)
    >>> y[w] = 0.
    >>> tck = make_lsq_spline(x, y, t, w=~w)

    Notice the need to replace a ``nan`` by a numerical value (precise value
    does not matter as long as the corresponding weight is zero.)

    See Also
    --------
    BSpline : base class representing the B-spline objects
    make_interp_spline : a similar factory function for interpolating splines
    LSQUnivariateSpline : a FITPACK-based spline fitting routine
    splrep : a FITPACK-based fitting routine

    s   axis {} is out of boundsi    i   iÿÿÿÿs'   Expect x to be a 1-D sorted array_like.s   Need more x points.s   Expect non-negative k.s'   Expect t to be a 1-D sorted array_like.s   x & y are incompatible.s   Out of bounds w/ x = %s.s   Incompatible weights.R   R‰   RŠ   R   t   lowerR#   RŽ   R3   N(   R%   RC   R   t	   ones_likeR   R)   R2   R"   R   R4   R6   R1   RE   Rt   R   RW   R   R   R   t   _norm_eq_lsqRI   R   R   R   R   R>   (   R   R”   R.   R*   t   wR3   R#   R9   R§   R¢   R¡   R£   t
   cho_decompR,   (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyR   `  sT    i#004($
		(#   t
   __future__R    R   R   R   R   t   numpyR   t   scipy._lib.sixR   t   scipy.linalgR   R   R   R   t    R   R	   R
   R_   t   __all__R   R   R   R%   R;   R   Rx   Ry   R   R†   RC   Rt   R   R   (    (    (    s:   lib/python2.7/site-packages/scipy/interpolate/_bsplines.pyt   <module>   s,   "		ÿ ÿ 				ó