<s> from __future__ import print_function <EOL> import os <EOL> import tables <EOL> from indexed_search import DB <EOL> class PyTables_DB ( DB ) : <EOL> def __init__ ( self , nrows , rng , userandom , datadir , <EOL> docompress = <NUM_LIT:0> , complib = '<STR_LIT>' , kind = "<STR_LIT>" , optlevel = <NUM_LIT:6> ) : <EOL> DB . __init__ ( self , nrows , rng , userandom ) <EOL> self . tprof = [ ] <EOL> self . docompress = docompress <EOL> self . complib = complib <EOL> self . filename = "<STR_LIT>" + self . filename <EOL> self . filename += '<STR_LIT:->' + '<STR_LIT>' % optlevel <EOL> self . filename += '<STR_LIT:->' + kind <EOL> if docompress : <EOL> self . filename += '<STR_LIT:->' + complib + str ( docompress ) <EOL> self . filename = datadir + '<STR_LIT:/>' + self . filename + '<STR_LIT>' <EOL> self . filters = tables . Filters ( complevel = self . docompress , <EOL> complib = self . complib , <EOL> shuffle = <NUM_LIT:1> ) <EOL> print ( "<STR_LIT>" , self . filename ) <EOL> def open_db ( self , remove = <NUM_LIT:0> ) : <EOL> if remove and os . path . exists ( self . filename ) : <EOL> os . remove ( self . filename ) <EOL> con = tables . open_file ( self . filename , '<STR_LIT:a>' ) <EOL> return con <EOL> def close_db ( self , con ) : <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> del self . table_cache <EOL> con . close ( ) <EOL> def create_table ( self , con ) : <EOL> class Record ( tables . IsDescription ) : <EOL> col1 = tables . Int32Col ( ) <EOL> col2 = tables . Int32Col ( ) <EOL> col3 = tables . Float64Col ( ) <EOL> col4 = tables . Float64Col ( ) <EOL> con . create_table ( con . root , '<STR_LIT>' , Record , <EOL> filters = self . filters , expectedrows = self . nrows ) <EOL> def fill_table ( self , con ) : <EOL> "<STR_LIT>" <EOL> table = con . root . table <EOL> j = <NUM_LIT:0> <EOL> for i in range ( <NUM_LIT:0> , self . nrows , self . step ) : <EOL> stop = ( j + <NUM_LIT:1> ) * self . step <EOL> if stop > self . nrows : <EOL> stop = self . nrows <EOL> arr_i4 , arr_f8 = self . fill_arrays ( i , stop ) <EOL> table . append ( [ arr_i4 , arr_i4 , arr_f8 , arr_f8 ] ) <EOL> j += <NUM_LIT:1> <EOL> table . flush ( ) <EOL> def index_col ( self , con , column , kind , optlevel , verbose ) : <EOL> col = getattr ( con . root . table . cols , column ) <EOL> col . create_index ( kind = kind , optlevel = optlevel , filters = self . filters , <EOL> tmp_dir = "<STR_LIT>" , <EOL> _verbose = verbose , _blocksizes = None ) <EOL> def do_query ( self , con , column , base , inkernel ) : <EOL> if True : <EOL> if not hasattr ( self , "<STR_LIT>" ) : <EOL> self . table_cache = table = con . root . table <EOL> self . colobj = getattr ( table . cols , column ) <EOL> self . condvars = { "<STR_LIT>" : self . colobj , <EOL> "<STR_LIT>" : table . cols . col1 , <EOL> "<STR_LIT>" : table . cols . col2 , <EOL> "<STR_LIT>" : table . cols . col3 , <EOL> "<STR_LIT>" : table . cols . col4 , <EOL> } <EOL> table = self . table_cache <EOL> colobj = self . colobj <EOL> else : <EOL> table = con . root . table <EOL> colobj = getattr ( table . cols , column ) <EOL> self . condvars = { "<STR_LIT>" : colobj , <EOL> "<STR_LIT>" : table . cols . col1 , <EOL> "<STR_LIT>" : table . cols . col2 , <EOL> "<STR_LIT>" : table . cols . col3 , <EOL> "<STR_LIT>" : table . cols . col4 , <EOL> } <EOL> self . condvars [ '<STR_LIT>' ] = self . rng [ <NUM_LIT:0> ] + base <EOL> self . condvars [ '<STR_LIT>' ] = self . rng [ <NUM_LIT:1> ] + base <EOL> d = ( self . rng [ <NUM_LIT:1> ] - self . rng [ <NUM_LIT:0> ] ) / <NUM_LIT> <EOL> inf1 = int ( self . rng [ <NUM_LIT:0> ] + base ) <EOL> sup1 = int ( self . rng [ <NUM_LIT:0> ] + d + base ) <EOL> inf2 = self . rng [ <NUM_LIT:0> ] + base * <NUM_LIT:2> <EOL> sup2 = self . rng [ <NUM_LIT:0> ] + d + base * <NUM_LIT:2> <EOL> self . condvars [ '<STR_LIT>' ] = inf1 <EOL> self . condvars [ '<STR_LIT>' ] = sup1 <EOL> self . condvars [ '<STR_LIT>' ] = inf2 <EOL> self . condvars [ '<STR_LIT>' ] = sup2 <EOL> condition = "<STR_LIT>" <EOL> condition += "<STR_LIT>" <EOL> ncoords = <NUM_LIT:0> <EOL> if colobj . is_indexed : <EOL> results = [ r [ column ] <EOL> for r in table . where ( condition , self . condvars ) ] <EOL> elif inkernel : <EOL> print ( "<STR_LIT>" ) <EOL> results = [ r [ column ] <EOL> for r in table . where ( condition , self . condvars ) ] <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> results = [ <EOL> r [ column ] for r in table if ( ( <EOL> ( inf2 <= r [ '<STR_LIT>' ] ) and ( r [ '<STR_LIT>' ] < sup2 ) ) or <EOL> ( ( inf1 < r [ '<STR_LIT>' ] ) and ( r [ '<STR_LIT>' ] < sup1 ) ) and <EOL> ( ( r [ '<STR_LIT>' ] + <NUM_LIT> * r [ '<STR_LIT>' ] + r [ '<STR_LIT>' ] * r [ '<STR_LIT>' ] ) > <NUM_LIT:3> ) <EOL> ) ] <EOL> ncoords = len ( results ) <EOL> return ncoords </s>
