
\c           @` s  d  d l  m Z m Z m Z d  d l m Z m Z m Z d  d l m	 Z	 d  d l
 m Z m Z d  d l m Z m Z d  d l Z d  d l m Z m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% d d l& m' Z' m( Z( m) Z) m* Z* d d l+ m, Z, d d d  Z. d d d  Z/ d d d  Z0 d d d  Z1 d e2 e3 d d d  Z4 d   Z5 e e j6  d    Z6 e7 d d  Z8 d d  e9 d  Z: e e j;  d    Z; e e j<  d  d  d d   Z< d  d  Z= d  d  Z> d    Z? e e j@  d d d d!   Z@ e e jA  d d"   ZA e e jB  d#    ZB d$   ZC d%   ZD d&   ZE d'   ZF d(   ZG d)   ZH d*   ZI d+   ZJ e e jK  d,    ZK d S(-   i    (   t   absolute_importt   divisiont   print_function(   t   partialt   wrapst   reduce(   t   product(   t   addt   getitem(   t   Integralt   NumberN(   t
   accumulatet   sliding_windowi   (   t   HighLevelGraph(   t   tokenize(   t   Sequencei   (   t   chunk(   t   Arrayt   asarrayt   normalize_chunkst   stackt   concatenatet   blockt   broadcast_tot   broadcast_arrays(   t   emptyt   onest   zerost   full(   t	   AxisErrorc         C` sI   t  |  d t }  t |  j d | p* |  j d | d k	 r? | n |  j S(   sz  
    Return a new array with the same shape and type as a given array.

    Parameters
    ----------
    a : array_like
        The shape and data-type of `a` define these same attributes of the
        returned array.
    dtype : data-type, optional
        Overrides the data type of the result.
    chunks : sequence of ints
        The number of samples on each block. Note that the last block will have
        fewer samples if ``len(array) % chunks != 0``.

    Returns
    -------
    out : ndarray
        Array of uninitialized (arbitrary) data with the same
        shape and type as `a`.

    See Also
    --------
    ones_like : Return an array of ones with shape and type of input.
    zeros_like : Return an array of zeros with shape and type of input.
    empty : Return a new uninitialized array.
    ones : Return a new array setting values to one.
    zeros : Return a new array setting values to zero.

    Notes
    -----
    This function does *not* initialize the returned array; to do that use
    `zeros_like` or `ones_like` instead.  It may be marginally faster than
    the functions that do set the array values.
    t   namet   dtypet   chunksN(   R   t   FalseR   t   shapeR   t   NoneR    (   t   aR   R    (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt
   empty_like   s    $c         C` sI   t  |  d t }  t |  j d | p* |  j d | d k	 r? | n |  j S(   s  
    Return an array of ones with the same shape and type as a given array.

    Parameters
    ----------
    a : array_like
        The shape and data-type of `a` define these same attributes of
        the returned array.
    dtype : data-type, optional
        Overrides the data type of the result.
    chunks : sequence of ints
        The number of samples on each block. Note that the last block will have
        fewer samples if ``len(array) % chunks != 0``.

    Returns
    -------
    out : ndarray
        Array of ones with the same shape and type as `a`.

    See Also
    --------
    zeros_like : Return an array of zeros with shape and type of input.
    empty_like : Return an empty array with shape and type of input.
    zeros : Return a new array setting values to zero.
    ones : Return a new array setting values to one.
    empty : Return a new uninitialized array.
    R   R   R    N(   R   R!   R   R"   R   R#   R    (   R$   R   R    (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt	   ones_likeA   s    c         C` sI   t  |  d t }  t |  j d | p* |  j d | d k	 r? | n |  j S(   s  
    Return an array of zeros with the same shape and type as a given array.

    Parameters
    ----------
    a : array_like
        The shape and data-type of `a` define these same attributes of
        the returned array.
    dtype : data-type, optional
        Overrides the data type of the result.
    chunks : sequence of ints
        The number of samples on each block. Note that the last block will have
        fewer samples if ``len(array) % chunks != 0``.

    Returns
    -------
    out : ndarray
        Array of zeros with the same shape and type as `a`.

    See Also
    --------
    ones_like : Return an array of ones with shape and type of input.
    empty_like : Return an empty array with shape and type of input.
    zeros : Return a new array setting values to zero.
    ones : Return a new array setting values to one.
    empty : Return a new uninitialized array.
    R   R   R    N(   R   R!   R   R"   R   R#   R    (   R$   R   R    (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt
   zeros_likee   s    c         C` sL   t  |  d t }  t |  j | d | p- |  j d | d k	 rB | n |  j S(   s  
    Return a full array with the same shape and type as a given array.

    Parameters
    ----------
    a : array_like
        The shape and data-type of `a` define these same attributes of
        the returned array.
    fill_value : scalar
        Fill value.
    dtype : data-type, optional
        Overrides the data type of the result.
    chunks : sequence of ints
        The number of samples on each block. Note that the last block will have
        fewer samples if ``len(array) % chunks != 0``.

    Returns
    -------
    out : ndarray
        Array of `fill_value` with the same shape and type as `a`.

    See Also
    --------
    zeros_like : Return an array of zeros with shape and type of input.
    ones_like : Return an array of ones with shape and type of input.
    empty_like : Return an empty array with shape and type of input.
    zeros : Return a new array setting values to zero.
    ones : Return a new array setting values to one.
    empty : Return a new uninitialized array.
    full : Fill a new array.
    R   R   R    N(   R   R!   R   R"   R   R#   R    (   R$   t
   fill_valueR   R    (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt	   full_like   s    !i2   t   autoc         C` so  t  |  } | d k r3 t j d d d  j } n  t | | f d | } | |  } | re | d n | } t |  | }	 d t |  | | | | | f  }
 i  } |  } x t | d  D]u \ } } | r | d n | } | | |	 } t	 t j d | d | | | | f } | |	 | } | | |
 | f <q W| rUt
 | |
 | d | |	 f St
 | |
 | d | Sd S(   s-  
    Return `num` evenly spaced values over the closed interval [`start`,
    `stop`].

    Parameters
    ----------
    start : scalar
        The starting value of the sequence.
    stop : scalar
        The last value of the sequence.
    num : int, optional
        Number of samples to include in the returned dask array, including the
        endpoints. Default is 50.
    endpoint : bool, optional
        If True, ``stop`` is the last sample. Otherwise, it is not included.
        Default is True.
    retstep : bool, optional
        If True, return (samples, step), where step is the spacing between
        samples. Default is False.
    chunks :  int
        The number of samples on each block. Note that the last block will have
        fewer samples if `num % blocksize != 0`
    dtype : dtype, optional
        The type of the output array.

    Returns
    -------
    samples : dask array
    step : float, optional
        Only returned if ``retstep`` is True. Size of spacing between samples.


    See Also
    --------
    dask.array.arange
    i    i   R   s	   linspace-t   endpointN(   t   intR#   t   npt   linspaceR   R   t   floatR   t	   enumerateR   R   (   t   startt   stopt   numR+   t   retstepR    R   t   range_t   divt   stepR   t   dskt
   blockstartt   it   bst   bs_spacet	   blockstopt   task(    (    s2   lib/python2.7/site-packages/dask/array/creation.pyR.      s(    &
"c          O` s  t  |   d k r+ d } |  d } d } n_ t  |   d k rZ |  d } |  d } d } n0 t  |   d k r~ |  \ } } } n t d   | j d d  } t t t j | | |  d   } | j d d  } | d k rt j | | | r | | n |  j	 } n  t
 | | f d | } | rKt d	 d
 j | j      n  d t | | | | | f  } i  }	 d }
 xs t | d  D]a \ } } | |
 | } | |
 | | } t j | | | | | f } | |	 | | f <|
 | 7}
 qWt |	 | | d | S(   s:  
    Return evenly spaced values from `start` to `stop` with step size `step`.

    The values are half-open [start, stop), so including start and excluding
    stop. This is basically the same as python's range function but for dask
    arrays.

    When using a non-integer step, such as 0.1, the results will often not be
    consistent. It is better to use linspace for these cases.

    Parameters
    ----------
    start : int, optional
        The starting value of the sequence. The default is 0.
    stop : int
        The end of the interval, this value is excluded from the interval.
    step : int, optional
        The spacing between the values. The default is 1 when not specified.
        The last value of the sequence.
    chunks :  int
        The number of samples on each block. Note that the last block will have
        fewer samples if ``len(array) % chunks != 0``.
    dtype : numpy.dtype
        Output dtype. Omit to infer it from start, stop, step

    Returns
    -------
    samples : dask array

    See Also
    --------
    dask.array.linspace
    i   i    i   i   sT   
        arange takes 3 positional arguments: arange([start], stop, [step])
        R    R*   R   s"   Unexpected keyword argument(s): %st   ,s   arange-N(   t   lent	   TypeErrort   popR,   t   maxR-   t   ceilR#   t   arangeR   R   t   joint   keysR   R0   R   R   (   t   argst   kwargsR1   R2   R7   R    R3   R   R   R8   t
   elem_countR:   R;   R9   R=   R>   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyRE      s>    "
	

		&+c    	      O` s  | j  d d  } t | j  d t   } d | k rE t d   n  | rZ t d   n  | d k ru t d   n  g  |  D] } t |  ^ q| }  g  |  D] } | j   ^ q }  | d k r t |   d	 k r |  d	 |  d
 |  d
 <|  d	 <n  g  } xd t	 t |    D]P } t |   d  g } t d   | | <t |  } |  | | } | j |  q
W| sst |   } n  | d k rt |   d	 k r| d	 | d
 | d
 <| d	 <n  | S(   Nt   indexingt   xyt   sparset   copys   `copy` not supporteds(   unsupported keyword argument(s) providedt   ijs#   `indexing` must be `'ij'` or `'xy'`i   i    (   RO   RL   (   RB   t   boolR!   t   NotImplementedErrorRA   t
   ValueErrorR   t   flattenR@   t   rangeR#   t   slicet   tuplet   appendR   (	   t   xiRI   RK   RM   t   et   gridR:   t   st   r(    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt   meshgridE  s0      c      	   C` s  t  |   }  t j |  } t  |  } t |   t |  k rN t d   n  g  } xD t t |    D]0 } | j t |  | d | d | | f  qg Wg  } t j |   r t	 d d |  } n  | r t
 |  } n) t t |   f |  d | d d | } | S(   s  
    Implements NumPy's ``indices`` for Dask Arrays.

    Generates a grid of indices covering the dimensions provided.

    The final array has the shape ``(len(dimensions), *dimensions)``. The
    chunks are used to specify the chunking for axis 1 up to
    ``len(dimensions)``. The 0th axis always has chunks of length 1.

    Parameters
    ----------
    dimensions : sequence of ints
        The shape of the index grid.
    dtype : dtype, optional
        Type to use for the array. Default is ``int``.
    chunks : sequence of ints
        The number of samples on each block. Note that the last block will have
        fewer samples if ``len(array) % chunks != 0``.

    Returns
    -------
    grid : dask array
    s)   Need same number of chunks as dimensions.R   R    RK   RO   i   (   i   (   RV   R-   R   R@   RR   RT   RW   RE   t   prodR]   R   R   (   t
   dimensionsR   R    RX   R:   RZ   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt   indicesl  s     .&c      	   C` s  t  | t  s t d   n  t |  t | | |  } d | } i  } | d k r[ |  } n  | g |  | } |  | d k r | j |  |  n  | g | | }	 | | d k r |	 j | |  n  x t |  D] \ }
 } x t |	  D] \ } } | |
 d | | k o&| |
 d | k n r_t j	 | | | | |
 | | f | | |
 | f <q t j
 | | f | f | | |
 | f <q Wq Wt | | d |  | f d | | f d | S(	   s  
    Return a 2-D Array with ones on the diagonal and zeros elsewhere.

    Parameters
    ----------
    N : int
      Number of rows in the output.
    chunks: int
        chunk size of resulting blocks
    M : int, optional
      Number of columns in the output. If None, defaults to `N`.
    k : int, optional
      Index of the diagonal: 0 (the default) refers to the main diagonal,
      a positive value refers to an upper diagonal, and a negative value
      to a lower diagonal.
    dtype : data-type, optional
      Data-type of the returned array.

    Returns
    -------
    I : Array of shape (N,M)
      An array where all elements are equal to zero, except for the `k`-th
      diagonal, whose values are equal to one.
    s   chunks must be an ints   eye-i    i   R"   R    R   N(   t
   isinstanceR	   RR   R   R   R#   RW   R0   R-   t   eyeR   R   (   t   NR    t   Mt   kR   t   tokent   name_eyeRb   t   vchunkst   hchunksR:   t   vchunkt   jt   hchunk(    (    s2   lib/python2.7/site-packages/dask/array/creation.pyRb     s(    
	44-c         ` s  d t  |     t |  t j  r |  j d k rs |  j d f |  j d f f } i t j |  f   d d f 6} nO |  j d k r t |  j  f f } i t j |  f   d f 6} n t d   t	 |   | d |  j
 St |  t	  st d j t |      n  |  j d k r|  j d |  j d k r  f d   t |  j    D } t j   | d	 |  g } t	 |   |  j d f d |  j
 St d
   n  |  j d } |  j   } i  } x t |  D]w \ } } xh t |  D]Z \ } }	   | | f }
 | | k r&t j | | f | |
 <qt j | |	 f f | |
 <qWqWt j   | d	 |  g } t	 |   | | f d |  j
 S(   Ns   diag-i   i    i   s   Array must be 1d or 2d onlyR   s.   v must be a dask array or numpy array, got {0}c         ` s2   i  |  ]( \ } } t  j | | f   | f  q S(    (   R-   t   diag(   t   .0R:   t   row(   R   (    s2   lib/python2.7/site-packages/dask/array/creation.pys
   <dictcomp>  s   	t   dependenciess3   Extracting diagonals from non-square chunked arrays(   R   Ra   R-   t   ndarrayt   ndimR"   Rm   t   minRR   R   R   RA   t   formatt   typeR    R0   t   __dask_keys__R   t   from_collectionsRQ   R   (   t   vR    R8   t   grapht	   chunks_1dt   blocksR:   t   mRk   t   nt   key(    (   R   s2   lib/python2.7/site-packages/dask/array/creation.pyRm     s>     "	#!c      	   ` s  d t    | | |  }   j d k  r7 t d   n  d   } | | d   j  } | | d   j  } | | k r t d   n  t      | | k r | | } } | } n  d   } g  } g  } d	 g t t j   j |   d
  }	 d	 g t t j   j |   d
  }
 x t |	   j |  D]x \ } } | j	 g   x\ t |
   j |  D]D \ } } | | | } | j	 | | | |   | d
 j	 |  q^Wq.Wi  } t
 t   j   t
 | | g  } t   j |  } t   j |  } x t   f d   | D   D] } x t t t |  t |    D] \ } \ } } t t | |    j    | } t t | | | d !|  | } t t | | d |  } | | | } t j | | | | f | | f | | f <q@WqWt   f d   | D  } |   j |   j | |  f } | | } t   f d   | D  } t |  f } | | } t j | | d   g } t | | d | d | d   j S(   Ns	   diagonal-i   s1   diag requires an array of at least two dimensionsc         S` sS   |  d k  rO | |  } | d k  rF d } t  | j | |  |    n  | }  n  |  S(   Ni    s6   {}: axis {} is out of bounds for array of dimension {}(   R   Rt   (   t   axisR   Rr   t   tt   msg(    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt	   _axis_fmt  s    
	t   axis1t   axis2s"   axis1 and axis2 cannot be the samec         S` s*   t  d t t |  |  |  | | |   S(   Ni    (   RC   Rs   (   t   dim1t   dim2t   offset(    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt	   _diag_len  s    i    ic         3` s(   |  ] } t  t   j |   Vq d  S(   N(   RT   R@   R    (   Rn   R:   (   R$   (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>(  s    i   c         3` s   |  ] }   j  | Vq d  S(   N(   R"   (   Rn   R:   (   R$   (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>0  s    c         3` s   |  ] }   j  | Vq d  S(   N(   R    (   Rn   R:   (   R$   (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>4  s    Rp   R"   R    R   (   R   Rr   RR   R   t   listR-   t   cumsumR    t   zipRW   t   setRT   R@   R   R0   R   R   Rv   t   diagonalRV   R"   R   Rw   R   R   (   R$   R   R   R   R   R   R   t   diag_chunkst   chunk_offsetst   cum1t   cum2t   co1t   c1t   co2t   c2Re   R8   t   idx_sett   n1t   n2t   idxR:   t   i1t   i2t   tskt
   left_shapet   right_shapeR"   t   left_chunksR    Ry   (    (   R$   s2   lib/python2.7/site-packages/dask/array/creation.pyR     sT    		
	''##%#4 !2#

c      	   C` s  |  j  d k r t d   n  |  j d d |  j d d k rU d } t |   n  t |  j d  } t |  j d  } |  j d d } t |  |  } d | } i  } xt |  D] }	 x t |  D] }
 | |
 |	 d | k  r$t j |  j d |	 |  j d |
 f f | | |	 |
 f <q | |
 |	 d | k  oS| |
 |	 d k n rt j	 |  j
 |	 |
 f | | |
 |	 f | | |	 |
 f <q |  j
 |	 |
 f | | |	 |
 f <q Wq Wt j | | d |  g } t | | d |  j d	 |  j d
 |  j S(   s  
    Upper triangle of an array with elements above the `k`-th diagonal zeroed.

    Parameters
    ----------
    m : array_like, shape (M, N)
        Input array.
    k : int, optional
        Diagonal above which to zero elements.  `k = 0` (the default) is the
        main diagonal, `k < 0` is below it and `k > 0` is above.

    Returns
    -------
    triu : ndarray, shape (M, N)
        Upper triangle of `m`, of same shape and data-type as `m`.

    See Also
    --------
    tril : lower triangle of an array
    i   s   input must be 2 dimensionali    i   sJ   chunks must be a square. Use .rechunk method to change the size of chunks.s   triu-Rp   R"   R    R   (   Rr   RR   R    RQ   R@   R   RT   R-   R   t   triuR   R   Rw   R   R"   R   (   R|   Re   R   t   rdimt   hdimR   Rf   R   R8   R:   Rk   Ry   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyR   <  s(    "
;4:'c      	   C` s  |  j  d k r t d   n  t t |  j d |  j d   d k s] d } t |   n  t |  j d  } t |  j d  } |  j d d } t |  |  } d | } i  } xt |  D] }	 x t |  D] }
 | |
 |	 d | k  r|  j |	 |
 f | | |	 |
 f <q | |
 |	 d | k  oB| |
 |	 d k n rt j	 |  j |	 |
 f | | |
 |	 f | | |	 |
 f <q t j
 |  j d |	 |  j d |
 f f | | |	 |
 f <q Wq Wt j | | d |  g } t | | d |  j d	 |  j d
 |  j S(   s  
    Lower triangle of an array with elements above the `k`-th diagonal zeroed.

    Parameters
    ----------
    m : array_like, shape (M, M)
        Input array.
    k : int, optional
        Diagonal above which to zero elements.  `k = 0` (the default) is the
        main diagonal, `k < 0` is below it and `k > 0` is above.

    Returns
    -------
    tril : ndarray, shape (M, M)
        Lower triangle of `m`, of same shape and data-type as `m`.

    See Also
    --------
    triu : upper triangle of an array
    i   s   input must be 2 dimensionali    i   sq   All chunks must be a square matrix to perform lu decomposition. Use .rechunk method to change the size of chunks.s   tril-Rp   R"   R    R   (   Rr   RR   R@   R   R    R   RT   R   R-   t   trilR   R   Rw   R   R"   R   (   R|   Re   R   R   R   R   Rf   R   R8   R:   Rk   Ry   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyR   l  s(    *
"4:@c         ` s+      f d   } t  j | | d | | S(   Nc          ` s%   t  t t |     }   | |   S(   N(   R   t   mapR   (   RH   RI   t   args2(   t   funcR   (    s2   lib/python2.7/site-packages/dask/array/creation.pyt   offset_func  s    R   (   R-   t   fromfunction(   R   R"   R   R   t   func_kwargsR   (    (   R   R   s2   lib/python2.7/site-packages/dask/array/creation.pyt   _np_fromfunction  s    c         K` s-  t  | | d | } d t |  | | | |  } t t | g g  | D] } t t |   ^ qD   } g  | D]# } t t t d | d    ^ qo } t t |    }	 t t |    }
 | p t } g  t	 |	 |
  D]$ \ } } t
 |  | | | | f ^ q } t t	 | |   } t | | | d | S(   NR   s   fromfunction-i    i(   i    (   R   R   R   R   RT   R@   R   R   R/   R   R   t   dictR   (   R   R    R"   R   RI   R   t   bdRG   t   aggdimst   offsetst   shapesR   t   shpt   valuesR8   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyR     s    707c      
   C` s  | d  k r3 |  j d k r$ d } q3 t d   n  t | t  sQ t d   n  |  j | k ol d k  n r | |  j 7} n6 d | k o |  j d k n s t d |   n  | d k r |  St j d
 |  j |  } g  } x t	 d |  D]o \ } } t j
 | | |  j d  } xB t	 d |  D]1 \ } }	 | |	 k r1| j t | |	   q1q1Wq Wt d  d  d   }
 g  | D]0 } |
 f | | f |
 f |  j | d ^ q} g  | D] } |  | ^ q} g  } x | D] } t | j  } t | |  d k st  | | d | f | | <t |  } | j t j | d | d | d	 | j } | j |  qWt | d | S(   Ni   i    s!   Must supply an integer axis values%   Only integer valued repeats supporteds   axis(=%d) out of boundsi   R   R    R   (   i    (   R#   Rr   RQ   Ra   R	   RR   R-   R   R    R   R.   t   roundRW   RU   R   R@   t   AssertionErrorRV   t
   map_blockst   repeatR   R   (   R$   t   repeatsR   t   cchunkst   slicest   c_startt   c_stopt   lst   ls_startt   ls_stopt	   all_sliceR[   t   slct   slabst   outt   slabR    t   result(    (    s2   lib/python2.7/site-packages/dask/array/creation.pyR     sB    	 #!:c         C` s   t  | t  s t d   n  | d k  r9 t d   n0 | d k rY |  d d  d  f S| d k ri |  St | |  g d d S(   Ns%   Only integer valued `reps` supported.i    s    Negative `reps` are not allowed..i   R   i(   Ra   R	   RQ   RR   R   (   t   At   reps(    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt   tile  s    c         ` sn  t    t  r( |  j     f f   nBt    t  r t d     D  r t    d k r |  j   d   d f f   n t    t  r t    d k r t d     D  r t   f d   t |  j  D    n t    t  r^t    |  j k r^t d     D  r^t d     D  r^t d	     D  r^t d
     D    n t d     S(   Nc         s` s   |  ] } t  | t  Vq d  S(   N(   Ra   R
   (   Rn   t   pw(    (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>  s    i   i    i   c         s` s   |  ] } t  | t  Vq d  S(   N(   Ra   R
   (   Rn   R   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>  s    c         3` s#   |  ] }   d    d f Vq d S(   i    i   N(    (   Rn   t   _(   t	   pad_value(    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>  s    c         s` s   |  ] } t  | t  Vq d  S(   N(   Ra   R   (   Rn   R   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>  s    c         s` s!   |  ] } t  |  d  k Vq d S(   i   N(   R@   (   Rn   R   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>  s    c         s` s%   |  ] } t  d    | D  Vq d S(   c         s` s   |  ] } t  | t  Vq d  S(   N(   Ra   R
   (   Rn   t   w(    (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>  s    N(   t   all(   Rn   R   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>  s    c         s` s#   |  ] } | d  | d f Vq d S(   i    i   N(    (   Rn   R   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>  s    s6   `pad_value` must be composed of integral typed values.(	   Ra   R
   Rr   R   R   R@   RV   RT   RA   (   t   arrayR   (    (   R   s2   lib/python2.7/site-packages/dask/array/creation.pyt   expand_pad_value  s(    !%	c   	      C` s   t  |  j  t  |  j  g } t  |  j  t  |  j  g } xT | D]L } xC t d  D]5 } | | | | | | <| | | f | | | <qV WqC Wg  | D] } t |  ^ q } g  | D] } t |  ^ q } | | f S(   sD   
    Helper function for finding shapes and chunks of end pads.
    i   (   R   R"   R    RT   RV   (	   R   t	   pad_widtht   axest
   pad_shapest
   pad_chunkst   dR:   R[   t   c(    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt   get_pad_shapes_chunks  s    !c         C` s   | d } t  |  j  } | | | <t |  } t j |  j  } t j | d | } xv t j |  j  D]b }	 t  |	  }
 t d  |
 | <t |
  }
 t j	 |  |	 | | d | d d d |  | |
 <qi W| S(   s>   
    Helper function to find the linear ramp for a chunk.
    i   R   N(
   R   R"   RV   R-   R   R   t   ndindexRU   R#   R.   (   R1   R2   R3   t   dimR7   t   num1R"   R   R   R:   Rk   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt   linear_ramp_chunk!  s    

8c         ` s  t    f d   | D  }   } xjt   j  D]Y} t | | | f  \ } } | | g } | d k r | d | }	 g  |	 D] }
 t |
  j | j  ^ q }	 g  t |	 | |  D]! \ } } }
 t | | |
  ^ q } n| d k rh| j t	 d  g | j t	 d  g g } t	 d d d  | d | <t	 d d d  | d | <g  | D] } t  |  ^ qT} g  | D] } | | ^ qs} | d k rg  t | | |  D]! \ } } }
 t | | |
  ^ q} qh| d k rh| d | } g  t t | | | | |   D]P \ } \ } } } }
 | j t | | d |
 d	 | j d
 | d d | d ^ q} qhn  t | d | | d g d | } q2 W| S(   su   
    Helper function for padding edges.

    Handles the cases where the only the values on the edge are needed.
    c         3` s   |  ] } t    |  Vq d  S(   N(   R   (   Rn   RY   (   R   (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>@  s    t   constanti    t   edget   linear_rampi   iR    R   R   R7   i   R   (   R   R   N(   RV   RT   Rr   R   R   t   astypeR   R   R   RU   R#   R0   R   R   R   (   R   R   t   modeRH   R   R   R   R   t
   pad_arrayst   constant_valuesR   Rx   R[   t
   pad_slicest   slR$   t
   end_valuesR:   t   evR   (    (   R   s2   lib/python2.7/site-packages/dask/array/creation.pyt   pad_edge9  s4    +:,:v'c         G` s:  | d k r' d | k r' t  d   n  t j |  j d d t } xt j | j  D]} g  } g  } xft | |  j |  D]O\ } }	 }
 | d k r |
 d d d	  }
 n  | d
 k  r| d k r | j t	 d
 |
 d d
 d   q| j t	 d |
 d d   n{ | d
 k rs| d k rO| j t	 |	 |
 d
 d
 |	 d
 d   q| j t	 |	 |
 d
 d d   n | j t	 d   | d
 k r| d k r| j t	 d d d	   q~ | j t	 d   q~ Wt |  } t |  } | d k rt d   | D  } n  |  | | | | <qV Wt | j    } | S(   s   
    Helper function for padding boundaries with values in the array.

    Handles the cases where the padding is constructed from values in
    the array. Namely by reflecting them or tiling them to create periodic
    boundary constraints.
    t   reflectt	   symmetrict   odds/   `pad` does not support `reflect_type` of `odd`.i   R   t   wrapNii   i    c         s` s   |  ] } d  | Vq d S(   i   N(    (   Rn   R:   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pys	   <genexpr>  s    (   R   R   (   i   (   R   R   (   RQ   R-   R   Rr   t   objectR   R"   R   RW   RU   R#   RV   R   t   tolist(   R   R   R   RH   R   R   t   selectt   orientR:   R[   R   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt	   pad_reuser  s:    	%$ ,$c         G` s  | d k r t  d   n  t |  | d  } t j |  j d d t } x+t j | j  D]} g  } g  } g  }	 g  }
 x(t t	 | |  j |  j
 | |   D]\ } \ } } } } } | d k  r| j |  | j t d | d d   |	 j | d  |
 j | d  q | d k ru| j |  | j t | | d d d   |	 j | d  |
 j | d  q | j t d   |	 j |  |
 j |  q Wt |  } t |  } t |	  }	 t |
  }
 |  | } | d k r| j d | d	 t  } nN | d
 k r.| j d | d	 t  } n' | d k rU| j d | d	 t  } n  t | |	 d |
 } | | | <q] Wt | j    } | S(   s6  
    Helper function for padding boundaries with statistics from the array.

    In cases where the padding requires computations of statistics from part
    or all of the array, this function helps compute those statistics as
    requested and then adds those statistics onto the boundaries of the array.
    t   medians*   `pad` does not support `mode` of `median`.i    i   R   i   t   maximumR   t   keepdimst   meant   minimumR    (   i   N(   RQ   R   R-   R   Rr   R   R   R"   R0   R   R    RW   RU   R#   RV   RC   t   TrueR   Rs   R   R   R   (   R   R   R   RH   t   stat_lengthR   R   R   R   t	   pad_shapeR   R   R:   R[   R   R   t   lt
   result_idx(    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt	   pad_stats  sN    		7!
c         C` s   t  j |   } xi t  j |  j |  |  j | d  D]B } | |  t d   f | | } | |  | | | |  | | <q5 W| S(   Ni   (   R-   R%   R   R"   RU   R#   (   R   t   pad_funct   iaxis_pad_widtht   iaxist   pad_func_kwargsR   R:   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt   wrapped_pad_func  s
    ,!c         K` s   t  |  | d d  } | j } x t | j  D] } | j | |  | j | | d !f | | d  } | j t d d d | j d | d | | d	 | d
 | } | j |  } q. W| S(   s9  
    Helper function for padding boundaries with a user defined function.

    In cases where the padding requires a custom user defined function be
    applied to the array, this function assists in the prepping and
    application of this function to the Dask Array to construct the desired
    boundaries.
    R   i    i   R   t   padR   R   R   R   R   (	   R   R    RT   Rr   t   rechunkR"   R   R   R   (   R   R   R   RI   R   R    R   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt   pad_udf  s    
	.	
	c         K` s  t  |   }  t |  |  } | d k r= | j d |  j  n | d k r\ | j d d  n | d	 k r{ | j d
 d  nn | d k r | j d d  nO | d k r | r t d   q n+ t |  r | j d i   n t d   t |  rt |  d k rt d   n  | d k r<t |  | | | j	    S| d k rat
 |  | | | j	    S| d k rt |  | | | j	    St |  rt |  | | |  St d   d  S(   NR   R   R   R   R   R   R   i    R   R   R   R   t   reflect_typet   evenR   R   s"   Got unsupported keyword arguments.RI   s   Got an unsupported `mode`.i   s   Got too many keyword arguments.s   Unsupported mode selected.(   R   R   R   R   (   R   R   (   R   R   (   R   R   R   R   (   R   R   R   (   R   R   R   (   R   R   t
   setdefaultR"   RA   t   callableRR   R@   R   R   R   R   R   (   R   R   R   RI   (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyR     s6    (L   t
   __future__R    R   R   t	   functoolsR   R   R   t	   itertoolsR   t   operatorR   R   t   numbersR	   R
   t   numpyR-   t   toolzR   R   t   highlevelgraphR   t   baseR   t   compatibilityR   t    R   t   coreR   R   R   R   R   R   R   R   R   R   R   R   R   t   utilsR   R#   R%   R&   R'   R)   R   R!   R.   RE   R]   R,   R`   R/   Rb   Rm   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/dask/array/creation.pyt   <module>   sV   :"+$$*D	M'14(B00	-				9	5	<			!