

def memmap(docompute, dowrite, verbose):
    afilename = os.path.join(OUT_DIR, 'memmap-a.bin')
    bfilename = os.path.join(OUT_DIR, 'memmap-b.bin')
    rfilename = os.path.join(OUT_DIR, 'memmap-output.bin')
    if dowrite:
        t0 = time()
        a = np.memmap(afilename, dtype='float32', mode='w+', shape=shape)
        b = np.memmap(bfilename, dtype='float32', mode='w+', shape=shape)
        row = np.arange(0, ncols, dtype='float32')
        for i in range(nrows):
            a[i] = (row * (i + 1))
            b[i] = ((row * (i + 1)) * 2)
        del a, b
        print('[numpy.memmap] Time for creating inputs:', round((time() - t0), 3))
    if docompute:
        t0 = time()
        a = np.memmap(afilename, dtype='float32', mode='r', shape=shape)
        b = np.memmap(bfilename, dtype='float32', mode='r', shape=shape)
        r = np.memmap(rfilename, dtype='float32', mode='w+', shape=shape)
        for i in range(nrows):
            r[i] = eval(expr, {
                'a': a[i],
                'b': b[i],
            })
        if verbose:
            print('First ten values:', r[0, :10])
        del a, b
        del r
        print('[numpy.memmap] Time for compute & save:', round((time() - t0), 3))

dataset/ETHPy150Open PyTables/PyTables/bench/expression.py memmap/original