numpy.random.seed(137) a = nplazy.lazyarray(numpy.random.randint(0, 100, element_count)) start = time.time() d = a * a * a d.materialize() end = time.time() print("Lazy Evaluation (No Intermediates)", end - start) numpy.random.seed(137) a = numpy.random.randint(0, 100, element_count) start = time.time() d = a * a * a end = time.time() print("Eager Evaluation (Many Intermediates)", end - start) import thunklib numpy.random.seed(137) a = thunklib.thunk(numpy.random.randint(0, 100, element_count)) start = time.time() d = a * a * a d.evaluate() end = time.time() print("Pipelined Evaluation", end - start)
import thunklib import numpy dtype_list = [ numpy.dtype('int8'), numpy.dtype('int16'), numpy.dtype('int32'), numpy.dtype('int64'), numpy.dtype('uint8'), numpy.dtype('uint16'), numpy.dtype('uint32'), numpy.dtype('uint64'), numpy.dtype('float32'), numpy.dtype('float64'), numpy.dtype('complex64') ] errors = 0 tests = 0 for dtype in dtype_list: for dtype2 in dtype_list: a = numpy.arange(5, dtype=dtype) b = numpy.arange(5, dtype=dtype2) numpy_result = (a * b).__str__() a = thunklib.thunk(a) b = thunklib.thunk(b) thunk_result = (a * b).__str__() if thunk_result != numpy_result: errors += 1 print("Failed test %s*%s" % (dtype, dtype2)) tests += 1 print("\nFailed %d/%d tests." % (errors, tests) if errors > 0 else "Success!")
import thunklib import numpy a = numpy.arange(5, dtype=numpy.double) b = thunklib.thunk(a) c = b * b print(type(c)) print(c)
import thunklib import numpy import time element_count = 100000000 numpy.random.seed(137) a = thunklib.thunk(numpy.random.randint(0,100,element_count)) start = time.time() d = numpy.sum((a * a * a * a * a).asnumpyarray()) end = time.time() print("NumPy Evaluation", end - start) numpy.random.seed(137) a = thunklib.thunk(numpy.random.randint(0,100,element_count)) start = time.time() d = (a * a * a * a * a).sum() d.evaluate() end = time.time() print("Pipelined Evaluation", end - start)
import numpy import time import thunklib element_count = 100000000 numpy.random.seed(137) a = numpy.random.randint(0, 100, element_count).astype(numpy.float64) b = numpy.random.randint(0, 100, element_count).astype(numpy.float64) start = time.time() d = a * b end = time.time() print("NumPy Evaluation", end - start) numpy.random.seed(137) a = thunklib.thunk( numpy.random.randint(0, 100, element_count).astype(numpy.float64)) b = thunklib.thunk( numpy.random.randint(0, 100, element_count).astype(numpy.float64)) start = time.time() d = a * b d.evaluate() end = time.time() print("Pipelined Evaluation", end - start)
import numpy import thunklib numpy.random.seed(137) a = numpy.random.randint(0, 100, size=(200000, )).astype(numpy.object) b = thunklib.thunk(a * 2) b.sort() c = b numpy.random.seed(137) a = numpy.random.randint(0, 100, size=(200000, )).astype(numpy.object) * 2 a.sort() if numpy.array_equal(a, c.asnumpyarray()): print("Success!") else: print("Failure! Different arrays.") print("NumPy", a) print("Thunk", c.asnumpyarray())
import numpy import thunklib numpy.random.seed(137) a = numpy.random.randint(0, 100, size=(200000,)).astype(numpy.object) b = thunklib.thunk(a * 2) b.sort() c = b numpy.random.seed(137) a = numpy.random.randint(0, 100, size=(200000,)).astype(numpy.object) * 2 a.sort() if numpy.array_equal(a, c.asnumpyarray()): print("Success!") else: print("Failure! Different arrays.") print("NumPy", a) print("Thunk", c.asnumpyarray())
numpy.dtype('int8'), numpy.dtype('int16'), numpy.dtype('int32'), numpy.dtype('int64'), numpy.dtype('uint8'), numpy.dtype('uint16'), numpy.dtype('uint32'), numpy.dtype('uint64'), numpy.dtype('float32'), numpy.dtype('float64'), numpy.dtype('complex64') ] errors = 0 tests = 0 for dtype in dtype_list: for dtype2 in dtype_list: a = numpy.arange(5, dtype=dtype) b = numpy.arange(5, dtype=dtype2) numpy_result = (a * b).__str__() a = thunklib.thunk(a) b = thunklib.thunk(b) thunk_result = (a * b).__str__() if thunk_result != numpy_result: errors += 1 print("Failed test %s*%s" % (dtype, dtype2)) tests += 1 print("\nFailed %d/%d tests." % (errors, tests) if errors > 0 else "Success!")
import numpy import time import thunklib element_count = 100000000 numpy.random.seed(137) a = numpy.random.randint(0,100,element_count).astype(numpy.float64) b = numpy.random.randint(0,100,element_count).astype(numpy.float64) start = time.time() d = a * b end = time.time() print("NumPy Evaluation", end - start) numpy.random.seed(137) a = thunklib.thunk(numpy.random.randint(0,100,element_count).astype(numpy.float64)) b = thunklib.thunk(numpy.random.randint(0,100,element_count).astype(numpy.float64)) start = time.time() d = a * b d.evaluate() end = time.time() print("Pipelined Evaluation", end - start)
import numpy npy = numpy.arange(2048, dtype=numpy.int32) npy2 = numpy.repeat([2], 2048).astype(numpy.int32) import thunklib a = thunklib.thunk(npy) c = thunklib.thunk(npy2) print(a) b = a * c print(b) print(b) print(a) print(c)