smbinterp/bin/dgrid_bench.py

50 lines
1.1 KiB
Python

import sys
import time
import pickle
import numpy as np
from optparse import OptionParser
import interp.bootstrap
from interp.grid.delaunay import dgrid
from interp.tools import improved_answer, friendly_exact_3D as exact
if __name__ == '__main__':
if len(sys.argv) != 3:
print >> sys.stderr, "usage: %s <number of random points> <number of attempted interps>" % sys.argv[0]
sys.exit(1)
rcount, count = (int(i) for i in sys.argv[1:])
v = np.random.random((rcount, 3))
pickle.dump(v, open('/tmp/v.p', 'w'))
q = np.array([exact(x) for x in v])
start = time.time()
g = dgrid(v,q)
end = time.time()
print "cells: %d, verts: %d" % (len(g.cells), len(g.verts))
print end - start, " seconds to instantiate the dgrid object"
results = {True:0, False:0}
i = 0
outside = 0
while i < count:
try:
X = np.random.random((1,3))[0]
a = g.run_baker(X, order = 3, extra_points = 32)
e = exact(X)
results[improved_answer(a, e)] += 1
i += 1
except Exception as e:
print e
outside += 1
print "total skipped points: %d" % outside
print results