
j\c           @@  s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d   Z d   Z d   Z	 d   Z
 d   Z d	 d
 d
 d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e j d d  d Z e j d d  Z i d d g d 6d6 d8 g d 6d d: g d 6d< d> g d  6d d@ g d" 6dB dD g d$ 6d dF g d& 6dH dJ g d( 6d dL g d* 6e e g d+ 6e e g d, 6Z e e d-  re j e j  e j e j  g e d- <n  e e d.  re j e j  e j e j  g e d. <n  e e d/  rFe j e j  e j e j  g e d/ <n  e Z e Z  d 
d0  Z! d1   Z" d2   Z# d3   Z$ d4   Z% d S(M   s/   Utilities to be used mainly by the Index class.i    (   t   absolute_importNc         C@  s   d d t  j |   S(   s6   Return the fitted chunksize (a float value) for nrows.i@   i   (   t   matht   log10(   t   nrows(    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt	   csformula    s    	c         C@  s.   |  d k  r d }  n |  d k r* d }  n  |  S(   sD   Protection against creating too small or too large chunks or slices.i
   i   i   i i I    I    (    (   t   expectedrows(    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   limit_er,   s
    		c         C@  s;   t  |   }  t t j |    } d | } t t |   S(   s0   Get the optimum chunksize based on expectedrows.i
   (   R   t   intR   R   R   (   R   t   zoneR   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   computechunksize6   s    
c         C@  si   t  |   }  t |   } t |   } t | | d  } | | | } | d 9} | d k re d } n  | S(   s@   Get the optimum slicesize based on expectedrows and memorylevel.i   i   i   i   @i   @(   R   R   R	   R   (   R   t   memlevelt   cst	   chunksizet   ss(    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   computeslicesize?   s    
		c         C@  sC   |  | d } | d k r# d } n  | | } | | d | } | S(   s   Calculate the optimum number of superblocks made from compounds blocks.

    This is useful for computing the sizes of both blocks and
    superblocks (using the PyTables terminology for blocks in indexes).

    i   i   i   i   i   (    (   R   t   compoundsizet   lowercompoundsizet   nlowerblockst   size(    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   computeblocksizeY   s    	
i   i   c   	      C@  s   t  |   } t |  |  } | d k rB t | | |  \ } } nu | d k ri t | | |  \ } } nN | d k r t | | |  \ } } n' | d k r t | | |  \ } } n  t |  | |  } t |  | |  } | | | | f } | S(   s  Calculate the HDF5 chunk size for index and sorted arrays.

    The logic to do that is based purely in experiments playing with
    different chunksizes and compression flag. It is obvious that using
    big chunks optimizes the I/O speed, but if they are too large, the
    uncompressor takes too much time. This might (should) be further
    optimized by doing more experiments.

    i   i   i   i   (   R	   R   t   ccs_ultralightt	   ccs_lightt
   ccs_mediumt   ccs_fullR   (	   R   t   optlevelt   indsizeR
   R   t	   slicesizet	   blocksizet   superblocksizet   sizes(    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   calc_chunksizel   s    c         C@  s   |  d k r' | d } | |  | 7} nW |  d k rD | |  d 9} n: |  d k ra | |  d 9} n |  d
 k r~ | |  d 9} n  | | f S(   s:   Correct the slicesize and the chunksize based on optlevel.i    i   i   i   i   i   i   i   i   i	   (   i    i   i   (   i   i   i   (   i   i   i   (    (   R   R   R   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyR      s    
c         C@  sn   |  d k r | d } nK |  d k r( n< |  d k rA | d :} n# |  d
 k rd | d :} | d 9} n  | | f S(   s:   Correct the slicesize and the chunksize based on optlevel.i    i   i   i   i   i   i   i   i   i	   (   i    i   i   (   i   i   i   (   i   i   i   (    (   R   R   R   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyR      s    
c         C@  sn   |  d k r | d } nK |  d k r( n< |  d k rA | d } n# |  d
 k rd | d } | d 9} n  | | f S(   s:   Correct the slicesize and the chunksize based on optlevel.i    i   i   i   i   i   i   i   i   i	   (   i    i   i   (   i   i   i   (   i   i   i   (    (   R   R   R   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyR      s    
c         C@  sn   |  d k r | d } nK |  d k r( n< |  d k rA | d } n# |  d
 k rd | d } | d 9} n  | | f S(   s:   Correct the slicesize and the chunksize based on optlevel.i    i   i   i   i   i   i   i   i   i	   (   i    i   i   (   i   i   i   (   i   i   i   (    (   R   R   R   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyR      s    
c         C@  sO   | d k r t  |  |  S| d k r2 t |  |  S| d k rK t |  |  Sd S(   s   Compute the optimizations to be done.

    The calculation is based on the number of blocks, optlevel and
    indexing mode.

    i   i   i   N(   t	   col_lightt
   col_mediumt   col_full(   t   nblocksR   R   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   calcoptlevels   s    c         C@  s   t  f d \ } } } } d | k  o0 d k n r> t } n_ d | k  oU d k n rj t t } } n3 d | k  o d k n r t t t } } } n  | | | | f S(   s7   Compute the optimizations to be done for light indexes.i   i    i   i   i	   (   t   Falset   True(   R"   R   t	   optmediant	   optstartst   optstopst   optfull(    (    s.   lib/python2.7/site-packages/tables/idxutils.pyR      s    	c         C@  s  t  f d \ } } } } |  d k r d | k  o< d k n rJ t } qd | k  oa d k n rv t t } } qd | k  o d k n rd } qno d | k  o d k n r d } nJ d | k  o d k n r d } n% d | k  o d k n rd } n  | | | | f S(   s8   Compute the optimizations to be done for medium indexes.i   i   i    i   i   i	   i   (   R$   R%   (   R"   R   R&   R'   R(   R)   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyR       s    				c         C@  s  t  f d \ } } } } |  d k r d | k  o< d k n rJ t } qd | k  oa d k n rv t t } } qd | k  o d k n rd } qno d | k  o d k n r d } nJ d | k  o d k n r d } n% d | k  o d k n rd } n  | | | | f S(   s6   Compute the optimizations to be done for full indexes.i   i   i    i   i   i	   i   (   R$   R%   (   R"   R   R&   R'   R(   R)   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyR!     s    				c         C@  s  d d d d d d d d d d g
 d d d d d d d d d d g
 d d d d d d d d d d g
 d d d d d d d d d d g
 g } i d d 6d d 6d d 6d d 6} | | |  | } | | k r d } n  | | | k r d } n  |  d k r| d k st   n  | S(   s:   Compute the reduction level based on indsize and optlevel.i   i   i   i   i    i   (   t   AssertionError(   R   R   R   R   t   rlevelst   isizest   rlevel(    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   get_reduction_level  s    !!!'"		g      ?i  i   i   i   t   booli   t   int8i   t   uint8i   t   int16i   t   uint16i   t   int32i    t   uint32i?   t   int64i@   t   uint64t   float32t   float64t   float16t   float96t   float128c         C@  s   | d d 
g k s t   |  j d k rG | d k  r< d | Sd | Sn  y t |  j | d k SWn$ t k
 r t d |  j   n Xd S(	   s<   Return a superior limit for maximum representable data type.ii   t   Si    s    s   s   Type %s is not supportedN(   R*   t   kindt   infinitymapt   namet   KeyErrort	   TypeError(   t   dtypet   itemsizet   sign(    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   inftypex  s    c         C@  s  | d d 
g k s t   | t |   } | d k rF |  d | 7}  n  t j d d k  rh t |   } n" g  |  D] } t | g  ^ qo } | j   d } | d k r$| d | k r d j |  Sx | D]S } t |  d k  r	t	 t |  d  j
 d	  | | <Pn
 d | | <| d 7} q Wn{ | d | k rAd j |  Sx[ | D]S } t |  d k rt	 t |  d  j
 d	  | | <Pn
 d | | <| d 7} qHW| j   d j |  S(
   sM   Return the next representable neighbor of x in the appropriate
    direction.ii   i    s    i   s   t    i   t   ascii(   R*   t   lent   syst   version_infot   listt   bytest   reverset   joint   ordt   chrt   encode(   t   xt	   directionRD   t   padsizet   xlistt   it   xchar(    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   string_next_after  s8    "
#
#

c         C@  s   | d d 
g k s t   | d k  rY t |  t  r< |  d St t j |  |  d   Sn5 t |  t  rp |  d St t j |  |  d   d Sd S(   sM   Return the next representable neighbor of x in the appropriate
    direction.ii   i    N(   R*   t
   isinstanceR   t   numpyt	   nextafter(   RS   RT   RD   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   int_type_next_after  s    c         C@  s1   | d d 
g k s t   | d k  r) t St Sd S(   sM   Return the next representable neighbor of x in the appropriate
    direction.ii   i    N(   R*   R$   R%   (   RS   RT   RD   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   bool_type_next_after  s    c         C@  s  | d d d 
g k s t   | j d k sP t |   t t f t j k sP t   | d k r` |  S| j d k r t |  | |  S| j d k r t |  | |  S| j d k r t	 |  | |  S| j d k r| d k  r t
 j |  |  d  St
 j |  |  d  Sn  t d	 |   d
 S(   sM   Return the next representable neighbor of x in the appropriate
    direction.ii    i   R=   t   bRW   t   ut   fs!   data type ``%s`` is not supportedN(   R_   (   RW   R`   (   R*   R>   t   typeR/   t   floatt   sixt   integer_typesRY   R^   R]   R[   R\   RB   (   RS   RT   RC   RD   (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyR\     s    4i   ii   i   i   i   i   i i   i  i   i  I       i   I       iI       I    l            l         l            l    l            l    (&   t   __doc__t
   __future__R    Rd   RJ   R   R[   R   R   R	   R   R   R   R   R   R   R   R#   R   R    R!   R.   t   ldexpt   infinityt	   infinityfR?   t   hasattrR:   t   infR;   R<   t   infinityMapt	   infinityFRF   RY   R]   R^   R\   (    (    (    s.   lib/python2.7/site-packages/tables/idxutils.pyt   <module>   sd   		
				 									-	,		