/usr/share/doc/python-tables-doc/bench/blosc.py is in python-tables-doc 3.1.1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | from __future__ import print_function
import os
import sys
from time import time
import numpy as np
import tables as tb
niter = 3
dirname = "/scratch2/faltet/blosc-data/"
#expression = "a**2 + b**3 + 2*a*b + 3"
#expression = "a+b"
#expression = "a**2 + 2*a/b + 3"
#expression = "(a+b)**2 - (a**2 + b**2 + 2*a*b) + 1.1"
expression = "3*a-2*b+1.1"
shuffle = True
def create_file(kind, prec, synth):
prefix_orig = 'cellzome/cellzome-'
iname = dirname + prefix_orig + 'none-' + prec + '.h5'
f = tb.open_file(iname, "r")
if prec == "single":
type_ = tb.Float32Atom()
else:
type_ = tb.Float64Atom()
if synth:
prefix = 'synth/synth-'
else:
prefix = 'cellzome/cellzome-'
for clevel in range(10):
oname = '%s/%s-%s%d-%s.h5' % (dirname, prefix, kind, clevel, prec)
# print "creating...", iname
f2 = tb.open_file(oname, "w")
if kind in ["none", "numpy"]:
filters = None
else:
filters = tb.Filters(
complib=kind, complevel=clevel, shuffle=shuffle)
for name in ['maxarea', 'mascotscore']:
col = f.get_node('/', name)
r = f2.create_carray('/', name, type_, col.shape, filters=filters)
if synth:
r[:] = np.arange(col.nrows, dtype=type_.dtype)
else:
r[:] = col[:]
f2.close()
if clevel == 0:
size = 1.5 * float(os.stat(oname)[6])
f.close()
return size
def create_synth(kind, prec):
prefix_orig = 'cellzome/cellzome-'
iname = dirname + prefix_orig + 'none-' + prec + '.h5'
f = tb.open_file(iname, "r")
if prec == "single":
type_ = tb.Float32Atom()
else:
type_ = tb.Float64Atom()
prefix = 'synth/synth-'
for clevel in range(10):
oname = '%s/%s-%s%d-%s.h5' % (dirname, prefix, kind, clevel, prec)
# print "creating...", iname
f2 = tb.open_file(oname, "w")
if kind in ["none", "numpy"]:
filters = None
else:
filters = tb.Filters(
complib=kind, complevel=clevel, shuffle=shuffle)
for name in ['maxarea', 'mascotscore']:
col = f.get_node('/', name)
r = f2.create_carray('/', name, type_, col.shape, filters=filters)
if name == 'maxarea':
r[:] = np.arange(col.nrows, dtype=type_.dtype)
else:
r[:] = np.arange(col.nrows, 0, dtype=type_.dtype)
f2.close()
if clevel == 0:
size = 1.5 * float(os.stat(oname)[6])
f.close()
return size
def process_file(kind, prec, clevel, synth):
if kind == "numpy":
lib = "none"
else:
lib = kind
if synth:
prefix = 'synth/synth-'
else:
prefix = 'cellzome/cellzome-'
iname = '%s/%s-%s%d-%s.h5' % (dirname, prefix, kind, clevel, prec)
f = tb.open_file(iname, "r")
a_ = f.root.maxarea
b_ = f.root.mascotscore
oname = '%s/%s-%s%d-%s-r.h5' % (dirname, prefix, kind, clevel, prec)
f2 = tb.open_file(oname, "w")
if lib == "none":
filters = None
else:
filters = tb.Filters(complib=lib, complevel=clevel, shuffle=shuffle)
if prec == "single":
type_ = tb.Float32Atom()
else:
type_ = tb.Float64Atom()
r = f2.create_carray('/', 'r', type_, a_.shape, filters=filters)
if kind == "numpy":
a2, b2 = a_[:], b_[:]
t0 = time()
r = eval(expression, {'a': a2, 'b': b2})
print("%5.2f" % round(time() - t0, 3))
else:
expr = tb.Expr(expression, {'a': a_, 'b': b_})
expr.set_output(r)
expr.eval()
f.close()
f2.close()
size = float(os.stat(iname)[6]) + float(os.stat(oname)[6])
return size
if __name__ == '__main__':
if len(sys.argv) > 3:
kind = sys.argv[1]
prec = sys.argv[2]
if sys.argv[3] == "synth":
synth = True
else:
synth = False
else:
print("3 parameters required")
sys.exit(1)
# print "kind, precision, synth:", kind, prec, synth
# print "Creating input files..."
size_orig = create_file(kind, prec, synth)
# print "Processing files for compression levels in range(10)..."
for clevel in range(10):
t0 = time()
ts = []
for i in range(niter):
size = process_file(kind, prec, clevel, synth)
ts.append(time() - t0)
t0 = time()
ratio = size_orig / size
print("%5.2f, %5.2f" % (round(min(ts), 3), ratio))
|