ó
¦Õ\c           @` sJ  d  d l  m Z m Z m Z d  d l m Z d  d l Z d  d l m Z m Z d  d l	 m
 Z
 d  d l Z d  d l m Z m Z d  d l 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 Z d  d l Z d  d l m Z d  d l Z d  d l Z y< d  d	 l m Z m Z m Z m  Z  m! Z! d  d
 l" m# Z# WnI e$ k
 rd  d	 l% m Z m Z m Z m  Z  m! Z! d  d
 l& m# Z# n Xd  d l% m' Z' m( Z( m) Z) d  d l* Z+ d d l, m- Z- d d l, m. Z. d d l/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 d d l6 m7 Z7 m8 Z8 d d l9 m: Z: d d l; m< Z< m= Z= m> Z> m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH mI ZI d d lJ mK ZK mL ZL mM ZM mN ZN mO ZO d d lP mQ ZQ d d lR mR ZR mS ZS d d l, mT ZT mP ZP d d lU mU ZU d d lV mW ZW d d lX mY ZY mZ ZZ d d l[ m\ Z\ m] Z] d d l^ m_ Z_ m` Z` d d l6 m6 Z6 e. ja i i d d 6d  d! 6d" 6 eD d#  Zb eD d$  Zc eD d%  Zd eb je ef e+ jg f e+ jh  ec je ef e+ jg f e+ ji  ed je ef e+ jg f e+ jj  d& ek f d'     YZl em en d(  Zo em en d)  Zp em en d*  Zq d d+ lr ms Zs mt Zt d,   Zu eo en en ev em en d-  Zw en en d.  Zx g  d/  Zy d0 en d1  Zz d2   Z{ d3   Z| d4   Z} em en em ev d5  Z~ d6   Z d7   Z d8 j   Z d9 e0 f d:     YZ d;   Z en en en en d<  Z en d=  Z d>   Z d? en ev em em en d@  Z en en en en dA  Z en en ev em ev dB  Z dC   Z en dD  Z en en f  i  dE  Z dF   Z dG   Z dH   Z ev dI  Z d  ev dJ  Zh dK   Z dL   Z dM   Z em en ev ev en dN  Z en dO  Z dP   Z dQ   Z dR   Z dS   Z dT   Z dU   Z dV   Z en dW  Z e e+ j  dX    Z dY   Z  dZ   Z” d[   Z¢ d\   Z£ d]   Z¤ d  d^  Z„ d  d_  Z¦ d`   Z§ da   ZØ db   Z© dc   ZŖ dd   Z« de   Z¬ df   Z­ dg   Z® dh   ZÆ di   Z° dj   Z± d  dk  Z² dl dm  Z³ d S(n   i    (   t   absolute_importt   divisiont   print_function(   t   bisectN(   t   partialt   wraps(   t   product(   t   Numbert   Integral(   t   addt   getitemt   mul(   t   Lock(   t	   partitiont   concatt   firstt   groupbyt
   accumulate(   t   pluck(   t   mapt   reducet   frequenciesi   (   t   chunki   (   t   config(   t   DaskMethodsMixint   tokenizet   dont_optimizet   compute_as_if_collectiont   persistt   is_dask_collection(   t   broadcast_dimensionst   subs(   t   globalmethod(   t   ndeepmapt   ignoringt   concretet
   is_integert   IndexCallablet   funcnamet   derived_fromt   SerializableLockt   Dispatcht   factorst   parse_bytest   has_keywordt   Mt   ndimlist(   t   unicodet   zip_longestt   Iterablet   Iteratort   Mapping(   t   quote(   t   delayedt   Delayed(   t   threadedt   core(   t   sizeof(   t   HighLevelGraph(   t
   get_mappert   get_fs_token_paths(   t	   _Recursert   _make_sliced_dtype(   t   slice_arrayt   replace_ellipsis(   t	   blockwiset   128MiBs
   chunk-sizei   s   rechunk-thresholdt   arrayt   concatenatet	   tensordott   einsumt   PerformanceWarningc           B` s   e  Z d  Z RS(   s>    A warning given when bad chunking may cause poor performance (   t   __name__t
   __module__t   __doc__(    (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRG   A   s   c         C` sĀ   t  | t  rn t d   | D  rn t d   | D  } t d   | D  } t |  | d | d | | S| r | j   n  z& |  | } | r¦ t j |  } n  Wd  | r½ | j   n  X| S(   Nc         s` s   |  ] } | d  k Vq d  S(   N(   t   None(   t   .0t   x(    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>F   s    c         s` s!   |  ] } | d  k	 r | Vq d  S(   N(   RK   (   RL   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>G   s    c         s` s?   |  ]5 } t  | t  s | d  k r* d  n t d  d   Vq d  S(   N(   t
   isinstanceR   RK   t   slice(   RL   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>H   s   t   asarrayt   lock(   RN   t   tuplet   anyt   gettert   acquiret   npRP   t   release(   t   at   bRP   RQ   t   b2t   b3t   c(    (    s.   lib/python2.7/site-packages/dask/array/core.pyRT   E   s    %	
c         C` s   t  |  | d | d | S(   s    A simple wrapper around ``getter``.

    Used to indicate to the optimization passes that the backend doesn't
    support fancy indexing.
    RP   RQ   (   RT   (   RX   RY   RP   RQ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   getter_nofancyX   s    c         C` s   t  |  | d | d | S(   sÜ   A getter function that optimizations feel comfortable inlining

    Slicing operations with this function may be inlined into a graph, such as
    in the following rewrite

    **Before**

    >>> a = x[:10]  # doctest: +SKIP
    >>> b = a + 1  # doctest: +SKIP
    >>> c = a * 2  # doctest: +SKIP

    **After**

    >>> b = x[:10] + 1  # doctest: +SKIP
    >>> c = x[:10] * 2  # doctest: +SKIP

    This inlining can be relevant to operations when running off of disk.
    RP   RQ   (   RT   (   RX   RY   RP   RQ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   getter_inlinea   s    (   t   optimizet
   fuse_slicec         C` s   g  |  D]# } t  t t d | d    ^ q } t |    } t |   } g  t | |  D]+ \ } } t d   t | |  D  ^ qX S(   s§   Translate chunks tuple to a set of slices in product order

    >>> slices_from_chunks(((2, 2), (3, 3, 3)))  # doctest: +NORMALIZE_WHITESPACE
     [(slice(0, 2, None), slice(0, 3, None)),
      (slice(0, 2, None), slice(3, 6, None)),
      (slice(0, 2, None), slice(6, 9, None)),
      (slice(2, 4, None), slice(0, 3, None)),
      (slice(2, 4, None), slice(3, 6, None)),
      (slice(2, 4, None), slice(6, 9, None))]
    i    i’’’’c         s` s(   |  ] \ } } t  | | |  Vq d  S(   N(   RO   (   RL   t   st   dim(    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>   s    (   i    (   t   listR   R	   R   t   zipRR   (   t   chunkst   bdst   cumdimst   shapest   startst   startt   shape(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   slices_from_chunksz   s
    0c         C` są   | p	 |  } t  | | d | } t t | g g  | D] } t t |   ^ q4   }	 t |  }
 | t j k	 r« | s | r« g  |
 D] } | |  | | | f ^ q } n" g  |
 D] } | |  | f ^ q² } t t	 |	 |   S(   s   Dask getting various chunks from an array-like

    >>> getem('X', chunks=(2, 3), shape=(4, 6))  # doctest: +SKIP
    {('X', 0, 0): (getter, 'X', (slice(0, 2), slice(0, 3))),
     ('X', 1, 0): (getter, 'X', (slice(2, 4), slice(0, 3))),
     ('X', 1, 1): (getter, 'X', (slice(2, 4), slice(3, 6))),
     ('X', 0, 1): (getter, 'X', (slice(0, 2), slice(3, 6)))}

    >>> getem('X', chunks=((2, 2), (3, 3)))  # doctest: +SKIP
    {('X', 0, 0): (getter, 'X', (slice(0, 2), slice(0, 3))),
     ('X', 1, 0): (getter, 'X', (slice(2, 4), slice(0, 3))),
     ('X', 1, 1): (getter, 'X', (slice(2, 4), slice(3, 6))),
     ('X', 0, 1): (getter, 'X', (slice(0, 2), slice(3, 6)))}
    t   dtype(
   t   normalize_chunksRc   R   t   ranget   lenRl   t   operatorR
   t   dictRd   (   t   arrRe   R
   Rk   t   out_nameRQ   RP   Rm   Rf   t   keyst   slicesRM   t   values(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   getem   s    7+"c         K` sR   | r t  | |   }  n  | r0 t  | |  } n  t t  t t j |  |  |   S(   s   Dot product of many aligned chunks

    >>> x = np.array([[1, 2], [1, 2]])
    >>> y = np.array([[10, 20], [10, 20]])
    >>> dotmany([x, x, x], [y, y, y])
    array([[ 90, 180],
           [ 90, 180]])

    Optionally pass in functions to apply to the left and right chunks

    >>> dotmany([x, x, x], [y, y, y], rightfunc=np.transpose)
    array([[150, 150],
           [150, 150]])
    (   R   t   sumR   RV   t   dot(   t   At   Bt   leftfunct	   rightfunct   kwargs(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   dotmany«   s
    c         C` s­   t  |  t  r t |   }  n  t  |  t t f  s7 |  St |  d k ru g  |  D] } t | d | d ^ qP }  n  t j t t	 |  d d     } | |  d | d S(   sß   Recursively Concatenate nested lists of arrays along axes

    Each entry in axes corresponds to each level of the nested list.  The
    length of axes should correspond to the level of nesting of arrays.

    >>> x = np.array([[1, 2], [3, 4]])
    >>> _concatenate2([x, x], axes=[0])
    array([[1, 2],
           [3, 4],
           [1, 2],
           [3, 4]])

    >>> _concatenate2([x, x], axes=[1])
    array([[1, 2, 1, 2],
           [3, 4, 3, 4]])

    >>> _concatenate2([[x, x], [x, x]], axes=[0, 1])
    array([[1, 2, 1, 2],
           [3, 4, 3, 4],
           [1, 2, 1, 2],
           [3, 4, 3, 4]])

    Supports Iterators
    >>> _concatenate2(iter([x, x]), axes=[1])
    array([[1, 2, 1, 2],
           [3, 4, 3, 4]])
    i   t   axest   keyc         S` s   |  j  S(   N(   t   __array_priority__(   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   <lambda>ć   t    t   axisi    (
   RN   R2   Rc   RR   Rp   t   _concatenate2t   concatenate_lookupt   dispatcht   typet   max(   t   arraysR   RX   RD   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR   Į   s    ,$Rm   c         C` s:  g  | D]: } t  | t  r; t j d
 | j d | j n | ^ q } y, t j d d   |  | |   } Wd QXWn| t k
 rń } t j	   \ }	 }
 } d j
 t j |   } | rŹ d j d |  n d } d j | | t |  |  } n Xd } | d k	 rt |   n  | d k r&| j St d	   | D  S(   s  
    Tries to infer output dtype of ``func`` for a small set of input arguments.

    Parameters
    ----------
    func: Callable
        Function for which output dtype is to be determined

    args: List of array like
        Arguments to the function, which would usually be used. Only attributes
        ``ndim`` and ``dtype`` are used.

    kwargs: dict
        Additional ``kwargs`` to the ``func``

    funcname: String
        Name of calling function to improve potential error messages

    suggest_dtype: None/False or String
        If not ``None`` adds suggestion to potential error message to specify a dtype
        via the specified kwarg. Defaults to ``'dtype'``.

    nout: None or Int
        ``None`` if function returns single output, integer if many.
        Deafults to ``None``.

    Returns
    -------
    : dtype or List of dtype
        One or many dtypes (depending on ``nout``)
    i   Rm   t   allt   ignoreNR   s@   Please specify the dtype explicitly using the `{dtype}` kwarg.

sv   `dtype` inference failed in `{0}`.

{1}Original error is below:
------------------------
{2}

Traceback:
---------
{3}c         s` s   |  ] } | j  Vq d  S(   N(   Rm   (   RL   t   e(    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    (   i   (   RN   t   ArrayRV   t   onest   ndimRm   t   errstatet	   Exceptiont   syst   exc_infot   joint	   tracebackt	   format_tbt   formatt   reprRK   t
   ValueErrorRR   (   t   funct   argsR   R&   t   suggest_dtypet   noutRM   t   oR   t   exc_typet	   exc_valuet   exc_tracebackt   tbt   suggestt   msg(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   apply_infer_dtypeē   s     Dc         C` s   t  |   r |  St |  t  r; t j d |   r; t |   St |  t  rf t |   d k rf t |   St |   d k r t |   S|  Sd S(   s?   Normalize user provided arguments to blockwise or map_blocks

    We do a few things:

    1.  If they are string literals that might collide with blockwise_token then we
        quote them
    2.  IF they are large (as defined by sizeof) then we put them into the
        graph on their own by using dask.delayed
    s   _\d+i
   g    .AN(	   R   RN   t   strt   ret   matchR5   Rc   Rp   R9   (   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   normalize_arg   s    
!
!

c   #      ` s6	  t  |   s. d } t | t |   j   n  | j d d
  } | j d d
  } | rn t j d  | } n  d | p t |   t	 |  | |  f } | j d d
  } | j d d
  } | j d g     | j d	 d
   i  } t
   t  r’   g   n  t
  t  r g  n  g  | D] }	 t
 |	 t  r!|	 ^ q!}
 g  | D]I }	 t
 |	 t  r|	 t t |	 j   d
 d
 d  f n	 |	 d
 f ^ qI} |
 rŠt t t d   |
 D    d
 d
 d  } n d# } t |  d  rņd | d <n  t |  d  rd | d <n  | } | d
 k r8t |  | | d  } n    rct   f d   t |  D  } n   d
 k r²| d
 k	 r²t |  t |  k  r²t t |  t |    n   r^t |  } xa t   D]S } t |  t    } | j | |  | d
 k	 r| | | | <qŃd | | <qŃWt |  } t   t |  k r^t d   q^n  t |  | d | d | d | d t d t t |  |  t |  d  s»t |  d  s»  rš j j  j } t  |  } |  j j  j <n  t |  d  rx | j!   D] \ } } t" j" | d  } t" j" | j#  | _# | j# j!   \ \ } } t$ | i | d d 6 } | | j# | <| f | d | | <qWn  | d
 k	 rØt |  t  j%  k rģt d j& t |  t  j%     n  g  } x” t t' |  j%   D] \  \ } } t
 | t  r~| d k rnt |  | k rnt d j&  | t |     n  | j( |  q| j( | | f  qWt) |   _* n  t |  d  r2	i  } i   i  } xs t |  D]e \  } t
 | t  rÖg  | j+ D] } t, j- d$ |  ^ qū|  <| j. |  <| j%   <qÖqÖWxs | j!   D]e \ } } t
 | t  rLg  | j+ D] } t, j- d% |  ^ qq| | <| j. | | <| j%   <qLqLWg   j+ D] } t, j- d& |  ^ qæ} xQ| j!   D]@\ } } | } | d } | j# j!   \ \ } }  rNt  f d   t | d  D  } n
 | d } i  } x» | j!   D]­ \  } | t |  }  t   f d   t |   D  }  i | d 6  d 6g  t |   D]4 \ }! }" |  |! |" |  |! |" d f ^ qĻd 6|  d  6|  <qkWi  j. d 6 j% d 6g  t | d  D], \ }! }" | |! |" | |! |" d f ^ qDd 6| d d  6t  f d!   t | d  D  d" 6| d 6| d
 <t" j" |  } t" j" | j#  | _# | j# j!   \ \ } } t$ | i | d 6 } | | j# | <| f | d | | <qėWn   S('   s   Map a function across all blocks of a dask array.

    Parameters
    ----------
    func : callable
        Function to apply to every block in the array.
    args : dask arrays or other objects
    dtype : np.dtype, optional
        The ``dtype`` of the output array. It is recommended to provide this.
        If not provided, will be inferred by applying the function to a small
        set of fake data.
    chunks : tuple, optional
        Chunk shape of resulting blocks if the function does not preserve
        shape. If not provided, the resulting array is assumed to have the same
        block structure as the first input array.
    drop_axis : number or iterable, optional
        Dimensions lost by the function.
    new_axis : number or iterable, optional
        New dimensions created by the function. Note that these are applied
        after ``drop_axis`` (if present).
    token : string, optional
        The key prefix to use for the output array. If not provided, will be
        determined from the function name.
    name : string, optional
        The key name to use for the output array. Note that this fully
        specifies the output key name, and must be unique. If not provided,
        will be determined by a hash of the arguments.
    **kwargs :
        Other keyword arguments to pass to function. Values must be constants
        (not dask.arrays)

    Examples
    --------
    >>> import dask.array as da
    >>> x = da.arange(6, chunks=3)

    >>> x.map_blocks(lambda x: x * 2).compute()
    array([ 0,  2,  4,  6,  8, 10])

    The ``da.map_blocks`` function can also accept multiple arrays.

    >>> d = da.arange(5, chunks=2)
    >>> e = da.arange(5, chunks=2)

    >>> f = map_blocks(lambda a, b: a + b**2, d, e)
    >>> f.compute()
    array([ 0,  2,  6, 12, 20])

    If the function changes shape of the blocks then you must provide chunks
    explicitly.

    >>> y = x.map_blocks(lambda x: x[::2], chunks=((2, 2),))

    You have a bit of freedom in specifying chunks.  If all of the output chunk
    sizes are the same, you can provide just that chunk size as a single tuple.

    >>> a = da.arange(18, chunks=(6,))
    >>> b = a.map_blocks(lambda x: x[:3], chunks=(3,))

    If the function changes the dimension of the blocks you must specify the
    created or destroyed dimensions.

    >>> b = a.map_blocks(lambda x: x[None, :, None], chunks=(1, 6, 1),
    ...                  new_axis=[0, 2])

    If ``chunks`` is specified but ``new_axis`` is not, then it is inferred to
    add the necessary number of axes on the left.

    Map_blocks aligns blocks by block positions without regard to shape. In the
    following example we have two arrays with the same number of blocks but
    with different shape and chunk sizes.

    >>> x = da.arange(1000, chunks=(100,))
    >>> y = da.arange(100, chunks=(10,))

    The relevant attribute to match is numblocks.

    >>> x.numblocks
    (10,)
    >>> y.numblocks
    (10,)

    If these match (up to broadcasting rules) then we can map arbitrary
    functions across blocks

    >>> def func(a, b):
    ...     return np.array([a.max(), b.max()])

    >>> da.map_blocks(func, x, y, chunks=(2,), dtype='i8')
    dask.array<func, shape=(20,), dtype=int64, chunksize=(2,)>

    >>> _.compute()
    array([ 99,   9, 199,  19, 299,  29, 399,  39, 499,  49, 599,  59, 699,
            69, 799,  79, 899,  89, 999,  99])

    Your block function get information about where it is in the array by
    accepting a special ``block_info`` keyword argument.

    >>> def func(block, block_info=None):
    ...     pass

    This will receive the following information:

    >>> block_info  # doctest: +SKIP
    {0: {'shape': (1000,),
         'num-chunks': (10,),
         'chunk-location': (4,),
         'array-location': [(400, 500)]},
     None: {'shape': (1000,),
            'num-chunks': (10,),
            'chunk-location': (4,),
            'array-location': [(400, 500)],
            'chunk-shape': (100,),
            'dtype': dtype('float64')}}

    For each argument and keyword arguments that are dask arrays (the positions
    of which are the first index), you will receive the shape of the full
    array, the number of chunks of the full array in each dimension, the chunk
    location (for example the fourth chunk over in the first dimension), and
    the array location (for example the slice corresponding to ``40:50``). The
    same information is provided for the output, with the key ``None``, plus
    the shape and dtype that should be returned.

    These features can be combined to synthesize an array from scratch, for
    example:

    >>> def func(block_info=None):
    ...     loc = block_info[None]['array-location'][0]
    ...     return np.arange(loc[0], loc[1])

    >>> da.map_blocks(func, chunks=((4, 4),), dtype=np.float_)
    dask.array<func, shape=(8,), dtype=float64, chunksize=(4,)>

    >>> _.compute()
    array([0, 1, 2, 3, 4, 5, 6, 7])

    You may specify the key name prefix of the resulting task in the graph with
    the optional ``token`` keyword argument.

    >>> x.map_blocks(lambda x: x + 1, name='increment')  # doctest: +SKIP
    dask.array<increment, shape=(100,), dtype=int64, chunksize=(10,)>
    s~   First argument must be callable function, not %s
Usage:   da.map_blocks(function, x)
   or:   da.map_blocks(function, x, y, z)t   namet   tokens8   The token= keyword to map_blocks has been moved to name=s   %s-%sRm   Re   t	   drop_axist   new_axisNi’’’’c         s` s   |  ] } | j  Vq d  S(   N(   R   (   RL   RX   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ć  s    t   block_idt   __block_id_dummy__t
   block_infot   __block_info_dummy__t
   map_blocksc         3` s'   |  ] \ } } |   k r | Vq d  S(   N(    (   RL   t   iRM   (   RÆ   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ņ  s    i   s-   New_axis values do not fill in all dimensionst   new_axesRD   t   align_arraysi    s1   Provided chunks have {0} dims, expected {1} dims.s>   Dimension {0} has {1} blocks, chunks specified with {2} blocksc         3` s'   |  ] \ } } |   k r | Vq d  S(   N(    (   RL   R¶   RM   (   R°   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>B  s    c         3` s5   |  ]+ \ } }    | d  k r) | n d Vq d S(   i   i    N(    (   RL   t   ijt   j(   R¶   t
   num_chunks(    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>M  s    Rk   s
   num-chunkss   array-locations   chunk-locationc         3` s&   |  ] \ } }   j  | | Vq d  S(   N(   Re   (   RL   R¹   Rŗ   (   t   out(    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>Y  s   s   chunk-shape(    (   i    (   i    (   i    (/   t   callablet	   TypeErrorR   RH   t   popRK   t   warningst   warnR&   R   RN   R   R   RR   Ro   R   R   R,   RØ   t	   enumerateRp   Rc   t   sortedt   insertR   RA   t   Truet   FalseR   t   daskt   layersR­   Rr   t   itemst   copyt   dskR   t	   numblocksR   Rd   t   appendRn   t   _chunksRe   RV   t   cumsumRk   (#   R   R   R   R§   R­   R®   Rm   Re   R·   RX   t   arrst   argpairst   out_indt   original_kwargst   axt   nRĖ   t   kt   vvt   vR   t   taskt   chunks2R\   t   nbRi   Rh   t   argt
   out_startst   old_kt   infoRk   t   arr_kR¹   Rŗ   (    (   RÆ   R¶   R°   R»   R¼   s.   lib/python2.7/site-packages/dask/array/core.pyRµ   6  sš    	((S2%0$	!+	--)
)
%
E
Ac          G` s.  |  s
 d St  |   d k r$ |  d St t t  |    } g  |  D] } d | t  |  | ^ q@ } g  } x· t |  D]© } g  | D] } | | ^ q } t d   | D  r¹ | } n% g  | D] } | d k rĄ | ^ qĄ } t  t |   d k rt d t |    n  | j | d  qw Wt	 |  S(	   s]   Construct a chunks tuple that broadcasts many chunks tuples

    >>> a = ((5, 5),)
    >>> b = ((5, 5),)
    >>> broadcast_chunks(a, b)
    ((5, 5),)

    >>> a = ((10, 10, 10), (5, 5),)
    >>> b = ((5, 5),)
    >>> broadcast_chunks(a, b)
    ((10, 10, 10), (5, 5))

    >>> a = ((10, 10, 10), (5, 5),)
    >>> b = ((1,), (5, 5),)
    >>> broadcast_chunks(a, b)
    ((10, 10, 10), (5, 5))

    >>> a = ((10, 10, 10), (5, 5),)
    >>> b = ((3, 3,), (5, 5),)
    >>> broadcast_chunks(a, b)
    Traceback (most recent call last):
        ...
    ValueError: Chunks do not align: [(10, 10, 10), (3, 3)]
    i   i    c         s` s   |  ] } | d k Vq d S(   i   N(   i   (    (   RL   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    s   Chunks do not align: %s(    (   i   (   (   i   (   i   (
   Rp   R   R   Ro   R   t   setR   R©   RĶ   RR   (   t   chunkssRÕ   R\   t   chunkss2t   resultR¶   t   step1t   step2(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   broadcast_chunksg  s     +	%c         ` s.  t  |  t  r$ |  g }  | g } n  t d   |  D  rI t d   n  t |   t |  k r t d t |   t |  f   n  t  | t  s” | d	 k r­ | g } n  t |   d k rä t |  d k rä | t |   9} n  t |   t |  k r*t d t |   t |  t |  f   n  t j g  |  D] } | j	   ^ q7  } t j
 | t t j g  |  D] } | j   ^ qk   } g  |  D]$ } t | | j | j | j  ^ q}	 g  }
 g  } g  } x~ | D]v } t  | t  r$|
 j | j  | j | j    | j | j	    qÖt |  r?t d   qÖ|
 j |  qÖWt j |   } t j
 | |  } | o{| } g  t t |    D] } t t j    ^ q} t j g  t |	 |
 | |  D]0 \ } } } } t | | | | | | |  ^ qĖ  } t | j    } t j | | |  } | rŃ|   | rØg  | D] } t | |  ^ qD} t | |   } t j g  | D] } | j  ^ q{  } t! | | |    n  t   f d   t |  |  D  } | Sd t t j    } t j i | | 6|  } t | |  } | r&| j" |   d	 S| Sd	 S(
   sŲ   Store dask arrays in array-like objects, overwrite data in target

    This stores dask arrays into object that supports numpy-style setitem
    indexing.  It stores values chunk by chunk so that it does not have to
    fill up memory.  For best performance you can align the block size of
    the storage target with the block size of your array.

    If your data fits in memory then you may prefer calling
    ``np.array(myarray)`` instead.

    Parameters
    ----------

    sources: Array or iterable of Arrays
    targets: array-like or Delayed or iterable of array-likes and/or Delayeds
        These should support setitem syntax ``target[10:20] = ...``
    lock: boolean or threading.Lock, optional
        Whether or not to lock the data stores while storing.
        Pass True (lock each file individually), False (don't lock) or a
        particular ``threading.Lock`` object to be shared among all writes.
    regions: tuple of slices or list of tuples of slices
        Each ``region`` tuple in ``regions`` should be such that
        ``target[region].shape = source.shape``
        for the corresponding source and target in sources and targets,
        respectively. If this is a tuple, the contents will be assumed to be
        slices, so do not provide a tuple of tuples.
    compute: boolean, optional
        If true compute immediately, return ``dask.delayed.Delayed`` otherwise
    return_stored: boolean, optional
        Optionally return the stored result (default False).

    Examples
    --------
    >>> x = ...  # doctest: +SKIP

    >>> import h5py  # doctest: +SKIP
    >>> f = h5py.File('myfile.hdf5')  # doctest: +SKIP
    >>> dset = f.create_dataset('/data', shape=x.shape,
    ...                                  chunks=x.chunks,
    ...                                  dtype='f8')  # doctest: +SKIP

    >>> store(x, dset)  # doctest: +SKIP

    Alternatively store many arrays at the same time

    >>> store([x, y, z], [dset1, dset2, dset3])  # doctest: +SKIP
    c         s` s   |  ] } t  | t  Vq d  S(   N(   RN   R   (   RL   Ra   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>É  s    s&   All sources must be dask array objectss1   Different number of sources [%d] and targets [%d]i   sC   Different number of sources [%d] and targets [%d] than regions [%d]s5   Targets must be either Delayed objects or array-likesc         3` s4   |  ]* \ } } t    d  | | j | j  Vq d S(   s   load-store-%sN(   R   Re   Rm   (   RL   Ra   t   t(   t   load_store_dsk(    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s   s   store-N(#   RN   R   RS   R   Rp   RR   RK   R:   t   merget   __dask_graph__t   __dask_optimize__Rc   R8   t   flattent   __dask_keys__R­   Re   Rm   R6   RĶ   R   t   extendR   R¾   Ro   R©   t   uuidt   uuid1Rd   t   insert_to_oocRu   R   RĒ   t   retrieve_from_ooct   compute(   t   sourcest   targetsRQ   t   regionsRō   t   return_storedR   R   t   sources_dskt   sources2t   targets2t   targets_keyst   targets_dskt   load_storedt   _t   toksRa   Rč   t   rt   tokt	   store_dskt
   store_keysRÖ   t   store_dlydst   store_dsk_2Rä   R­   RĖ   (    (   Ré   s.   lib/python2.7/site-packages/dask/array/core.pyt   store  sx    2	$((111L"%c         C` s  | d k r t d   n  |  d k r6 t d   n  t j t |    s` t j t |   ry t d |  | f   n  t t t |   s t d   n  t t t |    sĮ t d   n  t	 t t
 |    }  t	 t t
 |   } t	 d   t |  |  D  S(   s”   

    >>> blockdims_from_blockshape((10, 10), (4, 3))
    ((4, 4, 2), (3, 3, 3, 1))
    >>> blockdims_from_blockshape((10, 0), (4, 0))
    ((4, 4, 2), (0,))
    s$   Must supply chunks= keyword arguments#   Must supply shape= keyword arguments4   Array chunk sizes are unknown. shape: %s, chunks: %ss!   chunks can only contain integers.s    shape can only contain integers.c         s` sM   |  ]C \ } } | rA | f | | | | r: | | f n d n d Vq d S(   i    N(    (   i    (    (   RL   t   dt   bd(    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>1  s   N(   RK   R¾   RV   t   isnanRy   R   R   R   R$   RR   t   intRd   (   Rk   Re   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   blockdims_from_blockshape  s    *	c         C` sb   |  s t  |   S|  } x? t | t t f  rW t |  d k rJ t  |   S| d } q Wt |   S(   Ni   i    (   t   concatenate3RN   RR   Rc   Rp   t   unpack_singleton(   t   resultst   results2(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   finalize6  s    

sŃ   
You must specify a chunks= keyword argument.
This specifies the chunksize of your array blocks.

See the following documentation page for details:
  https://docs.dask.org/en/latest/array-creation.html#chunks
R   c           B` s  e  Z d  Z d Z d d  Z d   Z d   Z d	   Z d
   Z	 d   Z
 e e d d d e Z e e j  Z d   Z d   Z e d    Z e d    Z e d    Z e d    Z e d    Z d   Z d   Z e e e d  Z d   Z d   Z d   Z  e d    Z! e d    Z" e d    Z# e d    Z$ e d     Z% e% j& d!    Z% d" Z' d d#  Z( d$   Z) e d%    Z* e+ e,  d&    Z, d'   Z- d d d(  Z. d)   Z/ e/ Z0 d*   Z1 d+   Z2 e2 Z3 d,   Z4 d-   Z5 d.   Z6 d/   Z7 d0   Z8 e d1    Z9 d2   Z: e d3    Z; e< e= j>  d4    Z? e d5    Z@ e d6    ZA e< e= j>  d7    ZB e< e= j>  d8    ZC eC ZD e< e= j>  d9    ZE e< e= j>  d:    ZF d; d d<  ZG d; d d=  ZH d>   ZI d?   ZJ d@   ZK dA   ZL dB   ZM dC   ZN dD   ZO dE   ZP dF   ZQ dG   ZR dH   ZS dI   ZT dJ   ZU dK   ZV dL   ZW dM   ZX dN   ZY dO   ZZ dP   Z[ dQ   Z\ dR   Z] dS   Z^ dT   Z_ dU   Z` dV   Za dW   Zb dX   Zc dY   Zd dZ   Ze d[   Zf d\   Zg d]   Zh d^   Zi d_   Zj d`   Zk da   Zl db   Zm dc   Zn dd   Zo e< e= j>  d ep d d de   Zq e< e= j>  d ep d d df   Zr e< e= j>  d ep d d dg   Zs e< e= j>  d ep d d dh   Zt e< e= j>  d d d di   Zu e< e= j>  d d d dj   Zv e< e= j>  d d ep d d dk   Zw e< e= j>  dl dl dm d dn   Zx e< e= j>  d d ep d d do   Zy e< e= j>  d d ep d d dp   Zz e< e= j>  d d ep dl d d dq   Z{ e< e= j>  d d ep dl d d dr   Z| d d ep dl d d ds  Z} e+ e~  dt    Z~ d e du  Z d d dv  Z d d dw  Z e< e= j>  d dx   Z d d dy  Z e dz    Z e d{    Z d|   Z e< e= j>  d d d}   Z d~ d  Z e< e= j>  d    Z e< e= j>  dl d   Z d   Z d   Z e d  Z e< e= j>  d d   Z e< e= j>  d    Z d   Z d   Z RS(   s   Parallel Dask Array

    A parallel nd-array comprised of many numpy arrays arranged in a grid.

    This constructor is for advanced uses only.  For normal use see the
    ``da.from_array`` function.

    Parameters
    ----------

    dask : dict
        Task dependency graph
    name : string
        Name of array in dask
    shape : tuple of ints
        Shape of the entire array
    chunks: iterable of tuples
        block sizes along each dimension

    See Also
    --------
    dask.array.from_array
    RĒ   t   _namet   _cached_keysRĪ   Rm   c   	      C` s  t  t |   j |   } t | t  s- t  t | t  sW t j | | d d } n  | | _ | | _	 | d  k r t d   n  t j |  | _ t | | d | j | _ | j d  k rĻ t t   n  x; t j d d  D]' } | |  } | d  k	 rā | } qā qā W| S(   Nt   dependenciess'   You must specify the dtype of the arrayRm   t   array_plugins(    (    (   t   superR   t   __new__RN   R3   t   AssertionErrorR:   t   from_collectionsRĒ   R­   RK   R   RV   Rm   Rn   RĪ   t   CHUNKS_NONE_ERROR_MESSAGER   t   get(	   t   clsRĒ   R­   Re   Rm   Rk   t   selft   pluginRä   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  e  s"    		c         C` s"   t  |  j |  j |  j |  j f f S(   N(   R   RĒ   R­   Re   Rm   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt
   __reduce__{  s    c         C` s   |  j  S(   N(   RĒ   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRė   ~  s    c         C` s
   |  j  f S(   N(   R­   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __dask_layers__  s    c         ` s_   |  j  d  k	 r |  j  S|  j |  j |  j          f d       |  _  } | S(   Nc          ` s     s  f g St  |   } | d t    k rf g  t  |  D] }  f |  | f ^ qC } n0 g  t  |  D] }  |  | f   ^ qw } | S(   Ni   (   Rp   Ro   (   R   t   indR¶   Rä   (   Re   Ru   R­   RĢ   (    s.   lib/python2.7/site-packages/dask/array/core.pyRu     s    
40(   R  RK   R­   Re   RĢ   (   R  Rä   (    (   Re   Ru   R­   RĢ   s.   lib/python2.7/site-packages/dask/array/core.pyRī     s    
c         C` s   |  j  S(   N(   R­   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __dask_tokenize__  s    R   t   array_optimizet   falseyc         C` s
   t  d f S(   N(    (   R  (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __dask_postcompute__  s    c         C` s   t  |  j |  j |  j f f S(   N(   R   R­   Re   Rm   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __dask_postpersist__”  s    c         C` s   t  t t |  j   S(   N(   RR   R   Rp   Re   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRĢ   ¤  s    c         C` s   t  t |  j d  S(   Ni   (   R   R   RĢ   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   npartitionsØ  s    c         C` s   t  t t |  j   S(   N(   RR   R   Ry   Re   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRk   ¬  s    c         C` s   t  d   |  j D  S(   Nc         s` s   |  ] } t  |  Vq d  S(   N(   R   (   RL   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>²  s    (   RR   Re   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt	   chunksize°  s    c         C` s   t  j d d d |  j  S(   NRk   Rm   (    (   RV   t   emptyRm   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   _meta“  s    c         C` s   |  j  S(   N(   RĪ   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   _get_chunksø  s    c         C` s   t  d t |    d  S(   NsS   Can not set chunks directly

Please use the rechunk method instead:
  x.rechunk(%s)(   R¾   R©   (   R  Re   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   _set_chunks»  s    s   chunks propertyc         C` s)   |  j  s t d   n  t |  j  d  S(   Ns   len() of unsized objecti    (   Re   R¾   Ry   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __len__Ā  s    	c         O` s|  | j  d d  } x1 | | D]% } t | t j t t f  s t Sq W| d k r| t j k r~ d d l m } | | |   S| j	 d  k	 r³ d d l m } | | | j	 | |  S| j d k r
d d l m }	 y t |	 | j  }
 Wn t k
 rü t SX|
 | |   St | | |  Sn[ | d k rtd d l m }	 y t |	 | j  }
 Wn t k
 rct SX|
 j | |   St Sd  S(	   NR¼   t   __call__i   (   t   matmul(   t   apply_gufunc(   t   ufunct   outer(    (   R  RN   RV   t   ndarrayR   R   t   NotImplementedR/  t   routinest	   signatureRK   t   gufuncR0  R    R   R1  t   getattrRH   t   AttributeErrort   elemwiseR2  (   R  t   numpy_ufunct   methodt   inputsR   R¼   RM   R/  R0  R1  t   da_ufunc(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __array_ufunc__Ē  s<    c         C` sB   t  |  j  } |  j j d d  d } d | |  j |  j | f S(   s®   

        >>> import dask.array as da
        >>> da.ones((10, 10), chunks=(5, 5), dtype='i4')
        dask.array<..., shape=(10, 10), dtype=int32, chunksize=(5, 5)>
        t   -i   i    s0   dask.array<%s, shape=%s, dtype=%s, chunksize=%s>(   R©   R(  R­   t   rsplitRk   Rm   (   R  R(  R­   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __repr__ė  s    c         C` s   t  |  j  S(   N(   Rp   Rk   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR   ÷  s    c         C` s   t  t |  j d  S(   s    Number of elements in array i   (   R   R   Rk   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   sizeū  s    c         C` s   |  j  |  j j S(   s    Number of bytes in array (   RC  Rm   t   itemsize(   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   nbytes   s    c         C` s
   |  j  j S(   s&    Length of one array element in bytes (   Rm   RD  (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRD    s    c         C` s   |  j  S(   N(   R  (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR­   
  s    c         C` s   | |  _  d  |  _ d  S(   N(   R  RK   R  (   R  t   val(    (    s.   lib/python2.7/site-packages/dask/array/core.pyR­     s    	i   c         K` s[   |  j    } | r3 | j | k r3 | j |  } n  t | t j  sW t j |  } n  | S(   N(   Rō   Rm   t   astypeRN   RV   R3  RC   (   R  Rm   R   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt	   __array__  s    c         C` s   d d  l  j } xF | j j d  d D]. } y t | |  } Wq& t k
 rS t SXq& Wt | | j  sn t St | | j  } | | k r t S| | |   S(   Ni    t   .i   (	   t
   dask.arrayRC   RI   t   splitR8  R9  R4  t   hasattrRH   (   R  R   t   typesR   R   t   modulet	   submodulet   da_func(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __array_function__  s    	c         C` s   t  S(   N(   R:  (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt	   _elemwise,  s    c         K` s;   t  |  g | g |  } | j d t  r7 | d } n  | S(   NRų   i    (   R  R  RĘ   (   R  t   targetR   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  0  s    c         K` s   t  | | |  |  S(   sd   Store array in HDF5 file

        >>> x.to_hdf5('myfile.hdf5', '/x')  # doctest: +SKIP

        Optionally provide arguments as though to ``h5py.File.create_dataset``

        >>> x.to_hdf5('myfile.hdf5', '/x', compression='lzf', shuffle=True)  # doctest: +SKIP

        See Also
        --------
        da.store
        h5py.File.create_dataset
        (   t   to_hdf5(   R  t   filenamet   datapathR   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRT  9  s    c         C` s&   d d l  m } | |  d | d | S(   sm   Convert dask Array to dask Dataframe

        Parameters
        ----------
        columns: list or string
            list of column names if DataFrame, single string if Series
        index : dask.dataframe.Index, optional
            An optional *dask* Index to use for the output Series or DataFrame.

            The default output index depends on whether the array has any unknown
            chunks. If there are any unknown chunks, the output has ``None``
            for all the divisions (one per chunk). If all the chunks are known,
            a default index with known divsions is created.

            Specifying ``index`` can be useful if you're conforming a Dask Array
            to an existing dask Series or DataFrame, and you would like the
            indices to match.

        See Also
        --------
        dask.dataframe.from_dask_array
        i   (   t   from_dask_arrayt   columnst   index(   t	   dataframeRW  (   R  RX  RY  RW  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   to_dask_dataframeI  s    c         C` sA   |  j  d k r- t d j |  j j    n t |  j    Sd  S(   Ni   s>   The truth value of a {0} is ambiguous. Use a.any() or a.all().(   RC  R   R   t	   __class__RH   t   boolRō   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __bool__c  s    	c         C` s2   |  j  d k r t d   n | |  j    Sd  S(   Ni   s7   Only length-1 arrays can be converted to Python scalars(   RC  R¾   Rō   (   R  t	   cast_type(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   _scalarfuncm  s    c         C` s   |  j  t  S(   N(   R`  R  (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __int__t  s    c         C` s   |  j  t  S(   N(   R`  t   float(   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt	   __float__y  s    c         C` s   |  j  t  S(   N(   R`  t   complex(   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __complex__|  s    c         C` s¬   d d l  m } t | t  r t | t  rL | j d k rL t d   n  | | | |   } | j |  _ | j |  _ | j |  _ | j	 |  _
 |  St d t |    d  S(   Ni   (   t   wheres+   boolean index array should have 1 dimensions%   Item assignment with %s not supported(   R5  Rf  RN   R   R   R   Rm   RĒ   R­   Re   RĪ   t   NotImplementedErrorR   (   R  R   t   valueRf  t   y(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __setitem__  s    c      	   C` sl  t  | t t f  s@ t  | t  r| rt d   | D  rt  | t t f  re |  j | } n t |  j |  } | j rķ t t |  j	 |  j	 t
 | j    } |  j t d   | j D  } |  j t | d | j d | d | S|  j t | d | Sn  t  | t  s!| f } n  d d l m } m } m } | | |  j  } |  j h }	 x0 | D]( }
 t  |
 t  rb|	 j |
 j  qbqbWt d   | D  r¼| |  |  \ }  } n  t d	   | D  rź| |  |  \ }  } n  t d
   | D  r|  Sd t |  |  } t | |  j |  j |  \ } } t j | | d |  g } t | | | d |  j S(   Nc         s` s$   |  ] } t  | t t f  Vq d  S(   N(   RN   R©   R/   (   RL   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    c         s` s   |  ] } | f Vq d  S(   N(    (   RL   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    Rm   Re   R°   i   (   t   normalize_indext   slice_with_int_dask_arrayt   slice_with_bool_dask_arrayc         s` s0   |  ]& } t  | t  o' | j j d  k Vq d S(   t   iuN(   RN   R   Rm   t   kind(   RL   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>«  s    c         s` s-   |  ]# } t  | t  o$ | j t k Vq d  S(   N(   RN   R   Rm   R]  (   RL   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>­  s    c         s` s0   |  ]& } t  | t  o' | t d   k Vq d  S(   N(   RN   RO   RK   (   RL   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>°  s    s   getitem-R  (   RN   R©   R/   Rc   R   Rm   R>   Rk   Ro   R   Rp   Re   RR   Rµ   R
   t   baset   slicingRk  Rl  Rm  R­   R   R	   RS   R   R?   R:   R  (   R  RY  t   dtR°   Re   Rk  Rl  Rm  t   index2R  R¶   R¼   RĖ   t   graph(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __getitem__  s<    	( !c         C` sŖ   t  | t  s | f } n  t d   | D  rI t d j |    n  t d   | D  r t d   t | |  j  D  r |  St d j |    n  t |  |  S(   Nc         s` s   |  ] } | d  k Vq d  S(   N(   RK   (   RL   RÖ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>¼  s    s?   vindex does not support indexing with None (np.newaxis), got {}c         s` s   |  ] } t  | t  Vq d  S(   N(   RN   RO   (   RL   RÖ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>Ą  s    c         s` s<   |  ]2 \ } } | j  |  t d  |  j  |  k Vq d S(   i    N(   t   indicesRO   (   RL   RÖ   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>Į  s   s®   vindex requires at least one non-slice to vectorize over when the slices are not over the entire array (i.e, x[:]). Use normal slicing instead when only using slices. Got: {}(	   RN   RR   RS   t
   IndexErrorR   R   Rd   Rk   t   _vindex(   R  R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRx  ¹  s    	c         C` s   t  |  j  S(   sT  Vectorized indexing with broadcasting.

        This is equivalent to numpy's advanced indexing, using arrays that are
        broadcast against each other. This allows for pointwise indexing:

        >>> x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        >>> x = from_array(x, chunks=2)
        >>> x.vindex[[0, 1, 2], [0, 1, 2]].compute()
        array([1, 5, 9])

        Mixed basic/advanced indexing with slices/arrays is also supported. The
        order of dimensions in the result follows those proposed for
        ndarray.vindex [1]_: the subspace spanned by arrays is followed by all
        slices.

        Note: ``vindex`` provides more general functionality than standard
        indexing, but it also has fewer optimizations and can be significantly
        slower.

        _[1]: https://github.com/numpy/numpy/pull/6256
        (   R%   Rx  (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   vindexĖ  s    c         ` sr  d d l  m } t | t  s+ | f } n  t d   | D  d k rV t d   n  t d   | D  r{ t d   n  | | |  j  } t d   | D  } d t |  |    t	 j
 |  j   d	 t |  t d
   t |  j |  D  } t t g  | D] } t t |   ^ q   }    f d   | D } t j   | d |  g } t |   | |  j  S(   Ni   (   Rk  c         s` s'   |  ] } t  | t j t f  Vq d  S(   N(   RN   RV   R3  Rc   (   RL   R!  (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>č  s    s!   Can only slice with a single listc         s` s   |  ] } | d  k Vq d  S(   N(   RK   (   RL   R!  (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ź  s    s0   Slicing with np.newaxis or None is not supportedc         s` s7   |  ]- } t  | t  r+ t | | d   n | Vq d S(   i   N(   RN   R   RO   (   RL   RÖ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ķ  s   s   blocks-Rm   c         s` s4   |  ]* \ } } t  t j |  | j    Vq d  S(   N(   RR   RV   RC   t   tolist(   RL   R\   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ō  s   c         ` s0   i  |  ]& } t   | j      f |  q S(    (   RR   Rz  (   RL   R   (   R­   t   new_keys(    s.   lib/python2.7/site-packages/dask/array/core.pys
   <dictcomp>ł  s   	 R  (   Rq  Rk  RN   RR   Ry   R   RS   RĢ   R   RV   RC   Rī   t   objectRd   Re   Rc   R   Ro   Rp   R:   R  R   Rm   (   R  RY  Rk  Re   R\   Ru   t   layerRt  (    (   R­   R{  s.   lib/python2.7/site-packages/dask/array/core.pyt   _blocksä  s$    		1c         C` s   t  |  j  S(   s   Slice an array by blocks

        This allows blockwise slicing of a Dask array.  You can perform normal
        Numpy-style slicing but now rather than slice elements of the array you
        slice along blocks so, for example, ``x.blocks[0, ::2]`` produces a new
        dask array with every other block in the first row of blocks.

        You can index blocks in any way that could index a numpy array of shape
        equal to the number of blocks in each dimension, (available as
        array.numblocks).  The dimension of the output array will be the same
        as the dimension of this array, even if integer indices are passed.
        This does not support slicing with ``np.newaxis`` or multiple lists.

        Examples
        --------
        >>> import dask.array as da
        >>> x = da.arange(10, chunks=2)
        >>> x.blocks[0].compute()
        array([0, 1])
        >>> x.blocks[:3].compute()
        array([0, 1, 2, 3, 4, 5])
        >>> x.blocks[::2].compute()
        array([0, 1, 4, 5, 8, 9])
        >>> x.blocks[[-1, 0]].compute()
        array([8, 9, 0, 1])

        Returns
        -------
        A Dask array
        (   R%   R~  (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   blocksž  s     c         C` s=   d d l  m } | |  | d |  j d f | j d f f S(   Ni   (   RE   R   i   (   R5  RE   R   (   R  t   otherRE   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRz      s    c         C` s   |  S(   N(    (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR{   &  s    c         C` s
   |  j    S(   N(   t	   transpose(   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   T*  s    c         G` sa   d d l  m } | s d  } n2 t |  d k rQ t | d t  rQ | d } n  | |  d | S(   Ni   (   R  i    R   (   R5  R  RK   Rp   RN   R1   (   R  R   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  .  s    	%c         C` s   d d l  m } | |   S(   Ni   (   t   ravel(   R5  R  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  7  s    c         C` s   d d l  m } | |  |  S(   Ni   (   t   choose(   R5  R  (   R  t   choicesR  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  >  s    c         G` sP   d d l  m  } t |  d k rC t | d t  rC | d } n  | |  |  S(   Ni   (   t   reshapei    (   R  Rp   RN   R   (   R  Rk   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  C  s    &i’’’’c         C` s)   d d l  m } | |  | d | d | S(   sF   The top k elements of an array.

        See ``da.topk`` for docstringi   (   t   topkR   t   split_every(   t
   reductionsR  (   R  RÖ   R   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  J  s    c         C` s)   d d l  m } | |  | d | d | S(   sX   The indices of the top k elements of an array.

        See ``da.argtopk`` for docstringi   (   t   argtopkR   R  (   R  R  (   R  RÖ   R   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  Q  s    c         K` sÉ   t  |  d d h } | r: t d j t |     n  | j d d  } t j |  } |  j | k rn |  St j |  j | d | sŖ t d j |  j | |    n  |  j t	 j
 d | d | | S(   s÷  Copy of the array, cast to a specified type.

        Parameters
        ----------
        dtype : str or dtype
            Typecode or data-type to which the array is cast.
        casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
            Controls what kind of data casting may occur. Defaults to 'unsafe'
            for backwards compatibility.

            * 'no' means the data types should not be cast at all.
            * 'equiv' means only byte-order changes are allowed.
            * 'safe' means only casts which can preserve values are allowed.
            * 'same_kind' means only safe casts or casts within a kind,
                like float64 to float32, are allowed.
            * 'unsafe' means any data conversions may be done.
        copy : bool, optional
            By default, astype always returns a newly allocated array. If this
            is set to False and the `dtype` requirement is satisfied, the input
            array is returned instead of a copy.
        t   castingRŹ   s;   astype does not take the following keyword arguments: {0!s}t   unsafesA   Cannot cast array from {0!r} to {1!r} according to the rule {2!r}Rm   t   astype_dtype(   Rį   R¾   R   Rc   R  RV   Rm   t   can_castRµ   R   RG  (   R  Rm   R   t   extraR  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRG  X  s    		c         C` s   t  t j |   S(   N(   R:  Rq   t   abs(   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __abs__  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   R	   (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __add__  s    c         C` s   t  t j | |   S(   N(   R:  Rq   R	   (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __radd__  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   and_(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __and__  s    c         C` s   t  t j | |   S(   N(   R:  Rq   R  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rand__  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   div(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __div__  s    c         C` s   t  t j | |   S(   N(   R:  Rq   R  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rdiv__  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   eq(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __eq__  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   gt(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __gt__  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   ge(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __ge__  s    c         C` s   t  t j |   S(   N(   R:  Rq   t   invert(   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt
   __invert__  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   lshift(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt
   __lshift__   s    c         C` s   t  t j | |   S(   N(   R:  Rq   R¢  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rlshift__£  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   lt(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __lt__¦  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   le(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __le__©  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   mod(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __mod__¬  s    c         C` s   t  t j | |   S(   N(   R:  Rq   R©  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rmod__Æ  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   R   (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __mul__²  s    c         C` s   t  t j | |   S(   N(   R:  Rq   R   (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rmul__µ  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   ne(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __ne__ø  s    c         C` s   t  t j |   S(   N(   R:  Rq   t   neg(   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __neg__»  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   or_(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __or__¾  s    c         C` s   |  S(   N(    (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __pos__Į  s    c         C` s   t  t j | |   S(   N(   R:  Rq   R²  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __ror__Ä  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   pow(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __pow__Ē  s    c         C` s   t  t j | |   S(   N(   R:  Rq   R¶  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rpow__Ź  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   rshift(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt
   __rshift__Ķ  s    c         C` s   t  t j | |   S(   N(   R:  Rq   R¹  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rrshift__Š  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   sub(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __sub__Ó  s    c         C` s   t  t j | |   S(   N(   R:  Rq   R¼  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rsub__Ö  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   truediv(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __truediv__Ł  s    c         C` s   t  t j | |   S(   N(   R:  Rq   Ræ  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rtruediv__Ü  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   floordiv(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __floordiv__ß  s    c         C` s   t  t j | |   S(   N(   R:  Rq   RĀ  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rfloordiv__ā  s    c         C` s   t  t j |  |  S(   N(   R:  Rq   t   xor(   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __xor__å  s    c         C` s   t  t j | |   S(   N(   R:  Rq   RÅ  (   R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rxor__č  s    c         C` s   d d l  m } | |  |  S(   Ni   (   R/  (   R5  R/  (   R  R  R/  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt
   __matmul__ė  s    c         C` s   d d l  m } | | |   S(   Ni   (   R/  (   R5  R/  (   R  R  R/  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __rmatmul__ļ  s    c      
   C` s2   d d l  m } | |  d | d | d | d | S(   Ni   (   RS   R   t   keepdimsR  R¼   (   R  RS   (   R  R   RŹ  R  R¼   RS   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRS   ó  s    c      
   C` s2   d d l  m } | |  d | d | d | d | S(   Ni   (   R   R   RŹ  R  R¼   (   R  R   (   R  R   RŹ  R  R¼   R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR   ł  s    c      
   C` s2   d d l  m } | |  d | d | d | d | S(   Ni   (   t   minR   RŹ  R  R¼   (   R  RĖ  (   R  R   RŹ  R  R¼   RĖ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRĖ  ’  s    c      
   C` s2   d d l  m } | |  d | d | d | d | S(   Ni   (   R   R   RŹ  R  R¼   (   R  R   (   R  R   RŹ  R  R¼   R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR     s    c         C` s,   d d l  m } | |  d | d | d | S(   Ni   (   t   argminR   R  R¼   (   R  RĢ  (   R  R   R  R¼   RĢ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRĢ    s    c         C` s,   d d l  m } | |  d | d | d | S(   Ni   (   t   argmaxR   R  R¼   (   R  RĶ  (   R  R   R  R¼   RĶ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRĶ    s    c         C` s8   d d l  m } | |  d | d | d | d | d | S(   Ni   (   Ry   R   Rm   RŹ  R  R¼   (   R  Ry   (   R  R   Rm   RŹ  R  R¼   Ry   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRy     s    i    i   c      
   C` s2   d d l  m } | |  d | d | d | d | S(   Ni   (   t   tracet   offsett   axis1t   axis2Rm   (   R  RĪ  (   R  RĻ  RŠ  RŃ  Rm   RĪ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRĪ    s    c         C` s8   d d l  m } | |  d | d | d | d | d | S(   Ni   (   t   prodR   Rm   RŹ  R  R¼   (   R  RŅ  (   R  R   Rm   RŹ  R  R¼   RŅ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRŅ  !  s    c         C` s8   d d l  m } | |  d | d | d | d | d | S(   Ni   (   t   meanR   Rm   RŹ  R  R¼   (   R  RÓ  (   R  R   Rm   RŹ  R  R¼   RÓ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRÓ  (  s    c         C` s>   d d l  m } | |  d | d | d | d | d | d | S(	   Ni   (   t   stdR   Rm   RŹ  t   ddofR  R¼   (   R  RŌ  (   R  R   Rm   RŹ  RÕ  R  R¼   RŌ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRŌ  /  s    !c         C` s>   d d l  m } | |  d | d | d | d | d | d | S(	   Ni   (   t   varR   Rm   RŹ  RÕ  R  R¼   (   R  RÖ  (   R  R   Rm   RŹ  RÕ  R  R¼   RÖ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRÖ  6  s    !c   	      C` sA   d d l  m } | |  | d | d | d | d | d | d | S(	   sB  Calculate the nth centralized moment.

        Parameters
        ----------
        order : int
            Order of the moment that is returned, must be >= 2.
        axis : int, optional
            Axis along which the central moment is computed. The default is to
            compute the moment of the flattened array.
        dtype : data-type, optional
            Type to use in computing the moment. For arrays of integer type the
            default is float64; for arrays of float types it is the same as the
            array type.
        keepdims : bool, optional
            If this is set to True, the axes which are reduced are left in the
            result as dimensions with size one. With this option, the result
            will broadcast correctly against the original array.
        ddof : int, optional
            "Delta Degrees of Freedom": the divisor used in the calculation is
            N - ddof, where N represents the number of elements. By default
            ddof is zero.

        Returns
        -------
        moment : ndarray

        References
        ----------
        .. [1] Pebay, Philippe (2008), "Formulas for Robust, One-Pass Parallel
        Computation of Covariances and Arbitrary-Order Statistical Moments"
        (PDF), Technical Report SAND2008-6212, Sandia National Laboratories

        i   (   t   momentR   Rm   RŹ  RÕ  R  R¼   (   R  R×  (	   R  t   orderR   Rm   RŹ  RÕ  R  R¼   R×  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR×  =  s    $c         O` s   t  | |  | |  S(   N(   Rµ   (   R  R   R   R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRµ   e  s    c         K` s)   d d l  m } | |  | | | | |  S(   sź   Map a function over blocks of the array with some overlap

        We share neighboring zones between blocks of the array, then map a
        function, then trim away the neighboring strips.

        Parameters
        ----------
        func: function
            The function to apply to each extended block
        depth: int, tuple, or dict
            The number of elements that each block should share with its neighbors
            If a tuple or dict then this can be different per axis
        boundary: str, tuple, dict
            How to handle the boundaries.
            Values include 'reflect', 'periodic', 'nearest', 'none',
            or any constant value like 0 or np.nan
        trim: bool
            Whether or not to trim ``depth`` elements from each block after
            calling the map function.
            Set this to False if your mapping function already does this for you
        **kwargs:
            Other keyword arguments valid in ``map_blocks``

        Examples
        --------
        >>> x = np.array([1, 1, 2, 3, 3, 3, 2, 1, 1])
        >>> x = from_array(x, chunks=5)
        >>> def derivative(x):
        ...     return x - np.roll(x, 1)

        >>> y = x.map_overlap(derivative, depth=1, boundary=0)
        >>> y.compute()
        array([ 1,  0,  1,  1,  0,  0, -1, -1,  0])

        >>> import dask.array as da
        >>> x = np.arange(16).reshape((4, 4))
        >>> d = da.from_array(x, chunks=(2, 2))
        >>> d.map_overlap(lambda x: x + x.size, depth=1).compute()
        array([[16, 17, 18, 19],
               [20, 21, 22, 23],
               [24, 25, 26, 27],
               [28, 29, 30, 31]])

        >>> func = lambda x: x + x.size
        >>> depth = {0: 1, 1: 1}
        >>> boundary = {0: 'reflect', 1: 'none'}
        >>> d.map_overlap(func, depth, boundary).compute()  # doctest: +NORMALIZE_WHITESPACE
        array([[12,  13,  14,  15],
               [16,  17,  18,  19],
               [20,  21,  22,  23],
               [24,  25,  26,  27]])
        i   (   t   map_overlap(   t   overlapRŁ  (   R  R   t   deptht   boundaryt   trimR   RŁ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRŁ  i  s    5c         C` s&   d d l  m } | |  | | d | S(   s    See da.cumsum for docstring i   (   RĻ   R¼   (   R  RĻ   (   R  R   Rm   R¼   RĻ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRĻ   ”  s    c         C` s&   d d l  m } | |  | | d | S(   s    See da.cumprod for docstring i   (   t   cumprodR¼   (   R  RŽ  (   R  R   Rm   R¼   RŽ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRŽ  ¦  s    c         C` s   d d l  m } | |  |  S(   Ni   (   t   squeeze(   R5  Rß  (   R  R   Rß  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRß  «  s    c         C` s#   d d l  m } | |  | | |  S(   s    See da.rechunk for docstring i   (   t   rechunk(   R   Rą  (   R  Re   t	   thresholdt   block_size_limitRą  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRą  °  s    c         C` s   d d l  m } | |   S(   Ni   (   t   real(   R1  Rć  (   R  Rć  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRć  µ  s    c         C` s   d d l  m } | |   S(   Ni   (   t   imag(   R1  Rä  (   R  Rä  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRä  ŗ  s    c         C` s   d d l  m } | |   S(   Ni   (   t   conj(   R1  Rå  (   R  Rå  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRå  æ  s    c         C` s    d d l  m } | |  | |  S(   Ni   (   t   clip(   R1  Rę  (   R  RĖ  R   Rę  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRę  Ć  s    t   Cc      	   ` sÓ   t  j |  } |  j j | j   | d k rb |  j d  t   f d   |  j d D  f } nL | d k r¢ t   f d   |  j d D  f |  j d } n t d   |  j t j | d	 | d
 | d | S(   sŠ   Get a view of the array as a new data type

        Parameters
        ----------
        dtype:
            The dtype by which to view the array
        order: string
            'C' or 'F' (Fortran) ordering

        This reinterprets the bytes of the array under a new dtype.  If that
        dtype does not have the same size as the original array then the shape
        will change.

        Beware that both numpy and dask.array can behave oddly when taking
        shape-changing views of arrays under Fortran ordering.  Under some
        versions of NumPy this function will fail when taking shape-changing
        views of Fortran ordered arrays if the first dimension has chunks of
        size one.
        Rē  i’’’’c         3` s   |  ] } t  |    Vq d  S(   N(   t
   ensure_int(   RL   R\   (   t   mult(    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ą  s   t   Fc         3` s   |  ] } t  |    Vq d  S(   N(   Rč  (   RL   R\   (   Ré  (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ć  s    i    i   s   Order must be one of 'C' or 'F'RŲ  Rm   Re   (	   RV   Rm   RD  Re   RR   R   Rµ   R   t   view(   R  Rm   RŲ  Re   (    (   Ré  s.   lib/python2.7/site-packages/dask/array/core.pyRė  Č  s    #c         C` s    d d l  m } | |  | |  S(   Ni   (   t   swapaxes(   R5  Rģ  (   R  RŠ  RŃ  Rģ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRģ  ė  s    c         C` s    d d l  m } | |  d | S(   Ni   (   t   roundt   decimals(   R5  Rķ  (   R  Rī  Rķ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRķ  š  s    c         C` sB   |  j  d k r |  j t j  St |  j |  j |  j |  j  Sd S(   sS   
        Copy array.  This is a no-op for dask.arrays, which are immutable
        i   N(	   R'  Rµ   R-   RŹ   R   RĒ   R­   Re   Rm   (   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRŹ   õ  s    c         C` s    |  j    } | | t |   <| S(   N(   RŹ   t   id(   R  t   memoR\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   __deepcopy__ž  s    c         ` s   |  j    } |  j     | rX |  j   |    d |  j } t j |   d d   n  t |  j   f d   |  } t j	 | d t
 S(   sO  Convert into an array of ``dask.delayed`` objects, one per chunk.

        Parameters
        ----------
        optimize_graph : bool, optional
            If True [default], the graph is optimized before converting into
            ``dask.delayed`` objects.

        See Also
        --------
        dask.array.from_delayed
        s   delayed-R  c         ` s   t  |     S(   N(   R6   (   RÖ   (   Rt  (    s.   lib/python2.7/site-packages/dask/array/core.pyR     R   Rm   (    (   Rī   Rė   Rģ   R­   R:   R  R!   R   RV   RC   R|  (   R  t   optimize_graphRu   R­   t   L(    (   Rt  s.   lib/python2.7/site-packages/dask/array/core.pyt
   to_delayed  s    c         C` s#   d d l  m } | |  | d | S(   Ni   (   t   repeatR   (   t   creationRõ  (   R  t   repeatsR   Rõ  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRõ    s    c         C` s   d d l  m } | |   S(   Ni   (   t   nonzero(   R5  Rų  (   R  Rų  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRų    s    c         O` s   t  |  | |  S(   s©   Save array to the zarr storage format

        See https://zarr.readthedocs.io for details about the format.

        See function ``to_zarr()`` for parameters.
        (   t   to_zarr(   R  R   R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRł  #  s    c         O` s#   d d l  m } | |  | | |  S(   sĄ   Save array to the TileDB storage manager

        See function ``to_tiledb()`` for argument documentation.

        See https://docs.tiledb.io for details about the format and engine.
        i   (   t	   to_tiledb(   t	   tiledb_ioRś  (   R  t   uriR   R   Rś  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRś  ,  s    (   RĒ   R  R  RĪ   Rm   N(   RH   RI   RJ   t	   __slots__RK   R  R  Rė   R   Rī   R"  R    R_   R   Rģ   t   staticmethodR7   R  t   __dask_scheduler__R%  R&  t   propertyRĢ   R'  Rk   R(  R*  R+  R,  Re   R-  R?  RB  R   RC  RE  RD  R­   t   setterR   RH  RQ  RR  R   R  RT  R[  R^  t   __nonzero__R`  Ra  t   __long__Rc  Re  Rj  Ru  Rx  Ry  R~  R  R'   RV   R3  Rz   R{   R  R  R  Rķ   R  R  R  R  RG  R  R  R  R  R  R  R  R  R  R  R”  R£  R¤  R¦  RØ  RŖ  R«  R¬  R­  RÆ  R±  R³  R“  Rµ  R·  Rø  Rŗ  R»  R½  R¾  RĄ  RĮ  RĆ  RÄ  RĘ  RĒ  RČ  RÉ  RĘ   RS   R   RĖ  R   RĢ  RĶ  Ry   RĪ  RŅ  RÓ  RŌ  RÖ  R×  Rµ   RÅ   RŁ  RĻ   RŽ  Rß  Rą  Rć  Rä  Rå  Rę  Rė  Rģ  Rķ  RŹ   Rń  Rō  Rõ  Rų  Rł  Rś  (    (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR   K  s4  												$											+		"		'																																						'8	#					c         C` s/   t  |   } | |  k r+ t d |    n  | S(   Ns   Could not coerce %f to integer(   R  R   (   t   fR¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRč  7  s    c         ` sÅ  | r+ t  | t j  r+ t j |  } n    d k rF t t   n  t    t  rd t      n  t    t t	 f  r   f t
 |    n  t    t  rÉ t   f d   t t
 |   D    n  t    t j  rź   j     n    r | r t d   | D  r d t
 |    n  | rlt
 |  d k rlt
    d k rlt d     D  rl  f   n  | r£t
    t
 |  k r£t d   | f   n  d   k s»d   k rŻt d   t   |  D    n  xr   D]j } t  | t	  rä| d	 k rät |  } | d k r&| } qN| | k rNt d
 | | f   qNqäqäWt d     D    t d     D  rt   | | | |    n  | d k	 rĒt d   t   |  D    n    rž| d k	 ržt d   t |    D d    n  x#   D] } | st d   qqW| d k	 r±t
    t
 |  k rmt d t
 |  t
    f   n  t d   t t t    |  D  s±t d   | f   q±n  t d     D  S(   s	   Normalize chunks to tuple of tuples

    This takes in a variety of input types and information and produces a full
    tuple-of-tuples result for chunks, suitable to be passed to Array or
    rechunk or any other operation that creates a Dask array.

    Parameters
    ----------
    chunks: tuple, int, dict, or string
        The chunks to be normalized.  See examples below for more details
    shape: Tuple[int]
        The shape of the array
    limit: int (optional)
        The maximum block size to target in bytes,
        if freedom is given to choose
    dtype: np.dtype
    previous_chunks: Tuple[Tuple[int]] optional
        Chunks from a previous array that we should use for inspiration when
        rechunking auto dimensions.  If not provided but auto-chunking exists
        then auto-dimensions will prefer square-like chunk shapes.

    Examples
    --------
    Specify uniform chunk sizes

    >>> normalize_chunks((2, 2), shape=(5, 6))
    ((2, 2, 1), (2, 2, 2))

    Also passes through fully explicit tuple-of-tuples

    >>> normalize_chunks(((2, 2, 1), (2, 2, 2)), shape=(5, 6))
    ((2, 2, 1), (2, 2, 2))

    Cleans up lists to tuples

    >>> normalize_chunks([[2, 2], [3, 3]])
    ((2, 2), (3, 3))

    Expands integer inputs 10 -> (10, 10)

    >>> normalize_chunks(10, shape=(30, 5))
    ((10, 10, 10), (5,))

    Expands dict inputs

    >>> normalize_chunks({0: 2, 1: 3}, shape=(6, 6))
    ((2, 2, 2), (3, 3))

    The values -1 and None get mapped to full size

    >>> normalize_chunks((5, -1), shape=(10, 10))
    ((5, 5), (10,))

    Use the value "auto" to automatically determine chunk sizes along certain
    dimensions.  This uses the ``limit=`` and ``dtype=`` keywords to
    determine how large to make the chunks.  The term "auto" can be used
    anywhere an integer can be used.  See array chunking documentation for more
    information.

    >>> normalize_chunks(("auto",), shape=(20,), limit=5, dtype='uint8')
    ((5, 5, 5, 5),)

    You can also use byte sizes (see ``dask.utils.parse_bytes``) in place of
    "auto" to ask for a particular size

    >>> normalize_chunks("1kiB", shape=(2000,), dtype='float32')
    ((250, 250, 250, 250, 250, 250, 250, 250),)

    Respects null dimensions

    >>> normalize_chunks((), shape=(0, 0))
    ((0,), (0,))
    c         3` s!   |  ] }   j  | d   Vq d  S(   N(   R  RK   (   RL   R¶   (   Re   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    c         s` s   |  ] } | d  k Vq d S(   i    N(    (   RL   Ra   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    i    i   c         s` s$   |  ] } t  | t t f  Vq d  S(   N(   RN   R   R©   (   RL   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    sN   Chunks and shape must be of the same length/dimension. Got chunks=%s, shape=%si’’’’c         s` s9   |  ]/ \ } } | d  k s' | d k r- | n | Vq d S(   i’’’’N(   RK   (   RL   R\   Ra   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>”  s    t   autosD   Only one consistent value of limit or chunk is allowed.Used %s != %sc         s` s6   |  ], } t  | t  r* | d  k r* d  n | Vq d S(   R  N(   RN   R©   (   RL   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>Æ  s    c         s` s   |  ] } | d  k Vq d S(   R  N(    (   RL   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>±  s    c         s` s3   |  ]) \ } } | d d  h k r' | n | Vq d S(   i’’’’N(   RK   (   RL   R\   Ra   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>µ  s   c         s` sH   |  ]> \ } } t  | t t f  s9 t | f | f  n | f Vq d  S(   N(   RN   RR   Rc   R  (   RL   Ra   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>¹  s   sZ   Empty tuples are not allowed in chunks. Express zero length dimensions with 0(s) in chunkssL   Input array has %d dimensions but the supplied chunks has only %d dimensionsc         s` s?   |  ]5 \ } } | | k p6 t  j |  p6 t  j |  Vq d  S(   N(   t   mathR
  (   RL   R\   Ra   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>Ę  s   s6   Chunks do not add up to shape. Got chunks=%s, shape=%sc         s` s%   |  ] } t  d    | D  Vq d S(   c         s` s0   |  ]& } t  j |  s$ t |  n | Vq d  S(   N(   R  R
  R  (   RL   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>Ė  s    N(   RR   (   RL   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>Ė  s    N(   i    (   (   i    (    (   RN   RV   Rm   RK   R   R  Rc   RR   R   R©   Rp   Rr   Ro   R3  Rz  R   Rd   R+   RS   t   auto_chunksRy   R   (   Re   Rk   t   limitRm   t   previous_chunksR\   t   parsed(    (   Re   s.   lib/python2.7/site-packages/dask/array/core.pyRn   >  sj    K+#*"				c         ` sN    d k	 r% t d     D    n  t |   }  d   t |   D } | sW t |   S| d k ru t j d  } n  t | t  r t |  } n  | d k r® t	 d   n  | j
 rĘ t d   n  xo t |   t |  D]W } t | t  rt j |  s%t | t  rŻ t j |  j   rŻ t d   qŻ qŻ Wt d |  } t j g  |  D]3 } | d k rTt | t  r{| n	 t |  ^ qT }   r  f d	   | D }	 g  }
 x t |  D] \ } } t   |  } t | j   d
 d   \ } } | d k r2| t   |  d k r2|
 j |  qæ|
 j |  qæW| | j | t j t |	 j     } d } t   } xå | | k s| | k rc| } t |  } x t |  D]| } |	 | | d t |  } | | | k r| j |  | | | 9} | | |  | <|	 | =q¶t | |
 |  |	 | <q¶W| | j | t j t |	 j     } qWx$ |	 j   D] \ } } | |  | <qqWt |   S| | j | d t |  } g  | D] } | | | k  r»| ^ q»} | rx | D] } | | f |  | <qźWt |  | | |  Sx% | D] } t | | |  |  | <qWt |   Sd S(   se   Determine automatic chunks

    This takes in a chunks value that contains ``"auto"`` values in certain
    dimensions and replaces those values with concrete dimension sizes that try
    to get chunks to be of a certain size in bytes, provided by the ``limit=``
    keyword.  If multiple dimensions are marked as ``"auto"`` then they will
    all respond to meet the desired byte limit, trying to respect the aspect
    ratio of their dimensions in ``previous_chunks=``, if given.

    Parameters
    ----------
    chunks: Tuple
        A tuple of either dimensions or tuples of explicit chunk dimensions
        Some entries should be "auto"
    shape: Tuple[int]
    limit: int, str
        The maximum allowable size of a chunk in bytes
    previous_chunks: Tuple[Tuple[int]]

    See also
    --------
    normalize_chunks: for full docstring and parameters
    c         s` s-   |  ]# } t  | t  r | n | f Vq d  S(   N(   RN   RR   (   RL   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ē  s   c         S` s(   h  |  ] \ } } | d  k r |  q S(   R  (    (   RL   R¶   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <setcomp>ė  s   	 s   array.chunk-sizes%   DType must be known for auto-chunkingsi   Can not use auto rechunking with object dtype. We are unable to estimate the size in bytes of object datasC   Can not perform automatic rechunking with unknown (nan) chunk sizesi   R  c         ` s&   i  |  ] } t  j   |  |  q S(    (   RV   t   median(   RL   RX   (   R	  (    s.   lib/python2.7/site-packages/dask/array/core.pys
   <dictcomp>	  s   	 R   c         S` s   |  d S(   Ni   (    (   t   kv(    (    s.   lib/python2.7/site-packages/dask/array/core.pyR     R   i   i    N(   RK   RR   Rc   RĀ   R   R  RN   R©   R+   R¾   t	   hasobjectRg  R   RV   R
  RS   R   R   RŅ  R   RÉ   Rp   RĶ   RD  Rw   Rį   RĆ   t   removet   round_toR  (   Re   Rk   R  Rm   R	  t   autosRM   t   cst   largest_blockRä   t   ideal_shapeR¶   Ra   t   chunk_frequenciest   modet   countt
   multipliert   last_multipliert
   last_autosRX   t   proposedRÖ   RŲ   RC  t   small(    (   R	  s.   lib/python2.7/site-packages/dask/array/core.pyR  Ī  sx    	
	$	@!&*	
.
)c         ` sg     | k rW y$ t    f d   t |  D  SWqc t k
 rS t  d t     SXn   | | Sd S(   sų   Return a chunk dimension that is close to an even multiple or factor

    We want values for c that are nicely aligned with s.

    If c is smaller than s then we want the largest factor of s that is less than the
    desired chunk size, but not less than half, which is too much.  If no such
    factor exists then we just go with the original chunk size and accept an
    uneven chunk at the end.

    If c is larger than s then we want the largest multiple of s that is still
    smaller than c.
    c         3` s5   |  ]+ }   d  | k o$   k n r | Vq d S(   i   N(    (   RL   R  (   R\   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>M  s    i   N(   R   R*   R   R  (   R\   Ra   (    (   R\   s.   lib/python2.7/site-packages/dask/array/core.pyR  >  s    $R  c         C` sŚ  t  |  t t t f t j  r1 t j |   }  n  t |  d d  } t	 | |  j
 d |  j d | } | d t f k r¢ t |  |  } d | }	 | p d | } n/ | t k rĖ d t t j    }	 } n | }	 | t k ré t   } n  t |   t j k r2t d   | D  r2i |  | f d |  j 6}
 n | d k r~t |   t j k rf| rft j } q~| rut } q~t } n  t |	 | d | d	 |  j
 d
 | d | d | d |  j }
 |  |
 |	 <t |
 | | d |  j S(   sĢ	   Create dask array from something that looks like an array

    Input must have a ``.shape`` and support numpy-style slicing.

    Parameters
    ----------
    x : array_like
    chunks : int, tuple
        How to chunk the array. Must be one of the following forms:
        -   A blocksize like 1000.
        -   A blockshape like (1000, 1000).
        -   Explicit sizes of all blocks along all dimensions like
            ((1000, 1000, 500), (400, 400)).
        -   A size in bytes, like "100 MiB" which will choose a uniform
            block-like shape
        -   The word "auto" which acts like the above, but uses a configuration
            value ``array.chunk-size`` for the chunk size

        -1 or None as a blocksize indicate the size of the corresponding
        dimension.
    name : str, optional
        The key name to use for the array. Defaults to a hash of ``x``.
        By default, hash uses python's standard sha1. This behaviour can be
        changed by installing cityhash, xxhash or murmurhash. If installed,
        a large-factor speedup can be obtained in the tokenisation step.
        Use ``name=False`` to generate a random name instead of hashing (fast)
    lock : bool or Lock, optional
        If ``x`` doesn't support concurrent reads then provide a lock here, or
        pass in True to have dask.array create one for you.
    asarray : bool, optional
        If True (default), then chunks will be converted to instances of
        ``ndarray``. Set to False to pass passed chunks through unchanged.
    fancy : bool, optional
        If ``x`` doesn't support fancy indexing (e.g. indexing with lists or
        arrays) then set to False. Default is True.

    Examples
    --------

    >>> x = h5py.File('...')['/data/path']  # doctest: +SKIP
    >>> a = da.from_array(x, chunks=(1000, 1000))  # doctest: +SKIP

    If your underlying datastore does not support concurrent reads then include
    the ``lock=True`` keyword argument or ``lock=mylock`` if you want multiple
    arrays to coordinate around the same lock.

    >>> a = da.from_array(x, chunks=(1000, 1000), lock=True)  # doctest: +SKIP

    If your underlying datastore has a ``.chunks`` attribute (as h5py and zarr
    datasets do) then a multiple of that chunk shape will be used if you
    do not provide a chunk shape.

    >>> a = da.from_array(x, chunks='auto')  # doctest: +SKIP
    >>> a = da.from_array(x, chunks='100 MiB')  # doctest: +SKIP
    >>> a = da.from_array(x)  # doctest: +SKIP
    Re   Rm   R	  s   array-original-s   array-c         s` s!   |  ] } t  |  d  k Vq d S(   i   N(   Rp   (   RL   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>¦  s    i    R
   Rk   Rt   RQ   RP   N(   i    (   RN   Rc   RR   t
   memoryviewRV   t
   ScalarTypeRC   R8  RK   Rn   Rk   Rm   RÅ   R   RĘ   R©   Rš   Rń   R(   R   R3  R   R   Rq   R
   RT   R]   Rx   R   (   RM   Re   R­   RQ   RP   t   fancyR
   R	  R®   t   original_nameRĖ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt
   from_arrayT  s<    :			
+		
c         K` s)  d d l  } | p i  } t |  | j  r3 |  } n t |  t  r¬ t |  d d | \ } }	 }
 t |
  d k sx t  t | |
 d  } | j | d t d | | } n$ |  } | j | d t d | | } | d k	 rā | n | j
 } | d k rd t | | | | |  } n  t | | d	 | S(
   s+  Load array from the zarr storage format

    See https://zarr.readthedocs.io for details about the format.

    Parameters
    ----------
    url: Zarr Array or str or MutableMapping
        Location of the data. A URL can include a protocol specifier like s3://
        for remote data. Can also be any MutableMapping instance, which should
        be serializable if used in multiple processes.
    component: str or None
        If the location is a zarr group rather than an array, this is the
        subcomponent that should be loaded, something like ``'foo/bar'``.
    storage_options: dict
        Any additional parameters for the storage backend (ignored for local
        paths)
    chunks: tuple of ints or tuples of ints
        Passed to ``da.from_array``, allows setting the chunks on
        initialisation, if the chunking scheme in the on-disc dataset is not
        optimal for the calculations to follow.
    name : str, optional
         An optional keyname for the array.  Defaults to hashing the input
    kwargs: passed to ``zarr.Array``.
    i    Nt   rbt   storage_optionsi   t	   read_onlyt   paths
   from-zarr-R­   (   t   zarrRN   R   R©   R<   Rp   R  R;   RÅ   RK   Re   R   R   (   t   urlt	   componentR"  Re   R­   R   R%  t   zt   fst   fs_tokenR$  t   mapper(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt	   from_zarr»  s     	!c         K` s  d d l  } t | | j  r | }	 t |	 j t | j f  rf d t j d d  k rf t d   n  |  j	 |	 j
  }  |  j |	 d t d | d	 | St |  j
  sµ t d
   n  | p¾ i  } t | t  rt | d d | \ }
 } } t |  d k st  t |
 | d  } n | } g  |  j
 D] } | d ^ q,} | j d |  j d | d |  j d | d | d | |  }	 |  j |	 d t d | d	 | S(   sē  Save array to the zarr storage format

    See https://zarr.readthedocs.io for details about the format.

    Parameters
    ----------
    arr: dask.array
        Data to store
    url: Zarr Array or str or MutableMapping
        Location of the data. A URL can include a protocol specifier like s3://
        for remote data. Can also be any MutableMapping instance, which should
        be serializable if used in multiple processes.
    component: str or None
        If the location is a zarr group rather than an array, this is the
        subcomponent that should be created/over-written.
    storage_options: dict
        Any additional parameters for the storage backend (ignored for local
        paths)
    overwrite: bool
        If given array already exists, overwrite=False will cause an error,
        where overwrite=True will replace the existing data.
    compute, return_stored: see ``store()``
    kwargs: passed to the ``zarr.create()`` function, e.g., compression options
    i    Nt   distributedt	   schedulerR   sG   Cannot store into in memory Zarr Array using the Distributed Scheduler.RQ   Rō   Rų   s\   Attempt to save array to zarr with irregular chunking, please call `arr.rechunk(...)` first.R!  R"  i   Rk   Re   Rm   R  R$  t	   overwrite(   R%  RN   R   R  Rr   t	   DictStoreR   R  t   RuntimeErrorRą  Re   RĘ   t   _check_regular_chunksR   R©   R<   Rp   R  R;   t   createRk   Rm   (   Rs   R&  R'  R"  R/  Rō   Rų   R   R%  R(  R)  R*  R$  R+  R\   Re   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRł  ē  s.     !c         C` se   x^ |  D]V } t  |  d k r% q n  t  t | d    d k rE t S| d | d k r t Sq Wt S(   sÖ  Check if the chunks are regular

    "Regular" in this context means that along every axis, the chunks all
    have the same size, except the last one, which may be smaller

    Parameters
    ----------
    chunkset: tuple of tuples of ints
        From the ``.chunks`` attribute of an ``Array``

    Returns
    -------
    True if chunkset passes, else False

    Examples
    --------
    >>> import dask.array as da
    >>> arr = da.zeros(10, chunks=(5, ))
    >>> _check_regular_chunks(arr.chunks)
    True

    >>> arr = da.zeros(10, chunks=((3, 3, 3, 1), ))
    >>> _check_regular_chunks(arr.chunks)
    True

    >>> arr = da.zeros(10, chunks=((3, 1, 3, 3), ))
    >>> _check_regular_chunks(arr.chunks)
    False
    i   i’’’’i    (   Rp   Rį   RĘ   RÅ   (   t   chunksetRe   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR2  #	  s    c   	      C` sÅ   d d l  m } m } t |  |  rD t |  d  rD | |   }  n  | p] d t |  | |  } i |  j | f d t |  6} t d   | D  } t	 j
 | | d |  g } t | | | |  S(   s!   Create a dask array from a dask delayed value

    This routine is useful for constructing dask arrays in an ad-hoc fashion
    using dask delayed, particularly when combined with stack and concatenate.

    The dask array will consist of a single chunk.

    Examples
    --------
    >>> from dask import delayed
    >>> value = delayed(np.ones)(5)
    >>> array = from_delayed(value, (5,), float)
    >>> array
    dask.array<from-value, shape=(5,), dtype=float64, chunksize=(5,)>
    >>> array.compute()
    array([1., 1., 1., 1., 1.])
    i    (   R5   R6   R   s   from-value-c         s` s   |  ] } | f Vq d  S(   N(    (   RL   R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>b	  s    R  (   i    (   t   dask.delayedR5   R6   RN   RL  R   R   Rp   RR   R:   R  R   (	   Rh  Rk   Rm   R­   R5   R6   RĖ   Re   Rt  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   from_delayedK	  s    !c         C` s   | p d t  |  | | | |  } | s. | rC t |  | |  }  n  i |  f | f d t |  6} t d   | D  } t | | | |  S(   s;   Create dask array in a single block by calling a function

    Calling the provided function with func(*args, **kwargs) should return a
    NumPy array of the indicated shape and dtype.

    Examples
    --------

    >>> a = from_func(np.arange, (3,), dtype='i8', args=(3,))
    >>> a.compute()
    array([0, 1, 2])

    This works particularly well when coupled with dask.array functions like
    concatenate and stack:

    >>> arrays = [from_func(np.array, (), dtype='i8', args=(n,)) for n in range(5)]
    >>> stack(arrays).compute()
    array([0, 1, 2, 3, 4])
    s
   from_func-i    c         s` s   |  ] } | f Vq d  S(   N(    (   RL   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>	  s    (   i    (   R   R   Rp   RR   R   (   R   Rk   Rm   R­   R   R   RĖ   Re   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt	   from_funci	  s    "!c   
      C` s“  t  |   s d	 St g  |  D] } t |  d k r | ^ q  } t |  d k r] t |  St |  d k r t |  d t St j t t t |     rÆ t	 d |    n  t t t t |    d k rā t	 d |    n  g  | D] } t
 |  d d d  ^ qé } t t |   } d } g  } x{ | | k  r©t d   | D  } | j |  x; | D]3 }	 |	 d c | 8<|	 d d k re|	 j   qeqeW| | 7} q/Wt |  S(
   só   Find the common block dimensions from the list of block dimensions

    Currently only implements the simplest possible heuristic: the common
    block-dimension is the only one that does not span fully span a dimension.
    This is a conservative choice that allows us to avoid potentially very
    expensive rechunking.

    Assumes that each element of the input block dimensions has all the same
    sum (i.e., that they correspond to dimensions of the same size).

    Examples
    --------
    >>> common_blockdim([(3,), (2, 1)])
    (2, 1)
    >>> common_blockdim([(1, 2), (2, 1)])
    (1, 1, 1)
    >>> common_blockdim([(2, 2), (3, 1)])  # doctest: +SKIP
    Traceback (most recent call last):
        ...
    ValueError: Chunks do not align
    i   i    R   s"   Arrays chunk sizes are unknown: %ss"   Chunks do not add up to same valueNi’’’’c         s` s   |  ] } | d  Vq d S(   i’’’’N(    (   RL   R\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ŗ	  s    (    (   RS   Rį   Rp   R   R   RV   R
  Ry   R   R   Rc   RĖ  RĶ   Ræ   RR   (
   t	   blockdimsR  t   non_trivial_dimst   ntdt   rchunkst   totalR¶   R¼   t   mR\   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   common_blockdim	  s0    1
!,c          ` s  |  s i  g  f Sg  t  d |   D]0 \   } | d k	 rD t    n   | f ^ q  } t t |   }  | j d t  } t |   \   t d    D  r² i  t   f St  f d    D  rt  f d    D  rt	 t  d  d j
    f Sg  | D]- \   } | d k	 r6  j n   | f ^ q} d   | D } t | | d t  t d	   | D  } t j t t t  j      }	 | rä|	 rä|	 | d
 k rät j d |	 | t d d n  g   x | D] \   } | d k r j    qńt    f d   t |  D  }
 |
   j
 k rut   j
  ru j   j |
   qń j    qńW  f S(   s  
    Unify chunks across a sequence of arrays

    Parameters
    ----------
    *args: sequence of Array, index pairs
        Sequence like (x, 'ij', y, 'jk', z, 'i')

    Examples
    --------
    >>> import dask.array as da
    >>> x = da.ones(10, chunks=((5, 2, 3),))
    >>> y = da.ones(10, chunks=((2, 3, 5),))
    >>> chunkss, arrays = unify_chunks(x, 'i', y, 'i')
    >>> chunkss
    {'i': (2, 3, 2, 3)}

    >>> x = da.ones((100, 10), chunks=(20, 5))
    >>> y = da.ones((10, 100), chunks=(4, 50))
    >>> chunkss, arrays = unify_chunks(x, 'ij', y, 'jk', 'constant', None)
    >>> chunkss  # doctest: +SKIP
    {'k': (50, 50), 'i': (20, 20, 20, 20, 20), 'j': (4, 1, 3, 2)}

    >>> unify_chunks(0, None)
    ({}, [0])

    Returns
    -------
    chunkss : dict
        Map like {index: chunks}.
    arrays : list
        List of rechunked arrays.

    See Also
    --------
    common_blockdim
    i   RĮ   c         s` s   |  ] } | d  k Vq d  S(   N(   RK   (   RL   R!  (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ō	  s    c         3` s   |  ] } |   d  k Vq d S(   i    N(    (   RL   R!  (   t   inds(    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ö	  s    c         3` s%   |  ] } | j    d  j  k Vq d S(   i    N(   Re   (   RL   RX   (   R   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ö	  s    i    c         S` s1   i  |  ]' \ } } | d  k	 r | j | j  q S(   N(   RK   Re   R­   (   RL   RX   R!  (    (    s.   lib/python2.7/site-packages/dask/array/core.pys
   <dictcomp>ś	  s   		t   consolidatec         s` s*   |  ]  \ } } | d  k	 r | j Vq d  S(   N(   RK   R'  (   RL   RÜ   R!  (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr> 
  s    i
   s+   Increasing number of chunks by factor of %dt
   stackleveli   c         3` s^   |  ]T \ } }   j  | d  k r,  | n) t j t  |   sR   j  | n d Vq d S(   i   N(   Rk   RV   R
  Ry   RK   (   RL   RÕ   Rŗ   (   RX   Rā   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>
  s   N(   R   RK   t
   asanyarrayRc   R   R  RÅ   Rd   R   Rr   Re   R­   R   R>  R   RV   RŅ  R   Rp   Rw   RĄ   RĮ   RG   RĶ   RR   RĀ   Rą  (   R   R   R!  t   argindsRĮ   R¶   t   nameindst   blockdim_dictt	   max_partst   npartsRe   (    (   RX   R   Rā   R?  s.   lib/python2.7/site-packages/dask/array/core.pyt   unify_chunksÅ	  s>    &
C8$:
	$	c         C` sL   xE t  |  t t f  rG y |  d }  Wq t t t f k
 rC Pq Xq W|  S(   s   

    >>> unpack_singleton([[[[1]]]])
    1
    >>> unpack_singleton(np.array(np.datetime64('2000-01-01')))
    array('2000-01-01', dtype='datetime64[D]')
    i    (   RN   Rc   RR   Rw  R¾   t   KeyError(   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  
  s    	c         ` sĮ  d    d   } t  d d    } d } t } xÕ | j |   D]Ä \ } } } t |  t k r t d j | |     n  | s t |  }	 n. t |  d k r@ t |  d }	 t	 } n q@ | d k	 rž | |	 k rž t
 d j | |	 | |     n  |	 } q@ W| rt
 d	   n  | j |  d
 t d t }  | j |  d
 d   d t }
 t | |
    | } | j |  d
   f d   d t }  | j |  d   f d   d d   d | S(   s&  
    Assemble an nd-array from nested lists of blocks.

    Blocks in the innermost lists are concatenated along the last
    dimension (-1), then these are concatenated along the second-last
    dimension (-2), and so on until the outermost list is reached

    Blocks can be of any dimension, but will not be broadcasted using the normal
    rules. Instead, leading axes of size 1 are inserted, to make ``block.ndim``
    the same for all blocks. This is primarily useful for working with scalars,
    and means that code like ``block([v, 1])`` is valid, where
    ``v.ndim == 1``.

    When the nested list is two levels deep, this allows block matrices to be
    constructed from their components.

    Parameters
    ----------
    arrays : nested list of array_like or scalars (but not tuples)
        If passed a single ndarray or scalar (a nested list of depth 0), this
        is returned unmodified (and not copied).

        Elements shapes must match along the appropriate axes (without
        broadcasting), but leading 1s will be prepended to the shape as
        necessary to make the dimensions match.

    allow_unknown_chunksizes: bool
        Allow unknown chunksizes, such as come from converting from dask
        dataframes.  Dask.array is unable to verify that chunks line up.  If
        data comes from differently aligned sources then this can cause
        unexpected results.

    Returns
    -------
    block_array : ndarray
        The array assembled from the given blocks.

        The dimensionality of the output is equal to the greatest of:
        * the dimensionality of all the inputs
        * the depth to which the input list is nested

    Raises
    ------
    ValueError
        * If list depths are mismatched - for instance, ``[[a, b], c]`` is
          illegal, and should be spelt ``[[a, b], [c]]``
        * If lists are empty - for instance, ``[[a, b], []]``

    See Also
    --------
    concatenate : Join a sequence of arrays together.
    stack : Stack arrays in sequence along a new dimension.
    hstack : Stack arrays in sequence horizontally (column wise).
    vstack : Stack arrays in sequence vertically (row wise).
    dstack : Stack arrays in sequence depth wise (along third dimension).
    vsplit : Split array into a list of multiple sub-arrays vertically.

    Notes
    -----

    When called with only scalars, ``block`` is equivalent to an ndarray
    call. So ``block([[1, 2], [3, 4]])`` is equivalent to
    ``array([[1, 2], [3, 4]])``.

    This function does not enforce that the blocks lie on a fixed grid.
    ``block([[a, b], [c, d]])`` is not restricted to arrays of the form::

        AAAbb
        AAAbb
        cccDD

    But is also allowed to produce, for some ``a, b, c, d``::

        AAAbb
        AAAbb
        cDDDD

    Since concatenation happens along the last axis first, `block` is _not_
    capable of producing the following directly::

        AAAbb
        cccbb
        cccDD

    Matlab's "square bracket stacking", ``[A, B, ...; p, q, ...]``, is
    equivalent to ``block([[A, B, ...], [p, q, ...]])``.
    c         S` s5   t  |   }  t | |  j d  } |  d | t f S(   Ni    (   N(   RB  R   R   RK   t   Ellipsis(   RM   R   t   diff(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt
   atleast_nd
  s    c         S` s   d d j  d   |  D  S(   NR   R   c         s` s   |  ] } d  j  |  Vq d S(   s   [{}]N(   R   (   RL   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>
  s    (   R   (   RY  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   format_index
  s    t
   recurse_ifc         S` s   t  |   t k S(   N(   R   Rc   (   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR   
  R   s   {} is a tuple. Only lists can be used to arrange blocks, and np.block does not allow implicit conversion from tuple to ndarray.i    i   sc   List depths are mismatched. First element was at depth {}, but there is an element at depth {} ({})s   Lists cannot be emptyt   f_mapt   f_reducec         S` s   |  j  S(   N(   R   (   t   xi(    (    s.   lib/python2.7/site-packages/dask/array/core.pyR   æ
  R   c         ` s     |    S(   N(    (   RQ  (   RL  R   (    s.   lib/python2.7/site-packages/dask/array/core.pyR   Ź
  R   c         ` s   t  t |   d | d   S(   NR   t   allow_unknown_chunksizes(   RD   Rc   (   t   xsR   (   RR  (    s.   lib/python2.7/site-packages/dask/array/core.pyR   Ń
  s   t   f_kwargsc         S` s   t  d |  d  S(   NR   i   (   Rr   (   R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR   Ö
  R   R   N(   R=   RK   RĘ   t   walkR   RR   R¾   R   Rp   RÅ   R   t
   map_reduceRB  Rc   R   (   R   RR  RM  t   rect	   list_ndimt	   any_emptyRY  Rh  t   enteringt
   curr_deptht	   elem_ndimt
   first_axis(    (   RR  RL  R   s.   lib/python2.7/site-packages/dask/array/core.pyt   block&
  sX    ]			
			
		c      
   ` sŅ  t    } t   d j  }   d k  r8 |     n    | k rc d } t | |   f   n  | d k rw  d S| rt    f d   t |  D  rt t t j  d j   rć t d t	  d j    n  t d g   D] } | j ^ qš   n  g  t |  D] } t
 t |   ^ q} x) t |  D] \ } }	 | d |	   <qCWt
 t t  |    }
 t d t |
  \ }  g   D] } | j ^ q}  d j    t g  | D] } |   ^ qÉd  f  d j   d } d g t
 t t g   D] } t  | j    ^ q  } g   D] } | j ^ q?} t  t |   d k r£t t j |  } g   D] } | j |  ^ q n
 | d } g   D] } | j ^ q“} d t |    } t
 t | g g  | D] } t t  |   ^ qļ  } g  | D]o } | t | |   d  d f | d   d !|   d | t | |   d  d f |   d	 ^ q} t t | |   } t j | | d
  } t  | | | d | S(   są  
    Concatenate arrays along an existing axis

    Given a sequence of dask Arrays form a new dask Array by stacking them
    along an existing dimension (axis=0 by default)

    Parameters
    ----------
    seq: list of dask.arrays
    axis: int
        Dimension along which to align all of the arrays
    allow_unknown_chunksizes: bool
        Allow unknown chunksizes, such as come from converting from dask
        dataframes.  Dask.array is unable to verify that chunks line up.  If
        data comes from differently aligned sources then this can cause
        unexpected results.

    Examples
    --------

    Create slices

    >>> import dask.array as da
    >>> import numpy as np

    >>> data = [from_array(np.ones((4, 4)), chunks=(2, 2))
    ...          for i in range(3)]

    >>> x = da.concatenate(data, axis=0)
    >>> x.shape
    (12, 4)

    >>> da.concatenate(data, axis=1).shape
    (4, 12)

    Result is a new dask Array

    See Also
    --------
    stack
    i    sX   Axis must be less than than number of dimensions
Data has %d dimensions, but got axis=%di   c         3` s:   |  ]0      k p1 t     f d     D  Vq d S(   c         3` s-   |  ]# } | j     d  j    k Vq d S(   i    N(   Rk   (   RL   RM   (   R¶   t   seq(    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    N(   R   (   RL   (   R   R_  (   R¶   s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s   sn   Tried to concatenate arrays with unknown shape %s.  To force concatenation pass allow_unknown_chunksizes=True.s   Shapes do not align: %sRĮ   s   concatenate-i   R  Rm   (    (!   Rp   Rk   R   R   Ro   RS   R   RV   R
  R©   Rc   RĀ   R   Rd   RH  RĘ   Re   Ry   R   R	   Rm   Rį   R   t   promote_typesRG  R­   R   R   R   Rr   R:   R  R   (   R_  R   RR  RÕ   R   R§   RM   R¶   R?  R!  t   uc_argsR’   RX   Rf   R	  Re   t   cum_dimst
   seq_dtypesRr  t   namesR­   Ru   R   Rw   RĖ   Rt  (    (   R   R_  s.   lib/python2.7/site-packages/dask/array/core.pyRD   Ū
  sL    *(+5<%
7yc         C` s   d } | r | r | } n  | r/ | j   n  z? |  d k	 rT t j |   | | <n  | rm | rm | | } n  Wd | r | j   n  X| S(   sŃ  
    A function inserted in a Dask graph for storing a chunk.

    Parameters
    ----------
    x: array-like
        An array (potentially a NumPy one)
    out: array-like
        Where to store results too.
    index: slice-like
        Where to store result from ``x`` in ``out``.
    lock: Lock-like or False
        Lock to use before writing to ``out``.
    return_stored: bool
        Whether to return ``out``.
    load_stored: bool
        Whether to return the array stored in ``out``.
        Ignored if ``return_stored`` is not ``True``.

    Examples
    --------

    >>> a = np.ones((5, 6))
    >>> b = np.empty(a.shape)
    >>> load_store_chunk(a, b, (slice(None), slice(None)), False, False, False)
    N(   RK   RU   RV   RB  RW   (   RM   R¼   RY  RQ   Rų   Rž   Rä   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   load_store_chunk@  s    	c         C` s   t  |  | | | | t  S(   N(   Re  RĘ   (   RM   R¼   RY  RQ   Rų   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   store_chunkn  s    c         C` s   t  d  |  | | t t  S(   N(   Re  RK   RÅ   (   R¼   RY  RQ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt
   load_chunkr  s    c   
      ` sē    t  k r t    n  t |  j  } | rR g  | D] } t | |  ^ q4 } n  d | pj t t j     t  d    r¦ | r¦ d   t	    | f   n         f d   t
 t j |  j    |  D }	 |	 S(   s7  
    Creates a Dask graph for storing chunks from ``arr`` in ``out``.

    Parameters
    ----------
    arr: da.Array
        A dask array
    out: array-like
        Where to store results too.
    lock: Lock-like or bool, optional
        Whether to lock or with what (default is ``True``,
        which means a ``threading.Lock`` instance).
    region: slice-like, optional
        Where in ``out`` to store ``arr``'s results
        (default is ``None``, meaning all of ``out``).
    return_stored: bool, optional
        Whether to return ``out``
        (default is ``False``, meaning ``None`` is returned).
    load_stored: bool, optional
        Whether to handling loading from ``out`` at the same time.
        Ignored if ``return_stored`` is not ``True``.
        (default is ``False``, meaning defer to ``return_stored``).
    tok: str, optional
        Token to use when naming keys

    Examples
    --------
    >>> import dask.array as da
    >>> d = da.ones((5, 6), chunks=(2, 3))
    >>> a = np.empty(d.shape)
    >>> insert_to_ooc(d, a)  # doctest: +SKIP
    s   store-%ss   load-%sc         ` s@   i  |  ]6 \ } }  |  |   f    f | d   q S(   i   (    (   RL   Rč   t   slc(   R   R   RQ   R­   R¼   Rų   (    s.   lib/python2.7/site-packages/dask/array/core.pys
   <dictcomp>©  s   	(    (   RÅ   R   Rl   Re   R`   R©   Rš   Rń   Rf  Re  Rd   R8   Rķ   Rī   (
   Rs   R¼   RQ   t   regionRų   Rž   R  Rv   Rh  RĖ   (    (   R   R   RQ   R­   R¼   Rų   s.   lib/python2.7/site-packages/dask/array/core.pyRņ   v  s    #%
"c         ` s6     s d   |  D   n     f d   |  D } | S(   sM  
    Creates a Dask graph for loading stored ``keys`` from ``dsk``.

    Parameters
    ----------
    keys: Sequence
        A sequence containing Dask graph keys to load
    dsk_pre: Mapping
        A Dask graph corresponding to a Dask Array before computation
    dsk_post: Mapping, optional
        A Dask graph corresponding to a Dask Array after computation

    Examples
    --------
    >>> import dask.array as da
    >>> d = da.ones((5, 6), chunks=(2, 3))
    >>> a = np.empty(d.shape)
    >>> g = insert_to_ooc(d, a)
    >>> retrieve_from_ooc(g.keys(), g)  # doctest: +SKIP
    c         S` s   i  |  ] } | |  q S(    (    (   RL   RÖ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys
   <dictcomp>Ē  s   	 c         ` sE   i  |  ]; } t    | f  | d  d !d | d f | d  q S(   i   i’’’’s   load-i    i   (   Rg  (   RL   RÖ   (   t   dsk_postt   dsk_pre(    s.   lib/python2.7/site-packages/dask/array/core.pys
   <dictcomp>Ź  s   	(    (   Ru   Rk  Rj  t   load_dsk(    (   Rj  Rk  s.   lib/python2.7/site-packages/dask/array/core.pyRó   °  s
    
c         K` sÆ   t  |  t  r |  St |  d  r, |  j   St  |  t t f  rf t d   |  D  rf t |   }  n- t  t |  d d  t
  s t j |   }  n  t |  d |  j d t | S(   s7  Convert the input to a dask array.

    Parameters
    ----------
    a : array-like
        Input data, in any form that can be converted to a dask array.

    Returns
    -------
    out : dask array
        Dask array interpretation of a.

    Examples
    --------
    >>> import dask.array as da
    >>> import numpy as np
    >>> x = np.arange(3)
    >>> da.asarray(x)
    dask.array<array, shape=(3,), dtype=int64, chunksize=(3,)>

    >>> y = [[1, 2, 3], [4, 5, 6]]
    >>> da.asarray(y)
    dask.array<array, shape=(2, 3), dtype=int64, chunksize=(2, 3)>
    t   to_dask_arrayc         s` s   |  ] } t  | t  Vq d  S(   N(   RN   R   (   RL   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ī  s    Rk   Re   R
   N(   RN   R   RL  Rm  Rc   RR   RS   t   stackR8  RK   R1   RV   RP   R   Rk   R^   (   RX   R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRP   Ń  s    
+c         C` sę   t  |  t  r |  St |  d  r, |  j   St |  d  r` t |   j j d  r` t |  j  St  |  t	 t
 f  r t d   |  D  r t |   }  n- t  t |  d d	  t  sĒ t j |   }  n  t |  d |  j d t d t S(
   s  Convert the input to a dask array.

    Subclasses of ``np.ndarray`` will be passed through as chunks unchanged.

    Parameters
    ----------
    a : array-like
        Input data, in any form that can be converted to a dask array.

    Returns
    -------
    out : dask array
        Dask array interpretation of a.

    Examples
    --------
    >>> import dask.array as da
    >>> import numpy as np
    >>> x = np.arange(3)
    >>> da.asanyarray(x)
    dask.array<array, shape=(3,), dtype=int64, chunksize=(3,)>

    >>> y = [[1, 2, 3], [4, 5, 6]]
    >>> da.asanyarray(y)
    dask.array<array, shape=(2, 3), dtype=int64, chunksize=(2, 3)>
    Rm  t   datas   xarray.c         s` s   |  ] } t  | t  Vq d  S(   N(   RN   R   (   RL   R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    Rk   Re   R
   RP   N(   RN   R   RL  Rm  R   RI   t
   startswithRB  Ro  Rc   RR   RS   Rn  R8  RK   R1   RV   R   Rk   R^   RĘ   (   RX   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRB  õ  s    
'+c         C` s~   t  |  d d  } t | t  p5 t d   | D  } t j |   p} | p} t |  t j  p} t |  t j  o} |  j	 d k S(   s»  

    >>> is_scalar_for_elemwise(42)
    True
    >>> is_scalar_for_elemwise('foo')
    True
    >>> is_scalar_for_elemwise(True)
    True
    >>> is_scalar_for_elemwise(np.array(42))
    True
    >>> is_scalar_for_elemwise([1, 2, 3])
    True
    >>> is_scalar_for_elemwise(np.array([1, 2, 3]))
    False
    >>> is_scalar_for_elemwise(from_array(np.array(0), chunks=()))
    False
    >>> is_scalar_for_elemwise(np.dtype('i4'))
    True
    Rk   c         s` s   |  ] } t  |  Vq d  S(   N(   R   (   RL   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>6  s    i    N(
   R8  RK   RN   R1   RS   RV   t   isscalarRm   R3  R   (   RÜ   t   maybe_shapet   shape_condition(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   is_scalar_for_elemwise  s    c          ` sė   t  |   d k r |  d Sg  } xø t d d t t |    D] } t j |  j   rc t j   n! d | k ru d n t j |    t   f d   | D  rŹ t	 d j
 d j t t |       n  | j    q< Wt t |   S(   s2  
    Determines output shape from broadcasting arrays.

    Parameters
    ----------
    shapes : tuples
        The shapes of the arguments.

    Returns
    -------
    output_shape : tuple

    Raises
    ------
    ValueError
        If the input shapes cannot be successfully broadcast together.
    i   i    t	   fillvaluei’’’’c         3` s7   |  ]- } | d  d d   g k o. t  j |  Vq d S(   i’’’’i    i   N(   RV   R
  (   RL   R¶   (   Rb   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>X  s    s8   operands could not be broadcast together with shapes {0}t    (   Rp   R0   R   t   reversedRV   R
  RS   t   nanR   R   R   R   R©   RĶ   RR   (   Rh   R¼   t   sizes(    (   Rb   s.   lib/python2.7/site-packages/dask/array/core.pyt   broadcast_shapes>  s    "!	!c      	   O` sĖ  | j  d d  } t d d g  j |  sq d } t | |  j t t t |  t d d g    f   n  g  | D]0 } t | t	 t
 f  r¢ t j |  n | ^ qx } g  } xL | D]D } t | d d  } t d   | D  rņ d } n  | j |  q» Wg  | D]! }	 t |	 t  r%|	 n d ^ q
} t t |    }
 t
 t |
   d d d  } t } d | k r| d } n g  | D]@ } t |  sĀt j d t d	 | j  d | j n | ^ q} y t |  | i  d
 d t } Wn t k
 rt SXt d   | D  } | j d d  pId t |   t |  | |  f } t  d | d | d t |   j! d   } | r| | d <|  | d <t" }  n  t# |  | t$ d   | D  |  } t% | |  S(   sļ    Apply elementwise function across arguments

    Respects broadcasting rules

    Examples
    --------
    >>> elemwise(add, x, y)  # doctest: +SKIP
    >>> elemwise(sin, x)  # doctest: +SKIP

    See Also
    --------
    blockwise
    R¼   R­   Rm   s3   %s does not take the following keyword arguments %sRk   c         s` s   |  ] } t  |  Vq d  S(   N(   R   (   RL   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>w  s    Ni’’’’i   R:  R   c         s` s+   |  ]! } t  |  o" | j d  k Vq d S(   i    N(   Rt  R   (   RL   RX   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    s   %s-%sR®   R’   t   enforce_dtypet   enforce_dtype_functionc         s` sI   |  ]? } | t  |  s: t t | j  d  d  d   n d  f Vq d  S(   Ni’’’’(   Rt  RR   Ro   R   RK   (   RL   RX   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s   (    (    (    (   i   (&   Ræ   RK   Rį   t
   issupersetR¾   RH   R©   RĆ   RN   Rc   RR   RV   RP   R8  RS   RĶ   R1   Rp   Rz  Ro   RĘ   Rt  R)  R   R   Rm   RØ   R   R4  R  R&   R   Rr   t   stript   _enforce_dtypeRA   R   t
   handle_out(   t   opR   R   R¼   R§   RX   Rh   RÜ   Rk   Ra   t   out_ndimt	   expr_indst   need_enforce_dtypeRr  t   valsR­   t   blockwise_kwargsRä   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR:  _  sH    >=	.
J*

			
	c         C` s  t  |  t  rX t |   d k r. |  d }  qX t |   d k rO t d   qX d }  n  t  |  t  r× |  j | j k r¤ t d t |  j  t | j  f   n  | j	 |  _
 | j |  _ | j |  _ | j |  _ n2 |  d k	 rd t |   j } t |   n | Sd S(   s{    Handle out parameters

    If out is a dask.array then this overwrites the contents of that array with
    the result
    i   i    s(   The out parameter is not fully supportedsE   Mismatched shapes between result and out parameter. out=%s, result=%ssO   The out parameter is not fully supported. Received type %s, expected Dask ArrayN(   RN   RR   Rp   Rg  RK   R   Rk   R   R©   Re   RĪ   RĒ   Rm   R­   R   RH   (   R¼   Rä   R§   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  ¦  s(    	%c          O` s  | j  d  } | j  d  } | |  |   } t | d  r | | j k r | t k r t j | | d d s  t d t |  t |  t | j  f   n  t j	 |  rĮ | j
 |  } q y | j
 | d t } Wq t k
 rü | j
 |  } q Xn  | S(   s6  Calls a function and converts its result to the given dtype.

    The parameters have deliberately been given unwieldy names to avoid
    clashes with keyword arguments consumed by blockwise

    A dtype of `object` is treated as a special case and not enforced,
    because it is used as a dummy value in some places when the result will
    not be a block in an Array.

    Parameters
    ----------
    enforce_dtype : dtype
        Result dtype
    enforce_dtype_function : callable
        The wrapped function, which will be passed the remaining arguments
    R{  R|  Rm   R  t	   same_kinds`   Inferred dtype from function %r was %r but got %r, which can't be cast using casting='same_kind'RŹ   (   Ræ   RL  Rm   R|  RV   R  R   R&   R©   Rq  RG  RĘ   R¾   (   R   R   Rm   t   functionRä   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  Ä  s    *+c         C` s\  t  |   }  t |  } |  j | k rF | d k sB | |  j k rF |  St |  |  j } | d k  s t d   t | | |  j  D  r§ t	 d |  j | f   n  | d k rś t d   | |  D  t d   t |  j |  j | |  D  } n| t
 | | d |  j d |  j } xX t |  j | |  D]@ \ } } | | k r2| d k r2t	 d	 |  j | f   q2q2Wd
 t |  | |  } i  } t d   | D   } x} d   | D D]k \ }	 }
 t d   t |  j |	 |  D  } |  j f | } | f |	 } t j | t |
  f | | <q¹Wt j | | d |  g } t | | | d |  j S(   sÆ  Broadcast an array to a new shape.

    Parameters
    ----------
    x : array_like
        The array to broadcast.
    shape : tuple
        The shape of the desired array.
    chunks : tuple, optional
        If provided, then the result will use these chunks instead of the same
        chunks as the source array. Setting chunks explicitly as part of
        broadcast_to is more efficient than rechunking afterwards. Chunks are
        only allowed to differ from the original shape along dimensions that
        are new on the result or have size 1 the input array.

    Returns
    -------
    broadcast : dask array

    See Also
    --------
    :func:`numpy.broadcast_to`
    i    c         s` s-   |  ]# \ } } | d  k r | | k Vq d S(   i   N(    (   RL   t   newt   old(    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s   	s%   cannot broadcast shape %s to shape %sc         s` s   |  ] } | f Vq d  S(   N(    (   RL   Ra   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    c         s` s3   |  ]) \ } } } | d  k r$ | n | f Vq d S(   i   N(    (   RL   R	  R  R  (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s   Rm   R	  i   sq   cannot broadcast chunks %s to chunks %s: new chunks must either be along a new dimension or a dimension of size 1s   broadcast_to-c         s` s   |  ] } t  |  Vq d  S(   N(   RĀ   (   RL   Rf   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>"  s    c         s` s   |  ] } t  |   Vq d  S(   N(   Rd   (   RL   t   ec(    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>#  s    c         s` s-   |  ]# \ } } | d k r! d n | Vq d S(   i   i    N(   i   (    (   RL   R	  R¶   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>$  s   R  N(   i   (   RP   RR   Rk   RK   Re   Rp   R   RS   Rd   R   Rn   Rm   R   R   R­   RV   t   broadcast_toR4   R:   R  R   (   RM   Rk   Re   t   ndim_newt   old_bdt   new_bdR­   RĖ   t   enumerated_chunkst	   new_indext   chunk_shapet	   old_indext   old_keyt   new_keyRt  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  ģ  s<    *	'#	 c          ` s¶   t  | j d t   } | r$ t n t   t   f d   |  D  }  | r[ t d   n  t d   |  D   } t d   |  D   } g  |  D] } t	 | d | d | ^ q } | S(   Nt   subokc         3` s   |  ] }   |  Vq d  S(   N(    (   RL   R   (   t   to_array(    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>3  s    s(   unsupported keyword argument(s) providedc         s` s   |  ] } | j  Vq d  S(   N(   Rk   (   RL   R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>8  s    c         s` s   |  ] } | j  Vq d  S(   N(   Re   (   RL   R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>9  s    Rk   Re   (
   R]  Ræ   RĘ   RB  RP   RR   R¾   Rz  Rē   R  (   R   R   R  Rk   Re   R   Rä   (    (   R  s.   lib/python2.7/site-packages/dask/array/core.pyt   broadcast_arrays.  s    +c         ` s9      f d   } t  t   d   j | _ Wd QX| S(   s     Offsets inputs by offset

    >>> double = lambda x: x * 2
    >>> f = offset_func(double, (10,))
    >>> f(1)
    22
    >>> f(300)
    620
    c          ` s"   t  t t |     }   |   S(   N(   Rc   R   R	   (   R   t   args2(   R   RĻ  (    s.   lib/python2.7/site-packages/dask/array/core.pyt   _offsetJ  s    t   offset_N(   R"   R   RH   (   R   RĻ  R   R  (    (   R   RĻ  s.   lib/python2.7/site-packages/dask/array/core.pyt   offset_func@  s    
c         C` s   |  s
 d Sg  } d } d   } xc t  |  t t f  r | j t g  |  D] } | t |   | ^ qG   |  d }  | d 7} q" Wt |  S(   s`   Chunks tuple from nested list of arrays

    >>> x = np.array([1, 2])
    >>> chunks_from_arrays([x, x])
    ((2, 2),)

    >>> x = np.array([[1, 2]])
    >>> chunks_from_arrays([[x], [x]])
    ((1, 1), (2,))

    >>> x = np.array([[1, 2]])
    >>> chunks_from_arrays([[x, x]])
    ((1,), (2, 2))

    >>> chunks_from_arrays([1, 1])
    ((1, 1),)
    i    c         S` s$   y |  j  SWn t k
 r d SXd  S(   Ni   (   i   (   Rk   R9  (   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRk   k  s    i   (    (   RN   Rc   RR   RĶ   t	   deepfirst(   R   Rä   Rb   Rk   RX   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   chunks_from_arraysT  s    	6
c         C` s+   t  |  t t f  s |  St |  d  Sd S(   sa    First element in a nested list

    >>> deepfirst([[[1, 2], [3, 4]], [5, 6], [7, 8]])
    1
    i    N(   RN   Rc   RR   R  (   R_  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  x  s    c         C` sA   t  |   t k r9 t t |   g t t |  d    Sd Sd S(   s    Get the shape of nested list i    N(    (   R   Rc   RR   Rp   t	   shapelist(   RX   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR    s    'c         C` sg   t  |   d k r t |  St t  |  |  d  } g  t | |  D] } t |  d |  ^ qF Sd S(   sh    Reshape iterator to nested shape

    >>> reshapelist((2, 3), range(6))
    [[0, 1, 2], [3, 4, 5]]
    i   i    N(   Rp   Rc   R  R   t   reshapelist(   Rk   R_  RÕ   t   part(    (    s.   lib/python2.7/site-packages/dask/array/core.pyR     s    
c         C` sļ   t  |  t |   k r' t d   n  | d k  rB t d   n  t  |  t  t |   k ro t d   n  t |  d } t |   } g  t | |  D]+ } | | k rĮ | | j |  n d ^ q } t t	 j
 |    } t | |  S(   sŚ    Permute axes of nested list

    >>> transposelist([[1,1,1],[1,1,1]], [2,1])
    [[[1, 1], [1, 1], [1, 1]]]

    >>> transposelist([[1,1,1],[1,1,1]], [2,1], extradims=1)
    [[[[1], [1]], [[1], [1]], [[1], [1]]]]
    s2   Length of axes should equal depth of nested arraysi    s   `newdims` should be positives   `axes` should be uniquei   (   Rp   R.   R   Rį   R   R  Ro   RY  Rc   R8   Rķ   R   (   R   R   t	   extradimsR   Rk   R¶   t   newshapeRä   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   transposelist  s    	Bc      	   ` s  t    } t   d j  } | d k  r< | | d } n  | | k ra t d | | f   n  t  f d    D  sū t j t j g   D] } | j ^ q   d j k  d } t d j | d  d j | d d  | d j    n  t t	 |     t t
   f d    D   } t |   \ }  t t j g   D] } | j ^ qQ }	 g   D] } | j |	  ^ qp t  t d    D   d k s³t   d j |  d | f  d j | }
 g   D] } | j ^ qå} d t | |  } t t | g g  |
 D] } t	 t  |   ^ q   } g  | D]6 } | | | d f | d | d !| | d	 ^ qK} g  | D]G } t | t d d d  f | d t d d d  f | | f ^ q} t t | |   } t j | | d
  } t | | |
 d |	 S(   sb  
    Stack arrays along a new axis

    Given a sequence of dask arrays, form a new dask array by stacking them
    along a new dimension (axis=0 by default)

    Examples
    --------

    Create slices

    >>> import dask.array as da
    >>> import numpy as np

    >>> data = [from_array(np.ones((4, 4)), chunks=(2, 2))
    ...          for i in range(3)]

    >>> x = da.stack(data, axis=0)
    >>> x.shape
    (3, 4, 4)

    >>> da.stack(data, axis=1).shape
    (4, 3, 4)

    >>> da.stack(data, axis=-1).shape
    (4, 4, 3)

    Result is a new dask Array

    See Also
    --------
    concatenate
    i    i   sZ   Axis must not be greater than number of dimensions
Data has %d dimensions, but got axis=%dc         3` s%   |  ] } | j    d  j  k Vq d S(   i    N(   Rk   (   RL   RM   (   R_  (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>Ū  s    sc   Stacked arrays must have the same shape. The first {0} had shape {1}, while array {2} has shape {3}c         3` s   |  ] } |   f Vq d  S(   N(    (   RL   RM   (   R!  (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>å  s    c         s` s   |  ] } | j  Vq d  S(   N(   Re   (   RL   RX   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ė  s    s   stack-i   R  Rm   (   i   N(   N(   Rp   Rk   R   R   RV   Rf  RB  R   Rc   Ro   R   RH  R   R`  Rm   RG  Rį   R  Re   R­   R   R   R
   RO   RK   Rr   Rd   R:   R  R   (   R_  R   RÕ   R   RM   t   idxRa  R’   RX   Rr  Re   Rd  R­   R	  Ru   R   R=  t   inpRw   R}  Rt  (    (   R!  R_  s.   lib/python2.7/site-packages/dask/array/core.pyRn  ±  s>    "?	
"("(+7@Qc   
      C` se  t  |   }  |  s t j d  St t j |  d t t f d d   } t j	 t
 |   t j k	 r t |   } t |  d t t | j   St |   } | sØ |  St |   } t t t |   } d   } t j d | d | t |     } xh t t |  t j |    D]H \ } }	 t |	 d	  rSx  |	 j | k  rO|	 d }	 q3Wn  |	 | | <qW| S(   s	   Recursive np.concatenate

    Input should be a nested list of numpy arrays arranged in the order they
    should appear in the array itself.  Each array should have the same number
    of dimensions as the desired output and the nesting of the lists.

    >>> x = np.array([[1, 2]])
    >>> concatenate3([[x, x, x], [x, x, x]])
    array([[1, 2, 1, 2, 1, 2],
           [1, 2, 1, 2, 1, 2]])

    >>> concatenate3([[x, x], [x, x], [x, x]])
    array([[1, 2, 1, 2],
           [1, 2, 1, 2],
           [1, 2, 1, 2]])
    i    t	   containerR   c         S` s   t  |  d d  S(   NR   i    (   R8  (   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR     R   R   c         S` s*   y |  j  SWn t k
 r% t |   SXd  S(   N(   Rm   R9  R   (   RM   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRm     s    Rk   Rm   R   .N(   N.(   R#   RV   R)  R   R8   Rķ   Rc   RR   R   R   R   RD   R  R   Ro   R   R.   R  R   Ry   R  Rd   Rl   RL  RK   (
   R   t   advancedRM   R   Re   Rk   Rm   Rä   R„  Rs   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR  ž  s*    	$+c         C` sf   t  |  t |   k r' t d   n  t d t |   j t |  d  } t t |  | d |  S(   s,    Recursively call np.concatenate along axes s2   Length of axes should equal depth of nested arraysi    i   R¢  (   Rp   R.   R   R   R  R   R  R¤  (   R   R   R¢  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   concatenate_axes0  s    &c         O` s\  t  |  d k r2 t | d t  r2 | d } n\ t  |  d k r t | d t  r t | d t  r i | d | d 6} n t d   | j d t  } d d l } | j	 |    } g  | j
   D]h \ } } | j | d | j d | j d | t k r't g  | j D] }	 |	 d ^ q n | | ^ qĖ }
 t t | j    |
  Wd QXd S(	   s«   Store arrays in HDF5 file

    This saves several dask arrays into several datapaths in an HDF5 file.
    It creates the necessary datasets and handles clean file opening/closing.

    >>> da.to_hdf5('myfile.hdf5', '/x', x)  # doctest: +SKIP

    or

    >>> da.to_hdf5('myfile.hdf5', {'/x': x, '/y': y})  # doctest: +SKIP

    Optionally provide arguments as though to ``h5py.File.create_dataset``

    >>> da.to_hdf5('myfile.hdf5', '/x', x, compression='lzf', shuffle=True)  # doctest: +SKIP

    This can also be used as a method on a single Array

    >>> x.to_hdf5('myfile.hdf5', '/x')  # doctest: +SKIP

    See Also
    --------
    da.store
    h5py.File.create_dataset
    i   i    i   s/   Please provide {'/data/path': array} dictionaryRe   NRk   Rm   (   Rp   RN   Rr   R©   R   R   Ræ   RÅ   t   h5pyt   FileRÉ   t   require_datasetRk   Rm   RR   Re   R  Rc   Rw   (   RU  R   R   Ro  Re   RŖ  R  t   dpRM   R\   t   dsets(    (    s.   lib/python2.7/site-packages/dask/array/core.pyRT  9  s    %xc         C` s   g  } d } } t  |   t  |  } xg | | | k  r |  | d k	 rg | j |  |  | d 7} q) | j | |  | d 7} | d 7} q) Wt |  S(   sK   

    >>> interleave_none([0, None, 2, None], [1, 3])
    (0, 1, 2, 3)
    i    i   N(   Rp   RK   RĶ   RR   (   RX   RY   Rä   R¶   Rŗ   RÕ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   interleave_nonef  s    

c         C` s   |  | f t  d   | D  S(   sE   

    >>> keyname('x', 3, [None, None, 0, 2])
    ('x', 3, 0, 2)
    c         s` s!   |  ] } | d  k	 r | Vq d  S(   N(   RK   (   RL   RÖ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>  s    (   RR   (   R­   R¶   t   okey(    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   keynamez  s    c         G` s“  t  |  j |  } g  } g  } x t |  D]} \ } } t | t  rV | j |  q+ t | t  r | j |  | j t d   q+ | j t d   | j |  q+ Wt |  } t |  } |  | }  i  } xĮ t t	 | |  j
   D]§ \ } \ } } t | t  sķ t j | d t } | j j d k rDt d   n  | | k | | k  Bj   r}t d | | | f   n  | | ;} | | | <qķ qķ W| r°t |  |  }  n  |  S(   s3  Point wise indexing with broadcasting.

    >>> x = np.arange(56).reshape((7, 8))
    >>> x
    array([[ 0,  1,  2,  3,  4,  5,  6,  7],
           [ 8,  9, 10, 11, 12, 13, 14, 15],
           [16, 17, 18, 19, 20, 21, 22, 23],
           [24, 25, 26, 27, 28, 29, 30, 31],
           [32, 33, 34, 35, 36, 37, 38, 39],
           [40, 41, 42, 43, 44, 45, 46, 47],
           [48, 49, 50, 51, 52, 53, 54, 55]])

    >>> d = from_array(x, chunks=(3, 4))
    >>> result = _vindex(d, [0, 1, 6, 0], [0, 1, 0, 7])
    >>> result.compute()
    array([ 0,  9, 48,  7])
    RŹ   RY   s4   vindex does not support indexing with boolean arrayssN   vindex key has entries out of bounds for indexing along axis %s of size %s: %rN(   R@   R   RĀ   RN   R   RĶ   RO   RK   RR   Rd   Rk   RV   RC   RÅ   Rm   Ro  Rw  RS   t   _vindex_array(   RM   t   indexest   nonfancy_indexest   reduced_indexesR¶   R!  t   array_indexesRC  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRx    s8    
+
c         ` sŖ  y t  j | j     } Wn@ t k
 r[ d j d   | j   D  } t d |   n X| d j } t t | |   } g  t	  j
  D]. } | | k r¶ | | j   j   n d ^ q } | j d g  j
 t |   g  | D]$ } | d k	 rt |  n | ^ qź } g   j D] }	 t t t d |	   ^ q}
 g  t | |
  D] \ } } | d k	 rS| ^ qS} t |    t  |   d  } t   } xÜ t t g  | D] } | d k	 rµ| ^ qµ   D]© \ } } g  t | |  D]% \ } } t  j | | d  d ^ qó} g  t t | |   D]$ \ } \ } } | | | | ^ q4} | j | t |  t |  f  q×Wg  t |  j  D] \ } }	 | d k r|	 ^ q} | j d | rŁt |  f n d  t |  } | rRt d |   t d    j   D   t t g  t |  j  D]9 \ } }	 | d k rft t	 t |	    n d g ^ q6    g  | D]' } | d k r£t d d  n d ^ q d	   t        f d
   t   D  } | j    f d    D  t  t! j" | | d  g | |  j#  } | j$ | | j d  Sd d l% m& } | t t' t( |   d | d  j# d | } | j$ | | j d  S(   s+   Point wise indexing with only NumPy Arrays.Rv  c         s` s   |  ] } t  | j  Vq d  S(   N(   R©   Rk   (   RL   RX   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>Ć  s    sL   shape mismatch: indexing arrays could not be broadcast together with shapes i    s   vindex-merge-t   righti   c         s` s'   |  ] \ } } | r | | f Vq d  S(   N(    (   RL   RÖ   RŲ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ę  s    s   vindex-slice-c         3` s   |  ]w \ } }  D]d } t   | |  t t  j f t | |  t  t t t d   |      f   f f Vq q d S(   i   N(   R±  t   _vindex_transposet   _vindex_sliceR­   RÆ  Rc   Rd   R   (   RL   R¶   R   R°  (   R   t   full_slicesR­   t   other_blockst	   per_blockRM   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>š  s   	c      
   3` s   |  ]{ } t  d   d |  t g   D] } t t d  |   ^ q& g  t t    D] } t    | |  ^ q[ f f Vq d S(   s   vindex-merge-i    N(   R±  t   _vindex_mergeRc   R   Ro   Rp   (   RL   R°  R   R¶   (   R­   R¼  R®   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>ų  s   R  (   R)  Re   Rm   R­   N(   i    (   i    ()   RV   R  Rw   R   R   Rw  Rk   Rr   Rd   Ro   R   R  Rz  RK   Rļ   Rp   Rc   Re   R   R	   t	   _get_axisR   RĀ   t   searchsortedRĶ   RR   RÄ   R   RÉ   R   RO   t   updateR   R:   R  Rm   R  t   wrapR)  R   Ry   (   RM   t   dict_indexest   broadcast_indexest
   shapes_strt   broadcast_shapet   lookupR¶   t   flat_indexesRY  R\   t   boundsRY   t   bounds2Rt   t   pointsR„  R!  t	   block_idxRÖ   Rŗ   t   inblock_idxRe   RĖ   t	   result_1dR)  (    (   R   Rŗ  R­   R»  R¼  R®   RM   s.   lib/python2.7/site-packages/dask/array/core.pyR²  ¼  s\    A!1/4
	>8=&7%	U4
-c         C` sv   t  |   } g  |  D]* } | d k r4 t d d  n d g ^ q }  t j d |  } | t |   } | j j d  S(   sP   Get axis along which point-wise slicing results lie

    This is mostly a hack because I can't figure out NumPy's rule on this and
    can't be bothered to go reading.

    >>> _get_axis([[1, 2], None, [1, 2], None])
    0
    >>> _get_axis([None, [1, 2], [1, 2], None])
    1
    >>> _get_axis([None, None, [1, 2], [1, 2]])
    2
    i    i   i   N(   i   (   Rp   RK   RO   RV   R)  RR   Rk   RY  (   R³  R   R¶   RM   t   x2(    (    s.   lib/python2.7/site-packages/dask/array/core.pyR¾    s
    7c         C` sB   g  | D]' } t  | t  r" | n	 t |  ^ q } |  t |  S(   s'    Pull out point-wise slices from block (   RN   RO   Rc   RR   (   R^  RŹ  t   p(    (    s.   lib/python2.7/site-packages/dask/array/core.pyR¹  !  s    4c         C` s@   | g t  t |   t  t | d |  j   } |  j |  S(   s8    Rotate block so that points are on the first dimension i   (   Rc   Ro   R   R  (   R^  R   R   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyRø  '  s    3c   
      C` sź   t  t t  |    }  t  |  } t t t |    } t  | d j  } | | d <t |  } | d j } t j | d | } g  t	 | j
  D] } t d d  ^ q } x7 t |  |  D]& \ } }	 | | d <|	 | t |  <q¼ W| S(   s’   

    >>> locations = [0], [2, 1]
    >>> values = [np.array([[1, 2, 3]]),
    ...           np.array([[10, 20, 30], [40, 50, 60]])]

    >>> _vindex_merge(locations, values)
    array([[ 1,  2,  3],
           [40, 50, 60],
           [10, 20, 30]])
    i    Rm   N(   Rc   R   Ry   Rp   Rk   RR   Rm   RV   R)  Ro   R   RO   RK   Rd   (
   t	   locationsRw   RÕ   Rk   Rm   RM   R¶   R!  t   locRF  (    (    s.   lib/python2.7/site-packages/dask/array/core.pyR½  -  s    
+
c   	      ` s$  t    f d   t | j  D  } | j |  } t j j   sV t j   n  i | d 6| j d 6  d 6} t	 t j j
  d  d   } t j | |  Wd QXd t t j       f d	   t t j | j     D } t j  | d
 | g } t t | t |   d S(   s_   Write dask array to a stack of .npy files

    This partitions the dask.array along one axis and stores each block along
    that axis as a single .npy file in the specified directory

    Examples
    --------
    >>> x = da.ones((5, 10, 10), chunks=(2, 4, 4))  # doctest: +SKIP
    >>> da.to_npy_stack('data/', x, axis=0)  # doctest: +SKIP

        $ tree data/
        data/
        |-- 0.npy
        |-- 1.npy
        |-- 2.npy
        |-- info

    The ``.npy`` files store numpy arrays for ``x[0:2], x[2:4], and x[4:5]``
    respectively, as is specified by the chunk size along the zeroth axis.  The
    info file stores the dtype, chunks, and axis information of the array.

    You can load these stacks with the ``da.from_npy_stack`` function.

    >>> y = da.from_npy_stack('data/')  # doctest: +SKIP

    See Also
    --------
    from_npy_stack
    c         3` s6   |  ], \ } } |   k r! | n t  |  f Vq d  S(   N(   Ry   (   RL   R¶   R\   (   R   (    s.   lib/python2.7/site-packages/dask/array/core.pys	   <genexpr>m  s   Re   Rm   R   Rß   t   wbNs   to-npy-stack-c         ` sD   i  |  ]: \ } } t  j t j j   d  |  | f  | f  q S(   s   %d.npy(   RV   t   savet   osR$  R   (   RL   R¶   R   (   t   dirnameR­   (    s.   lib/python2.7/site-packages/dask/array/core.pys
   <dictcomp>z  s   	R  (   RR   RĀ   Re   Rą  RŌ  R$  t   existst   mkdirRm   t   openR   t   picklet   dumpR©   Rš   Rń   R8   Rķ   Rī   R:   R  R   R   Rc   (	   RÕ  RM   R   Re   t   xxt   metaR  RĖ   Rt  (    (   R   RÕ  R­   s.   lib/python2.7/site-packages/dask/array/core.pyt   to_npy_stackN  s    !R  c      	   C` s  t  t j j |  d  d   } t j |  } Wd QX| d } | d } | d } d |  } t t | g g  | D] } t t	 |   ^ qq   }	 g  t t	 | |   D]+ }
 t
 j t j j |  d |
  | f ^ q¬ } t t |	 |   } t | | | |  S(	   sķ    Load dask array from stack of npy files

    See ``da.to_npy_stack`` for docstring

    Parameters
    ----------
    dirname: string
        Directory of .npy files
    mmap_mode: (None or 'r')
        Read data in memory map mode
    Rß   R!  NRm   Re   R   s   from-npy-stack-%ss   %d.npy(   RŲ  RŌ  R$  R   RŁ  t   loadRc   R   Ro   Rp   RV   Rr   Rd   R   (   RÕ  t	   mmap_modeR  Rß   Rm   Re   R   R­   R\   Ru   R¶   Rw   RĖ   (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   from_npy_stack  s    !



7E(“   t
   __future__R    R   R   R   RŹ   t	   functoolsR   R   t	   itertoolsR   R  t   numbersR   R   Rq   R	   R
   R   RŌ  RŖ   R   R   RŁ  t	   threadingR   Rš   RĄ   t   cytoolzR   R   R   R   R   t   cytoolz.curriedR   t   ImportErrort   toolzt   toolz.curriedR   R   R   t   numpyRV   R   R   R   Rp  R   R   R   R   R   R   RA   R   R   t   contextR    t   utilsR!   R"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R-   R.   t   compatibilityR/   R0   R1   R2   R3   R8   R4   R5   R6   R7   R9   t   highlevelgraphR:   t
   bytes.coreR;   R<   t   numpy_compatR=   R>   Rq  R?   R@   t   update_defaultsR   t   tensordot_lookupt   einsum_lookupt   registerR|  R3  RD   RE   RF   t   WarningRG   RÅ   RK   RT   R]   R^   t   optimizationR_   R`   Rl   RĘ   Rx   R   R   RØ   R¬   Rµ   Rē   R  R  R  R~  R  R   Rč  Rn   R  R  R   R,  Rł  R2  R6  R7  R>  RH  R  R^  Re  Rf  Rg  Rņ   Ró   RP   RB  Rt  Rz  R:  R  R  R  R  R  R  R  R  R   R¤  Rn  R  R©  RT  RÆ  R±  Rx  R²  R¾  R¹  Rø  R½  RŻ  Rą  (    (    (    s.   lib/python2.7/site-packages/dask/array/core.pyt   <module>   sü   ((.^(		&9		’ 2	,			’ ’ ’ ļ		p	f,;	(	@	Q	µe	.		9!	$	)	 	!	G		(B		$			M	2			-				9	Q				!3