ó
¦–Õ\c           @   sA   d  d l  m Z d „  Z d d d d „ Z e e d d „ Z d S(   i   (   t   corec            s,   |  j  ‰  t ‡  f d †  t ˆ  j ƒ Dƒ ƒ S(   Nc         3   s$   |  ] } ˆ  j  j | ƒ j Vq d  S(   N(   t   domaint   dimt   tile(   t   .0t   i(   t   schema(    s3   lib/python2.7/site-packages/dask/array/tiledb_io.pys	   <genexpr>   s    (   R   t   listt   ranget   ndim(   t   tiledb_array(    (   R   s3   lib/python2.7/site-packages/dask/array/tiledb_io.pyt   _tiledb_to_chunks   s    	c   	      K   s%  d d l  } | p t ƒ  } | j d d ƒ } t |  | j ƒ rH |  } n! | j |  d | d | d | ƒ} | j j r„ t	 d ƒ ‚ n  | sÃ | j j
 d k r« t d ƒ ‚ qÃ | j j d	 ƒ j } n  | j rÛ t	 d
 ƒ ‚ n  | pê t | ƒ } t | ƒ | j j k st ‚ t j | | d d |  ƒS(   s”  Load array from the TileDB storage format

    See https://docs.tiledb.io for more information about TileDB.

    Parameters
    ----------
    uri: TileDB array or str
        Location to save the data
    attribute: str or None
        Attribute selection (single-attribute view on multi-attribute array)


    Returns
    -------

    A Dask Array

    Examples
    --------

    >>> # create a tiledb array
    >>> import tiledb, numpy as np, tempfile  # doctest: +SKIP
    >>> uri = tempfile.NamedTemporaryFile().name  # doctest: +SKIP
    >>> tiledb.from_numpy(uri, np.arange(0,9).reshape(3,3))  # doctest: +SKIP
    <tiledb.libtiledb.DenseArray object at 0x...>
    >>> # read back the array
    >>> import dask.array as da  # doctest: +SKIP
    >>> tdb_ar = da.from_tiledb(uri)  # doctest: +SKIP
    >>> tdb_ar.shape  # doctest: +SKIP
    (3, 3)
    >>> tdb_ar.mean().compute()  # doctest: +SKIP
    4.0
    iÿÿÿÿNt   keyt   attrt   configs&   Sparse TileDB arrays are not supportedi   sO   keyword 'attribute' must be providedwhen loading a multi-attribute TileDB arrayi    s%   TileDB array must be open for readingt   names	   tiledb-%s(   t   tiledbt   dictt   popt   Nonet
   isinstancet   Arrayt   openR   t   sparset
   ValueErrort   nattrt	   TypeErrorR   R   t
   iswritableR   t   lenR	   t   AssertionErrorR    t
   from_array(	   t   urit	   attributet   chunkst   storage_optionst   kwargsR   t   tiledb_configR   t   tdb(    (    s3   lib/python2.7/site-packages/dask/array/tiledb_io.pyt   from_tiledb	   s"    #	!	c      
   K   se  d d l  } | p t ƒ  } | j d d ƒ } t j |  j ƒ sN t d ƒ ‚ n  t | t	 ƒ r¹ g  |  j D] }	 |	 d ^ qg }
 | j d d ƒ } | j
 | |  d |
 d | d | | } nl t | | j ƒ r| } |  j | j k o|  j | j k o|  j | j k s%t d ƒ ‚ q%n t d	 ƒ ‚ | j o4| j sFt d
 ƒ ‚ n  |  j | d t d | d | ƒS(   sÔ  Save array to the TileDB storage format

    Save 'array' using the TileDB storage manager, to any TileDB-supported URI,
    including local disk, S3, or HDFS.

    See https://docs.tiledb.io for more information about TileDB.

    Parameters
    ----------

    darray: dask.array
        A dask array to write.
    uri:
        Any supported TileDB storage location.
    storage_options: dict
        Dict containing any configuration options for the TileDB backend.
        see https://docs.tiledb.io/en/stable/tutorials/config.html
    compute, return_stored: see ``store()``

    Returns
    -------

    None
        Unless ``return_stored`` is set to ``True`` (``False`` by default)

    Notes
    -----

    TileDB only supports regularly-chunked arrays.
    TileDB `tile extents`_ correspond to form 2 of the dask
    `chunk specification`_, and the conversion is
    done automatically for supported arrays.

    Examples
    --------

    >>> import dask.array as da, tempfile  # doctest: +SKIP
    >>> uri = tempfile.NamedTemporaryFile().name   # doctest: +SKIP
    >>> data = da.random.random(5,5)  # doctest: +SKIP
    >>> da.to_tiledb(data, uri)  # doctest: +SKIP
    >>> import tiledb  # doctest: +SKIP
    >>> tdb_ar = tiledb.open(uri)  # doctest: +SKIP
    >>> all(tdb_ar == data)  # doctest: +SKIP
    True

    .. _chunk specification: https://docs.tiledb.io/en/stable/tutorials/tiling-dense.html
    .. _tile extents: http://docs.dask.org/en/latest/array-chunks.html
    iÿÿÿÿNR   s^   Attempt to save array to TileDB with irregular chunking, please call `arr.rechunk(...)` first.i    R   R   s>   Target TileDB array layout is not compatible with source arraysc   'uri' must be string pointing to supported TileDB store location or an open, writable TileDB array.s-   Target TileDB array is not open and writable.t   lockt   computet   return_stored(   R   R   R   R   R    t   _check_regular_chunksR!   R   R   t   strt
   empty_likeR   t   shapet   dtypeR	   t   isopenR   t   storet   False(   t   darrayR   R(   R)   R"   R#   R   R$   R   t   cR!   R%   (    (    s3   lib/python2.7/site-packages/dask/array/tiledb_io.pyt	   to_tiledbI   s(    2 *N(   t    R    R   R   R&   t   TrueR1   R4   (    (    (    s3   lib/python2.7/site-packages/dask/array/tiledb_io.pyt   <module>   s
   	?