

def tables(docompute, dowrite, complib, verbose):
    ifilename = os.path.join(OUT_DIR, 'expression-inputs.h5')
    ofilename = os.path.join(OUT_DIR, 'expression-outputs.h5')
    shuffle = True
    if (complib == 'blosc'):
        filters = tb.Filters(complevel=1, complib='blosc', shuffle=shuffle)
    elif (complib == 'lzo'):
        filters = tb.Filters(complevel=1, complib='lzo', shuffle=shuffle)
    elif (complib == 'zlib'):
        filters = tb.Filters(complevel=1, complib='zlib', shuffle=shuffle)
    else:
        filters = tb.Filters(complevel=0, shuffle=False)
    if verbose:
        print('Will use filters:', filters)
    if dowrite:
        f = tb.open_file(ifilename, 'w')
        t0 = time()
        root = f.root
        a = f.create_carray(root, 'a', tb.Float32Atom(), shape, filters=filters)
        b = f.create_carray(root, 'b', tb.Float32Atom(), shape, filters=filters)
        if verbose:
            print('chunkshape:', a.chunkshape)
            print('chunksize:', (np.prod(a.chunkshape) * a.dtype.itemsize))
        row = np.arange(0, ncols, dtype='float32')
        for i in range(nrows):
            a[i] = (row * (i + 1))
            b[i] = ((row * (i + 1)) * 2)
        f.close()
        print('[tables.Expr] Time for creating inputs:', round((time() - t0), 3))
    if docompute:
        f = tb.open_file(ifilename, 'r')
        fr = tb.open_file(ofilename, 'w')
        a = f.root.a
        b = f.root.b
        r1 = dowrite.create_carray(fr.root, 'r1', tb.Float32Atom(), shape, filters=filters)
        e = tb.Expr(expr)
        e.set_output(r1)
        t0 = time()
        e.eval()
        if verbose:
            print('First ten values:', r1[0, :10])
        f.close()
        fr.close()
        print('[tables.Expr] Time for computing & save:', round((time() - t0), 3))

dataset/ETHPy150Open PyTables/PyTables/bench/expression.py tables/VarMisuse@407/533 `f`->`dowrite`