ó
ÚÆ÷Xc           @` sV  d  Z  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 e e j ƒ d k rŠ e j j Z n	 d „  Z d d „ Z e e j ƒ d	 k rÇ d d
 l m Z n d „  Z d „  Z e d „ Z e e j ƒ d k rd d l m Z n e e e d „ Z e e j ƒ d k rFe j j j Z n e d „ Z d S(   s4   Functions copypasted from newer versions of numpy.

i    (   t   divisiont   print_functiont   absolute_importN(   t   import_nose(   t   NumpyVersions	   1.7.0.devc      
   O` s™   t  j d t ƒ  } t  j d ƒ | | | Ž  } t | ƒ d k sY t d | j ƒ ‚ n  | d j |  k	 r t d | j |  | d f ƒ ‚ n  Wd QX| S(   s^  
        Fail unless the given callable throws the specified warning.

        This definition is copypasted from numpy 1.9.0.dev.
        The version in earlier numpy returns None.

        Parameters
        ----------
        warning_class : class
            The class defining the warning that `func` is expected to throw.
        func : callable
            The callable to test.
        *args : Arguments
            Arguments passed to `func`.
        **kwargs : Kwargs
            Keyword arguments passed to `func`.

        Returns
        -------
        The value returned by `func`.

        t   recordt   alwaysi    s!   No warning raised when calling %ss(   First warning for %s is not a %s( is %s)N(   t   warningst   catch_warningst   Truet   simplefiltert   lent   AssertionErrort   __name__t   category(   t   warning_classt   funct   argst   kwt   lt   result(    (    s7   /tmp/pip-build-X4mzal/scipy/scipy/_lib/_numpy_compat.pyt   _assert_warns   s    #c         O` sR   t  } t ƒ  } t j j d k r0 | j j } n | j j } | |  | | | | Ž S(   sc  
    Fail unless an exception of class exception_class and with message that
    matches expected_regexp is thrown by callable when invoked with arguments
    args and keyword arguments kwargs.
    Name of this function adheres to Python 3.2+ reference, but should work in
    all versions down to 2.6.
    Notes
    -----
    .. versionadded:: 1.8.0
    i   (   R	   R   t   syst   version_infot   majort   toolst   assert_raises_regext   assert_raises_regexp(   t   exception_classt   expected_regexpt   callable_objR   t   kwargst   __tracebackhide__t   noset   funcname(    (    s7   /tmp/pip-build-X4mzal/scipy/scipy/_lib/_numpy_compat.pyR   5   s    	s   1.10.0(   t   broadcast_toc         C` sP   t  |  ƒ t  | ƒ k	 rL | j d t  |  ƒ ƒ } | j rL | j |  ƒ qL n  | S(   Nt   type(   R$   t   viewt   __array_finalize__(   t   original_arrayt	   new_array(    (    s7   /tmp/pip-build-X4mzal/scipy/scipy/_lib/_numpy_compat.pyt   _maybe_view_as_subclassS   s
    	c      
   C` sõ   t  j | ƒ r t | ƒ n | f } t  j |  d t d | ƒ}  | r^ |  j r^ t d ƒ ‚ n  t d „  | Dƒ ƒ rƒ t d ƒ ‚ n  t  j |  f d d d d	 g d
 d g d | d d ƒj	 d } t
 |  | ƒ } | rñ |  j j rñ t | j _ n  | S(   Nt   copyt   suboks/   cannot broadcast a non-scalar to a scalar arrayc         s` s   |  ] } | d  k  Vq d S(   i    N(    (   t   .0t   size(    (    s7   /tmp/pip-build-X4mzal/scipy/scipy/_lib/_numpy_compat.pys	   <genexpr>d   s    s4   all elements of broadcast shape must be non-negativet   flagst   multi_indext   refs_okt   zerosize_okt   op_flagst   readonlyt	   itershapet   ordert   Ci    (   t   npt   iterablet   tuplet   arrayt   Falset   shapet
   ValueErrort   anyt   nditert   itviewsR)   R.   t	   writeableR	   (   R:   R<   R+   R3   t	   broadcastR   (    (    s7   /tmp/pip-build-X4mzal/scipy/scipy/_lib/_numpy_compat.pyt   _broadcast_to_   s    $c         C` s   t  |  | d | d t ƒS(   NR+   R3   (   RC   R	   (   R:   R<   R+   (    (    s7   /tmp/pip-build-X4mzal/scipy/scipy/_lib/_numpy_compat.pyR#   o   s    s   1.9.0(   t   uniquec         C` sþ  t  j |  ƒ j ƒ  }  | p | } | p* | } |  j d k rÇ | sK |  } nx |  f } | ry | t  j d t  j ƒ f 7} n  | rž | t  j d t  j ƒ f 7} n  | rÃ | t  j d t  j ƒ f 7} n  | S| rø |  j d | râ d n d ƒ } |  | } n |  j ƒ  |  } t  j	 t
 g | d | d  k f ƒ }	 | sA| |	 } n¹ | |	 f } | rh| | |	 f 7} n  | r¶t  j |	 ƒ d }
 t  j |  j d t  j ƒ} |
 | | <| | f 7} n  | rút  j	 t  j |	 ƒ |  j g f ƒ } | t  j | ƒ f 7} n  | S(   sP  
        Find the unique elements of an array.

        Returns the sorted unique elements of an array. There are three optional
        outputs in addition to the unique elements: the indices of the input array
        that give the unique values, the indices of the unique array that
        reconstruct the input array, and the number of times each unique value
        comes up in the input array.

        Parameters
        ----------
        ar : array_like
            Input array. This will be flattened if it is not already 1-D.
        return_index : bool, optional
            If True, also return the indices of `ar` that result in the unique
            array.
        return_inverse : bool, optional
            If True, also return the indices of the unique array that can be used
            to reconstruct `ar`.
        return_counts : bool, optional
            If True, also return the number of times each unique value comes up
            in `ar`.

            .. versionadded:: 1.9.0

        Returns
        -------
        unique : ndarray
            The sorted unique values.
        unique_indices : ndarray, optional
            The indices of the first occurrences of the unique values in the
            (flattened) original array. Only provided if `return_index` is True.
        unique_inverse : ndarray, optional
            The indices to reconstruct the (flattened) original array from the
            unique array. Only provided if `return_inverse` is True.
        unique_counts : ndarray, optional
            The number of times each of the unique values comes up in the
            original array. Only provided if `return_counts` is True.

            .. versionadded:: 1.9.0

        Notes
        -----
        Taken over from numpy 1.12.0-dev (c8408bf9c).  Omitted examples,
        see numpy documentation for those.

        i    t   kindt	   mergesortt	   quicksorti   iÿÿÿÿt   dtype(   R7   t
   asanyarrayt   flattenR-   t   emptyt   boolt   intpt   argsortt   sortt   concatenateR	   t   cumsumR<   t   nonzerot   diff(   t   art   return_indext   return_inverset   return_countst   optional_indicest   optional_returnst   rett   permt   auxt   flagt   iflagt   inv_idxt   idx(    (    s7   /tmp/pip-build-X4mzal/scipy/scipy/_lib/_numpy_compat.pyRD   w   sD    0		
&
%s
   1.12.0.devc         C` sÜ   t  j | d d d d ƒ} | j j d k rB | j t  j ƒ } n  t |  t t f ƒ ri t  j	 |  ƒ }  n  t |  t  j
 ƒ rÅ | r¡ | j | j d |  j ƒ } qÅ |  j | j k rÅ t d ƒ ‚ qÅ n  t  j |  | d d ƒS(	   s™  
        Evaluate a polynomial specified by its roots at points x.

        This function is copypasted from numpy 1.12.0.dev.

        If `r` is of length `N`, this function returns the value

        .. math:: p(x) = \prod_{n=1}^{N} (x - r_n)

        The parameter `x` is converted to an array only if it is a tuple or a
        list, otherwise it is treated as a scalar. In either case, either `x`
        or its elements must support multiplication and addition both with
        themselves and with the elements of `r`.

        If `r` is a 1-D array, then `p(x)` will have the same shape as `x`.  If
        `r` is multidimensional, then the shape of the result depends on the
        value of `tensor`. If `tensor is ``True`` the shape will be r.shape[1:]
        + x.shape; that is, each polynomial is evaluated at every value of `x`.
        If `tensor` is ``False``, the shape will be r.shape[1:]; that is, each
        polynomial is evaluated only for the corresponding broadcast value of
        `x`. Note that scalars have shape (,).

        Parameters
        ----------
        x : array_like, compatible object
            If `x` is a list or tuple, it is converted to an ndarray, otherwise
            it is left unchanged and treated as a scalar. In either case, `x`
            or its elements must support addition and multiplication with with
            themselves and with the elements of `r`.
        r : array_like
            Array of roots. If `r` is multidimensional the first index is the
            root index, while the remaining indices enumerate multiple
            polynomials. For instance, in the two dimensional case the roots of
            each polynomial may be thought of as stored in the columns of `r`.
        tensor : boolean, optional
            If True, the shape of the roots array is extended with ones on the
            right, one for each dimension of `x`. Scalars have dimension 0 for
            this action. The result is that every column of coefficients in `r`
            is evaluated for every element of `x`. If False, `x` is broadcast
            over the columns of `r` for the evaluation.  This keyword is useful
            when `r` is multidimensional. The default value is True.

        Returns
        -------
        values : ndarray, compatible object
            The shape of the returned array is described above.

        See Also
        --------
        polyroots, polyfromroots, polyval

        Examples
        --------
        >>> from numpy.polynomial.polynomial import polyvalfromroots
        >>> polyvalfromroots(1, [1,2,3])
        0.0
        >>> a = np.arange(4).reshape(2,2)
        >>> a
        array([[0, 1],
               [2, 3]])
        >>> polyvalfromroots(a, [-1, 0, 1])
        array([[ -0.,   0.],
               [  6.,  24.]])
        >>> r = np.arange(-2, 2).reshape(2,2) # multidimensional coefficients
        >>> r # each column of r defines one polynomial
        array([[-2, -1],
               [ 0,  1]])
        >>> b = [-2, 1]
        >>> polyvalfromroots(b, r, tensor=True)
        array([[-0.,  3.],
               [ 3., 0.]])
        >>> polyvalfromroots(b, r, tensor=False)
        array([-0.,  0.])
        t   ndmini   R*   i    s   ?bBhHiIlLqQpPs,   x.ndim must be < r.ndim when tensor == Falset   axis(   i   (   R7   R:   RH   t   chart   astypet   doublet
   isinstanceR9   t   listt   asarrayt   ndarrayt   reshapeR<   t   ndimR=   t   prod(   t   xt   rt   tensor(    (    s7   /tmp/pip-build-X4mzal/scipy/scipy/_lib/_numpy_compat.pyt   polyvalfromrootsÕ   s    K (   t   __doc__t
   __future__R    R   R   R   R   t   numpyR7   t   numpy.testing.nosetesterR   t   scipy._lib._versionR   t   __version__t   testingt   assert_warnsR   t   NoneR   R#   R)   RC   R;   RD   t
   polynomialRp   R	   (    (    (    s7   /tmp/pip-build-X4mzal/scipy/scipy/_lib/_numpy_compat.pyt   <module>   s*   	$		[