49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
|
import sys
|
||
|
import time
|
||
|
import pickle
|
||
|
|
||
|
import numpy as np
|
||
|
|
||
|
import interp.bootstrap
|
||
|
from interp.grid.delaunay import dgrid
|
||
|
from interp.tools import improved_answer, friendly_exact_3D as exact
|
||
|
|
||
|
|
||
|
def test_success(rcount, count):
|
||
|
v = np.random.random((rcount, 3)) * 10
|
||
|
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:
|
||
|
outside += 1
|
||
|
|
||
|
print "total skipped points: %d" % outside
|
||
|
return results
|
||
|
|
||
|
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:])
|
||
|
print test_success(rcount, int(count))
|