ó
¦–Õ\c           @` sq  d  d l  m Z m Z m Z d  d l Z d  d l m Z d  d l Z y  d  d l	 m
 Z
 m Z m Z Wn- e k
 r“ d  d l m
 Z
 m Z m Z n Xd d l m Z m Z m Z m Z m Z d d l m Z d d	 l m Z d
 Z d j e ƒ Z d j e ƒ Z d j e ƒ Z d j e ƒ Z d j e e ƒ Z d „  Z d „  Z  d „  Z! d e" f d „  ƒ  YZ# e$ d „ Z% d S(   i    (   t   absolute_importt   divisiont   print_functionN(   t   count(   t   concatt   merget   uniquei   (   t   Arrayt   asarrayt	   blockwiset   getitemt   apply_infer_dtypei   (   t   HighLevelGraph(   t   flattens   \w+s   (?:{0:}(?:,{0:})*,?)?s   \({}\)s   {0:}(?:,{0:})*s   ^{0:}->{1:}$c         C` sû   |  j  d d ƒ }  t j t |  ƒ s< t d j |  ƒ ƒ ‚ n  |  j d ƒ \ } } g  t j t | ƒ D] } t	 t j t
 | ƒ ƒ ^ qd } g  t j t | ƒ D] } t	 t j t
 | ƒ ƒ ^ q› } t | ƒ d k rë | d d k rë | d n | } | | f S(	   sÜ  
    Parse string signatures for a generalized universal function.

    Arguments
    ---------
    signature : string
        Generalized universal function signature, e.g., ``(m,n),(n,p)->(m,p)``
        for ``np.matmul``.

    Returns
    -------
    Tuple of input and output core dimensions parsed from the signature, each
    of the form List[Tuple[str, ...]], except for one output. For one  output
    core dimension is not a list, but of the form Tuple[str, ...]
    t    t    s    Not a valid gufunc signature: {}s   ->i   iÿÿÿÿt   ,i    (   t   replacet   ret   matcht
   _SIGNATUREt
   ValueErrort   formatt   splitt   findallt	   _ARGUMENTt   tuplet   _DIMENSION_NAMEt   len(   t	   signaturet   in_txtt   out_txtt   argt   inst   outs(    (    s0   lib/python2.7/site-packages/dask/array/gufunc.pyt   _parse_gufunc_signature   s    442c         C` sT  t  | ƒ } t | t ƒ s! d n	 t  | ƒ } |  d k	 rT | d k	 rT t d ƒ ‚ n  |  ry t |  t ƒ ry t d ƒ ‚ n  | d k r‹ | n | g } t t t  | ƒ ƒ } t  g  | D] } t  | ƒ d k r³ t ^ q³ ƒ }	 | r|	 d k rû t d ƒ ‚ n  t  | ƒ | d g } n  | | }
 | d k	 r¬t | t ƒ sIt d ƒ ‚ n  | r¬| d } t  | ƒ d k rzt d ƒ ‚ n  x, | D]! } | | k rt d ƒ ‚ qqWq¬n  |  d k r$| d k	 ròg  |
 D] } | rà| f n t ƒ  ^ qË}  qBg  |
 D]" } t t	 t  | ƒ d ƒ ƒ ^ qù}  n t |  t ƒ sBt d	 ƒ ‚ n  g  |  D]$ } t | t ƒ rg| f n | ^ qI}  |	 d k r§| t  |  ƒ k r§| | t  |  ƒ k sÉ|	 d k rØ| | t  |  ƒ k rØt d
 ƒ ‚ n  |  | } | rî| n, g  | D]" } t t	 t  | ƒ d ƒ ƒ ^ qõ} |  |  } xY t
 t | | ƒ ƒ D]B \ } \ } } t  | ƒ t  | ƒ k r=t d j | ƒ ƒ ‚ q=q=W| sèx¾ t
 t | | ƒ ƒ D]B \ } \ } } t  | ƒ t  | ƒ k rŸt d j | ƒ ƒ ‚ qŸqŸWnb | rJ| d } x) | D]! } | | k rÿt d ƒ ‚ qÿqÿW| d } g  | D] } | ^ q5} n  | | f S(   sÿ  
    Validates logic of `axes`/`axis`/`keepdims` arguments and normalize them.
    Refer to [1]_ for details

    Arguments
    ---------
    axes: List of tuples
    axis: int
    keepdims: bool
    input_coredimss: List of Tuple of dims
    output_coredimss: List of Tuple of dims

    Returns
    -------
    input_axes: List of tuple of int
    output_axes: List of tuple of int

    References
    ----------
    .. [1] https://docs.scipy.org/doc/numpy/reference/ufuncs.html#optional-keyword-arguments
    i   s>   Only one of `axis` or `axes` keyword arguments should be givens   `axes` has to be of type listi    s.   `keepdims` can only be used for scalar outputss*   `axis` argument has to be an integer values9   `axis` can be used only, if one core dimension is presents3   To use `axis`, all core dimensions have to be equals    `axes` argument has to be a listsR   The number of `axes` entries is not equal the number of input and output argumentssv   The number of `axes` entries for argument #{} is not equal the number of respective input core dimensions in signaturesw   The number of `axes` entries for argument #{} is not equal the number of respective output core dimensions in signatures7   To use `keepdims`, all core dimensions have to be equalN(   R   t
   isinstancet   listt   NoneR   t   filtert   Truet   intR   t   ranget	   enumeratet   zipR   (   t   axest   axist   keepdimst   input_coredimsst   output_coredimsst   nint   noutt   filtered_core_dimst   xt   nr_outputs_with_coredimst	   core_dimst   cd0t   cdt   icdt   at   output_axest   ocdt
   input_axest   idxt   iaxt   oaxt   icd0t   iax0t   _(    (    s0   lib/python2.7/site-packages/dask/array/gufunc.pyt   _validate_normalize_axes:   sl    !1

.214"
;
(	(	

c   E   
   ` s˜  | j  d d" ƒ } | j  d d" ƒ } | j  d t ƒ } | j  d d" ƒ } | j  d d" ƒ } | j  d d" ƒ }	 | j  d t ƒ }
 t | t ƒ sœ t d ƒ ‚ n  t | ƒ \ } } t | t ƒ sÃ d" n	 t | ƒ ‰ | d" k r|	 rù t	 j
 |  d	 | ƒ} n |  } t | | | d
 d ˆ ƒ } n  t | t t f ƒ r{ˆ d" k rrt | ƒ d k r_t d ƒ ‚ n  | } | d } qŸ| } n$ ˆ d" k	 r–t d ƒ ‚ n  | g } |	 rÃt	 j
 |  d	 | d | ƒ}  n  | d" k rØi  } n  t | | | | | ƒ \ } } g  | D] } t | ƒ ^ qý} t | ƒ t | ƒ k rPt d t | ƒ t | ƒ f ƒ n  g  } x˜ t | | | ƒ D]„ \ } ‰ } | j ‰ t ‡ f d †  ˆ Dƒ ƒ ‰ t ‡ f d †  t t ˆ ƒ d d ƒ Dƒ ƒ ˆ } | j | ƒ } | j | ƒ qiW| } g  | D] } | j ^ qþ} g  | D] } | j ^ q} g  t | | ƒ D]" \ } } t | ƒ t | ƒ ^ q?} | ryt | ƒ n d" } g  t | | | ƒ D]( \ } } } t t | | | ƒ ƒ ^ q’} t | Œ  ‰ ˆ j | ƒ g  | D]) } t d „  t | | | ƒ Dƒ ƒ ^ qà}  g  t |  | ƒ D] \ }! }" |! |" ^ q}# |  rSt |  d t ƒn t ƒ  }$ i  }% i  }& x› t |# | | ƒ D]‡ \ }' ‰ }( xu t |' ˆ |( ƒ D]a \ }) }* }+ |% j |) g  ƒ }, |, j |* ƒ |, |% |) <|& j |) g  ƒ }- |- j |+ ƒ |- |& |) <qWq{Wxú |% j ƒ  D]ì \ }) }. t |. ƒ j d h ƒ d t |. ƒ h k rat d j |) ƒ ƒ ‚ n  |
 s|& |) }( |) ˆ k r­|( d d ˆ |) k  r­t d j |) ƒ ƒ ‚ n  t t d „  t |. |( ƒ Dƒ ƒ ƒ }/ t |/ ƒ d k rÿt d j |) ƒ ƒ ‚ qÿqqWt t  t | |# ƒ ƒ ƒ }0 t! |  |$ d t" d t# |0 | Ž}1 |1 j }2 |1 j }3 t t$ |1 j% ƒ  ƒ ƒ }4 |4 d d j& d ƒ \ }5 }6 ˆ d" k r§| g } | g } n  g  }7 xÖt t' d ƒ | | | ƒ D]¹\ ‰ }8 }9 }: t ‡ f d †  |8 Dƒ ƒ }; t |8 ƒ d# ‰  |2 |; }< |3 |; }= d |5 ˆ |6 f ‰ ‡  ‡ ‡ ‡ f d †  |4 Dƒ }> t( j) ˆ |> d |1 g ƒ}? t* |? ˆ d  |= d! |< d |9 ƒ}@ | rÌt |@ j ƒ t+ d" ƒ f t |: ƒ t	 j, f }A |@ |A }@ n  d" g t |@ j ƒ }B x7 t t t |: ƒ d ƒ |: ƒ D] \ ‰ }C ˆ |B |C <qWd }D xA t t |B ƒ ƒ D]- ‰ |B ˆ d" k r5|D |B ˆ <|D d 7}D q5q5W|@ j |B ƒ }@ |7 j |@ ƒ qÉWˆ r|7 S|7 d S($   sž  
    Apply a generalized ufunc or similar python function to arrays.

    ``signature`` determines if the function consumes or produces core
    dimensions. The remaining dimensions in given input arrays (``*args``)
    are considered loop dimensions and are required to broadcast
    naturally against each other.

    In other terms, this function is like np.vectorize, but for
    the blocks of dask arrays. If the function itself shall also
    be vectorized use ``vectorize=True`` for convenience.

    Parameters
    ----------
    func : callable
        Function to call like ``func(*args, **kwargs)`` on input arrays
        (``*args``) that returns an array or tuple of arrays. If multiple
        arguments with non-matching dimensions are supplied, this function is
        expected to vectorize (broadcast) over axes of positional arguments in
        the style of NumPy universal functions [1]_ (if this is not the case,
        set ``vectorize=True``). If this function returns multiple outputs,
        ``output_core_dims`` has to be set as well.
    signature: string
        Specifies what core dimensions are consumed and produced by ``func``.
        According to the specification of numpy.gufunc signature [2]_
    *args : numeric
        Input arrays or scalars to the callable function.
    axes: List of tuples, optional, keyword only
        A list of tuples with indices of axes a generalized ufunc should operate on.
        For instance, for a signature of ``"(i,j),(j,k)->(i,k)"`` appropriate for
        matrix multiplication, the base elements are two-dimensional matrices
        and these are taken to be stored in the two last axes of each argument. The
        corresponding axes keyword would be ``[(-2, -1), (-2, -1), (-2, -1)]``.
        For simplicity, for generalized ufuncs that operate on 1-dimensional arrays
        (vectors), a single integer is accepted instead of a single-element tuple,
        and for generalized ufuncs for which all outputs are scalars, the output
        tuples can be omitted.
    axis: int, optional, keyword only
        A single axis over which a generalized ufunc should operate. This is a short-cut
        for ufuncs that operate over a single, shared core dimension, equivalent to passing
        in axes with entries of (axis,) for each single-core-dimension argument and ``()`` for
        all others. For instance, for a signature ``"(i),(i)->()"``, it is equivalent to passing
        in ``axes=[(axis,), (axis,), ()]``.
    keepdims: bool, optional, keyword only
        If this is set to True, axes which are reduced over will be left in the result as
        a dimension with size one, so that the result will broadcast correctly against the
        inputs. This option can only be used for generalized ufuncs that operate on inputs
        that all have the same number of core dimensions and with outputs that have no core
        dimensions , i.e., with signatures like ``"(i),(i)->()"`` or ``"(m,m)->()"``.
        If used, the location of the dimensions in the output can be controlled with axes
        and axis.
    output_dtypes : Optional, dtype or list of dtypes, keyword only
        Valid numpy dtype specification or list thereof.
        If not given, a call of ``func`` with a small set of data
        is performed in order to try to  automatically determine the
        output dtypes.
    output_sizes : dict, optional, keyword only
        Optional mapping from dimension names to sizes for outputs. Only used if
        new core dimensions (not found on inputs) appear on outputs.
    vectorize: bool, keyword only
        If set to ``True``, ``np.vectorize`` is applied to ``func`` for
        convenience. Defaults to ``False``.
    allow_rechunk: Optional, bool, keyword only
        Allows rechunking, otherwise chunk sizes need to match and core
        dimensions are to consist only of one chunk.
        Warning: enabling this can increase memory usage significantly.
        Defaults to ``False``.
    **kwargs : dict
        Extra keyword arguments to pass to `func`

    Returns
    -------
    Single dask.array.Array or tuple of dask.array.Array

    Examples
    --------
    >>> import dask.array as da
    >>> import numpy as np
    >>> def stats(x):
    ...     return np.mean(x, axis=-1), np.std(x, axis=-1)
    >>> a = da.random.normal(size=(10,20,30), chunks=(5, 10, 30))
    >>> mean, std = da.apply_gufunc(stats, "(i)->(),()", a)
    >>> mean.compute().shape
    (10, 20)


    >>> def outer_product(x, y):
    ...     return np.einsum("i,j->ij", x, y)
    >>> a = da.random.normal(size=(   20,30), chunks=(10, 30))
    >>> b = da.random.normal(size=(10, 1,40), chunks=(5, 1, 40))
    >>> c = da.apply_gufunc(outer_product, "(i),(j)->(i,j)", a, b, vectorize=True)
    >>> c.compute().shape
    (10, 20, 30, 40)

    References
    ----------
    .. [1] https://docs.scipy.org/doc/numpy/reference/ufuncs.html
    .. [2] https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html
    R-   R.   R/   t   output_dtypest   output_sizest	   vectorizet   allow_rechunks$   `signature` has to be of type stringR   t   apply_gufunci   s_   Must specify single dtype or list of one dtype for `output_dtypes` for function with one outputi    sS   Must specify tuple of dtypes for `output_dtypes` for function with multiple outputst   otypessD   According to `signature`, `func` requires %d arguments, but %s givenc         3` s1   |  ]' } | d  k  r | n | t  ˆ  ƒ Vq d S(   i    N(   R   (   t   .0R;   (   t   shape(    s0   lib/python2.7/site-packages/dask/array/gufunc.pys	   <genexpr>:  s    c         3` s!   |  ] } | ˆ  k r | Vq d  S(   N(    (   RL   t   i(   R@   (    s0   lib/python2.7/site-packages/dask/array/gufunc.pys	   <genexpr>;  s    c         s` s   |  ] } d  | Vq d S(   s   __loopdim%d__N(    (   RL   t   d(    (    s0   lib/python2.7/site-packages/dask/array/gufunc.pys	   <genexpr>J  s    t   keys1   Dimension `'{}'` with different lengths in arrayssÆ   Core dimension `'{}'` consists of multiple chunks. To fix, rechunk into a single chunk along this dimension or set `allow_rechunk=True`, but beware that this may increase memory usage significantly.c         s` s'   |  ] \ } } | d  k r | Vq d S(   i   N(    (   RL   t   st   c(    (    s0   lib/python2.7/site-packages/dask/array/gufunc.pys	   <genexpr>h  s    s1   Dimension `'{}'` with different chunksize presentt   dtypet   concatenatet   -c         3` s   |  ] } ˆ  | Vq d  S(   N(    (   RL   RO   (   t   core_shapes(    s0   lib/python2.7/site-packages/dask/array/gufunc.pys	   <genexpr>‰  s    s   %s_%d-%sc         ` s=   i  |  ]3 } ˆ r! t  | ˆ f n | ˆ f | d  ˆ  “ q S(   i   (   R
   (   RL   RP   (   t   core_chunkindsRN   t	   leaf_nameR3   (    s0   lib/python2.7/site-packages/dask/array/gufunc.pys
   <dictcomp>Ž  s   	 t   dependenciest   chunksRM   N(   i    (-   t   popR&   t   FalseR$   t   strt	   TypeErrorR#   R%   R   t   npRH   R   R   R   RE   R   R,   RM   R*   t	   transposet   appendRZ   t   maxt   dictR   t   updatet   gett   itemst   sett   unionR   R   R   R	   R)   R(   R   t   __dask_keys__R   R   R   t   from_collectionsR   t   slicet   newaxis(E   t   funcR   t   argst   kwargsR-   R.   R/   RF   RG   RH   RI   R0   R1   t   tempfuncRK   R>   R<   R;   t   transposed_argsR    t   input_coredimst   tidct   transposed_argt   input_shapest   input_chunkssRQ   R9   t   num_loopdimst   max_loopdimst   nR:   t   core_input_shapest   loop_input_dimsst   lRR   t   input_dimsst   loop_output_dimst	   dimsizesst   chunksizesst   dimst
   chunksizest   dimt   sizet	   chunksizet   dimsizest   chunksizes_t   sizest   relevant_chunksizest   argindst   tmpt   loop_output_shapet   loop_output_chunkst   keyst   namet   tokent	   leaf_arrsR=   t   odtRA   t   core_output_shapet   output_shapet   output_chunkst   leaf_dskt   grapht   leaf_arrt   slicest   tidcst   oat   j(    (   RW   RV   RN   R@   RX   R3   RM   s0   lib/python2.7/site-packages/dask/array/gufunc.pyRJ   ˜   sè    d!			"	48A6,!""
*
$%				.

	0,
t   gufuncc           B` s    e  Z d  Z d „  Z d „  Z RS(   sÁ  
    Binds `pyfunc` into ``dask.array.apply_gufunc`` when called.

    Parameters
    ----------
    pyfunc : callable
        Function to call like ``func(*args, **kwargs)`` on input arrays
        (``*args``) that returns an array or tuple of arrays. If multiple
        arguments with non-matching dimensions are supplied, this function is
        expected to vectorize (broadcast) over axes of positional arguments in
        the style of NumPy universal functions [1]_ (if this is not the case,
        set ``vectorize=True``). If this function returns multiple outputs,
        ``output_core_dims`` has to be set as well.
    signature : String, keyword only
        Specifies what core dimensions are consumed and produced by ``func``.
        According to the specification of numpy.gufunc signature [2]_
    axes: List of tuples, optional, keyword only
        A list of tuples with indices of axes a generalized ufunc should operate on.
        For instance, for a signature of ``"(i,j),(j,k)->(i,k)"`` appropriate for
        matrix multiplication, the base elements are two-dimensional matrices
        and these are taken to be stored in the two last axes of each argument. The
        corresponding axes keyword would be ``[(-2, -1), (-2, -1), (-2, -1)]``.
        For simplicity, for generalized ufuncs that operate on 1-dimensional arrays
        (vectors), a single integer is accepted instead of a single-element tuple,
        and for generalized ufuncs for which all outputs are scalars, the output
        tuples can be omitted.
    axis: int, optional, keyword only
        A single axis over which a generalized ufunc should operate. This is a short-cut
        for ufuncs that operate over a single, shared core dimension, equivalent to passing
        in axes with entries of (axis,) for each single-core-dimension argument and ``()`` for
        all others. For instance, for a signature ``"(i),(i)->()"``, it is equivalent to passing
        in ``axes=[(axis,), (axis,), ()]``.
    keepdims: bool, optional, keyword only
        If this is set to True, axes which are reduced over will be left in the result as
        a dimension with size one, so that the result will broadcast correctly against the
        inputs. This option can only be used for generalized ufuncs that operate on inputs
        that all have the same number of core dimensions and with outputs that have no core
        dimensions , i.e., with signatures like ``"(i),(i)->()"`` or ``"(m,m)->()"``.
        If used, the location of the dimensions in the output can be controlled with axes
        and axis.
    output_dtypes : Optional, dtype or list of dtypes, keyword only
        Valid numpy dtype specification or list thereof.
        If not given, a call of ``func`` with a small set of data
        is performed in order to try to  automatically determine the
        output dtypes.
    output_sizes : dict, optional, keyword only
        Optional mapping from dimension names to sizes for outputs. Only used if
        new core dimensions (not found on inputs) appear on outputs.
    vectorize: bool, keyword only
        If set to ``True``, ``np.vectorize`` is applied to ``func`` for
        convenience. Defaults to ``False``.
    allow_rechunk: Optional, bool, keyword only
        Allows rechunking, otherwise chunk sizes need to match and core
        dimensions are to consist only of one chunk.
        Warning: enabling this can increase memory usage significantly.
        Defaults to ``False``.

    Returns
    -------
    Wrapped function

    Examples
    --------
    >>> import dask.array as da
    >>> import numpy as np
    >>> a = da.random.normal(size=(10,20,30), chunks=(5, 10, 30))
    >>> def stats(x):
    ...     return np.mean(x, axis=-1), np.std(x, axis=-1)
    >>> gustats = da.gufunc(stats, signature="(i)->(),()", output_dtypes=(float, float))
    >>> mean, std = gustats(a)
    >>> mean.compute().shape
    (10, 20)


    >>> a = da.random.normal(size=(   20,30), chunks=(10, 30))
    >>> b = da.random.normal(size=(10, 1,40), chunks=(5, 1, 40))
    >>> def outer_product(x, y):
    ...     return np.einsum("i,j->ij", x, y)
    >>> guouter_product = da.gufunc(outer_product, signature="(i),(j)->(i,j)", output_dtypes=float, vectorize=True)
    >>> c = guouter_product(a, b)
    >>> c.compute().shape
    (10, 20, 30, 40)

    References
    ----------
    .. [1] https://docs.scipy.org/doc/numpy/reference/ufuncs.html
    .. [2] https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html
    c         K` sñ   | |  _  | j d d  ƒ |  _ | j d t ƒ |  _ | j d d  ƒ |  _ | j d d  ƒ |  _ | j d t ƒ |  _ | j d d  ƒ |  _	 | j d d  ƒ |  _
 | j d t ƒ |  _ | rÆ t d	 ƒ ‚ n  d
 j d t |  j  ƒ d |  j ƒ |  _ d  S(   NR   RH   R-   R.   R/   RG   RF   RI   s(   Unsupported keyword argument(s) providedsì  
        Bound ``dask.array.gufunc``
        func: ``{func}``
        signature: ``'{signature}'``

        Parameters
        ----------
        *args : numpy/dask arrays or scalars
            Arrays to which to apply to ``func``. Core dimensions as specified in
            ``signature`` need to come last.
        **kwargs : dict
            Extra keyword arguments to pass to ``func``

        Returns
        -------
        Single dask.array.Array or tuple of dask.array.Array
        Rm   (   t   pyfuncR[   R&   R   R\   RH   R-   R.   R/   RG   RF   RI   R^   R   R]   t   __doc__(   t   selfRž   Ro   (    (    s0   lib/python2.7/site-packages/dask/array/gufunc.pyt   __init__  s    	c         O` sj   t  |  j |  j d |  j d |  j d |  j d |  j d |  j d |  j d |  j	 p` | j
 d t ƒ | | ŽS(   NRH   R-   R.   R/   RG   RF   RI   (   RJ   Rž   R   RH   R-   R.   R/   RG   RF   RI   R[   R\   (   R    Rn   Ro   (    (    s0   lib/python2.7/site-packages/dask/array/gufunc.pyt   __call__!  s    								(   t   __name__t
   __module__RŸ   R¡   R¢   (    (    (    s0   lib/python2.7/site-packages/dask/array/gufunc.pyR   ©  s   X	c         ` sp   d d d d d d d h } t  | ƒ j ˆ  j ƒ  ƒ rE t d ƒ ‚ n  ‡  ‡ f d	 †  } d
 j d ˆ ƒ | _ | S(   sk  
    Decorator for ``dask.array.gufunc``.

    Parameters
    ----------
    signature : String
        Specifies what core dimensions are consumed and produced by ``func``.
        According to the specification of numpy.gufunc signature [2]_
    axes: List of tuples, optional, keyword only
        A list of tuples with indices of axes a generalized ufunc should operate on.
        For instance, for a signature of ``"(i,j),(j,k)->(i,k)"`` appropriate for
        matrix multiplication, the base elements are two-dimensional matrices
        and these are taken to be stored in the two last axes of each argument. The
        corresponding axes keyword would be ``[(-2, -1), (-2, -1), (-2, -1)]``.
        For simplicity, for generalized ufuncs that operate on 1-dimensional arrays
        (vectors), a single integer is accepted instead of a single-element tuple,
        and for generalized ufuncs for which all outputs are scalars, the output
        tuples can be omitted.
    axis: int, optional, keyword only
        A single axis over which a generalized ufunc should operate. This is a short-cut
        for ufuncs that operate over a single, shared core dimension, equivalent to passing
        in axes with entries of (axis,) for each single-core-dimension argument and ``()`` for
        all others. For instance, for a signature ``"(i),(i)->()"``, it is equivalent to passing
        in ``axes=[(axis,), (axis,), ()]``.
    keepdims: bool, optional, keyword only
        If this is set to True, axes which are reduced over will be left in the result as
        a dimension with size one, so that the result will broadcast correctly against the
        inputs. This option can only be used for generalized ufuncs that operate on inputs
        that all have the same number of core dimensions and with outputs that have no core
        dimensions , i.e., with signatures like ``"(i),(i)->()"`` or ``"(m,m)->()"``.
        If used, the location of the dimensions in the output can be controlled with axes
        and axis.
    output_dtypes : Optional, dtype or list of dtypes, keyword only
        Valid numpy dtype specification or list thereof.
        If not given, a call of ``func`` with a small set of data
        is performed in order to try to  automatically determine the
        output dtypes.
    output_sizes : dict, optional, keyword only
        Optional mapping from dimension names to sizes for outputs. Only used if
        new core dimensions (not found on inputs) appear on outputs.
    vectorize: bool, keyword only
        If set to ``True``, ``np.vectorize`` is applied to ``func`` for
        convenience. Defaults to ``False``.
    allow_rechunk: Optional, bool, keyword only
        Allows rechunking, otherwise chunk sizes need to match and core
        dimensions are to consist only of one chunk.
        Warning: enabling this can increase memory usage significantly.
        Defaults to ``False``.

    Returns
    -------
    Decorator for `pyfunc` that itself returns a `gufunc`.

    Examples
    --------
    >>> import dask.array as da
    >>> import numpy as np
    >>> a = da.random.normal(size=(10,20,30), chunks=(5, 10, 30))
    >>> @da.as_gufunc("(i)->(),()", output_dtypes=(float, float))
    ... def stats(x):
    ...     return np.mean(x, axis=-1), np.std(x, axis=-1)
    >>> mean, std = stats(a)
    >>> mean.compute().shape
    (10, 20)

    >>> a = da.random.normal(size=(   20,30), chunks=(10, 30))
    >>> b = da.random.normal(size=(10, 1,40), chunks=(5, 1, 40))
    >>> @da.as_gufunc("(i),(j)->(i,j)", output_dtypes=float, vectorize=True)
    ... def outer_product(x, y):
    ...     return np.einsum("i,j->ij", x, y)
    >>> c = outer_product(a, b)
    >>> c.compute().shape
    (10, 20, 30, 40)

    References
    ----------
    .. [1] https://docs.scipy.org/doc/numpy/reference/ufuncs.html
    .. [2] https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html
    RH   R-   R.   R/   RG   RF   RI   s(   Unsupported keyword argument(s) providedc         ` s   t  |  d ˆ ˆ  S(   NR   (   R   (   Rž   (   Ro   R   (    s0   lib/python2.7/site-packages/dask/array/gufunc.pyt
   _as_gufuncƒ  s    s  
        Decorator to make ``dask.array.gufunc``
        signature: ``'{signature}'``

        Parameters
        ----------
        pyfunc : callable
            Function matching signature ``'{signature}'``.

        Returns
        -------
        ``dask.array.gufunc``
        R   (   Rg   t   issubsetRŽ   R^   R   RŸ   (   R   Ro   t   _allowedkeysR¥   (    (   Ro   R   s0   lib/python2.7/site-packages/dask/array/gufunc.pyt	   as_gufunc/  s    P(&   t
   __future__R    R   R   t   numpyR_   t	   itertoolsR   R   t   cytoolzR   R   R   t   ImportErrort   toolzt   coreR   R   R	   R
   R   t   highlevelgraphR   R   R   R   t   _CORE_DIMENSION_LISTR   t   _INPUT_ARGUMENTSt   _OUTPUT_ARGUMENTSR   R#   RE   RJ   t   objectR   R&   R¨   (    (    (    s0   lib/python2.7/site-packages/dask/array/gufunc.pyt   <module>   s,     (		^	ÿ †