
˽Xc           @` s   d  Z  d d l m Z m Z m Z d d l Z d d l m Z m Z m	 Z	 m
 Z
 m Z m Z d d d d d	 g Z d
 d  Z d d
 d d d  Z d   Z d   Z e d  Z d S(   sW   
Functions which are common and require SciPy Base and Level 1 SciPy
(special, linalg)
i    (   t   divisiont   print_functiont   absolute_importN(   t   aranget   newaxist   hstackt   productt   arrayt
   fromstringt   central_diff_weightst
   derivativet   lenat   ascentt   facei   c         C` s   |  | d k  r t  d   n  |  d d k r> t  d   n  d d l m } |  d ?} t | | d  } | d d  t f } | d	 } x- t d |   D] } t | | | g  } q Wt t d | d  d
 d | j |  | } | S(   s  
    Return weights for an Np-point central derivative.

    Assumes equally-spaced function points.

    If weights are in the vector w, then
    derivative is w[0] * f(x-ho*dx) + ... + w[-1] * f(x+h0*dx)

    Parameters
    ----------
    Np : int
        Number of points for the central derivative.
    ndiv : int, optional
        Number of divisions.  Default is 1.

    Notes
    -----
    Can be inaccurate for large number of points.

    i   s;   Number of points must be at least the derivative order + 1.i   i    s!   The number of points must be odd.(   t   linalgg      ?Ng        t   axis(	   t
   ValueErrort   scipyR   R   R   t   rangeR   R   t   inv(   t   Npt   ndivR   t   hot   xt   Xt   kt   w(    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/common.pyR	      s    

0g      ?i   c   
   
   C` sv  | | d k  r t  d   n  | d d k r> t  d   n  | d k r | d k rr t d d d g  d } q| d	 k r t d d
 d d d g  d } q| d k r t d d d d d d d g  d } q| d k rt d d d d d d d d d g	  d } qt | d  } n | d k r| d k rPt d d d g  } q| d	 k r~t d d d d d g  d } q| d k rt d d d d  d d d g  d! } q| d k rt d d" d# d$ d% d$ d# d" d g	  d& } qt | d  } n t | |  } d' } | d ?} x; t |  D]- }	 | | |	 |  | |	 | | |  7} q*W| t | f | d( d S()   s6  
    Find the n-th derivative of a function at a point.

    Given a function, use a central difference formula with spacing `dx` to
    compute the `n`-th derivative at `x0`.

    Parameters
    ----------
    func : function
        Input function.
    x0 : float
        The point at which `n`-th derivative is found.
    dx : float, optional
        Spacing.
    n : int, optional
        Order of the derivative. Default is 1.
    args : tuple, optional
        Arguments
    order : int, optional
        Number of points to use, must be odd.

    Notes
    -----
    Decreasing the step size too small can result in round-off error.

    Examples
    --------
    >>> from scipy.misc import derivative
    >>> def f(x):
    ...     return x**3 + x**2
    >>> derivative(f, 1.0, dx=1e-6)
    4.9999999999217337

    i   sm   'order' (the number of points used to compute the derivative), must be at least the derivative order 'n' + 1.i   i    sJ   'order' (the number of points used to compute the derivative) must be odd.i   ig       @i   ii   g      (@i   i	   ii-   ig      N@ii   i`i  iXi    ig     @@g       i   iii  ig     f@i   ii  ig     @g        R   (   R   R   R	   R   R   (
   t   funct   x0t   dxt   nt   argst   ordert   weightst   valR   R   (    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/common.pyR
   2   s<    #"(."(.
+c           C` s   t  d   d S(   s  
    Function that previously returned an example image

    .. note:: Removed in 0.17

    Parameters
    ----------
    None

    Returns
    -------
    None

    Raises
    ------
    RuntimeError
        This functionality has been removed due to licensing reasons.

    Notes
    -----
    The image previously returned by this function has an incompatible license
    and has been removed from SciPy. Please use `face` or `ascent` instead.

    See Also
    --------
    face, ascent
    sL   lena() is no longer included in SciPy, please use ascent() or face() insteadN(   t   RuntimeError(    (    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/common.pyR   {   s    c          C` sj   d d l  }  d d l } | j j | j j t  d  } t | d   } t |  j |   } Wd QX| S(   sw  
    Get an 8-bit grayscale bit-depth, 512 x 512 derived image for easy use in demos

    The image is derived from accent-to-the-top.jpg at
    http://www.public-domain-image.com/people-public-domain-images-pictures/

    Parameters
    ----------
    None

    Returns
    -------
    ascent : ndarray
       convenient image to use for testing and demonstration

    Examples
    --------
    >>> import scipy.misc
    >>> ascent = scipy.misc.ascent()
    >>> ascent.shape
    (512, 512)
    >>> ascent.max()
    255

    >>> import matplotlib.pyplot as plt
    >>> plt.gray()
    >>> plt.imshow(ascent)
    >>> plt.show()

    i    Ns
   ascent.datt   rb(	   t   picklet   ost   patht   joint   dirnamet   __file__t   openR   t   load(   R%   R&   t   fnamet   fR   (    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/common.pyR      s    !c         C` s  d d l  } d d l } t | j j | j j t  d  d   } | j   } Wd QX| j |  } t	 | d d } d | _
 |  t k r d
 | d d  d d  d f d | d d  d d  d f d | d d  d d  d f j d  } n  | S(   sw  
    Get a 1024 x 768, color image of a raccoon face.

    raccoon-procyon-lotor.jpg at http://www.public-domain-image.com

    Parameters
    ----------
    gray : bool, optional
        If True return 8-bit grey-scale image, otherwise return a color image

    Returns
    -------
    face : ndarray
        image of a racoon face

    Examples
    --------
    >>> import scipy.misc
    >>> face = scipy.misc.face()
    >>> face.shape
    (768, 1024, 3)
    >>> face.max()
    255
    >>> face.dtype
    dtype('uint8')

    >>> import matplotlib.pyplot as plt
    >>> plt.gray()
    >>> plt.imshow(face)
    >>> plt.show()

    i    Ns   face.datR$   t   dtypet   uint8i   i   i   gzG?gQ?i   gQ?i   (   i   i   i   (   t   bz2R&   R+   R'   R(   R)   R*   t   readt
   decompressR   t   shapet   Truet   astype(   t   grayR1   R&   R.   t   rawdatat   dataR   (    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/common.pyR      s    !-	q(    (   t   __doc__t
   __future__R    R   R   t   numpyt   npR   R   R   R   R   R   t   __all__R	   R
   R   R   t   FalseR   (    (    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/common.pyt   <module>   s   .$I	 	'