def bench_ifft(): name = 'ifft' print("computing {}".format(name), end="", flush=True) fix_num = 1 for dim in shapes : for shape in dim : for module in modules: m = importlib.import_module(module) data = gen_data(numpy, numpy.random.random, shape) data = m.asarray(data) if module is 'scipy': res, rt = run_benchmark(m, m.fft.ifft, data) else: res, rt = run_benchmark(m, m.fft.ifft, data) if module is 'numpy': res_np = res elif module is 'nlcpy': res_vp = res elif module is 'scipy': res_sp = res set_dict(module, name, rt, shape) print(".", end="", flush=True) numpy.testing.assert_allclose(res_np, res_vp) numpy.testing.assert_allclose(res_np, res_sp) write_runtime(name, str(fix_num)) fix_num += 1 cleanup_dict() print("done", flush=True)
def bench_solve(): print("computing solve", end="", flush=True) for shape in shapes: for module in modules: m = importlib.import_module(module) data1 = gen_data(numpy, numpy.random.random, shape) data2 = gen_data(numpy, numpy.random.random, shape) data1 = m.asarray(data1) data2 = m.asarray(data2) res, rt = run_benchmark(m, m.linalg.solve, (data1, data2)) if module is 'numpy': res_np = res elif module is 'nlcpy': res_vp = res set_dict(module, 'solve\nlinear equation', data1.nbytes, rt) print(".", end="", flush=True) numpy.testing.assert_allclose(res_np, res_vp, atol=1e-6) print("done", flush=True)
def bench_std(): print("computing std", end="", flush=True) for shape in shapes: for module in modules: m = importlib.import_module(module) data = gen_data(numpy, numpy.random.random, shape) data = m.asarray(data) res, rt = run_benchmark(m, m.std, data) if module is 'numpy': res_np = res elif module is 'nlcpy': res_vp = res set_dict(module, 'standard\ndeviation', data.nbytes, rt) print(".", end="", flush=True) numpy.testing.assert_allclose(res_np, res_vp) print("done", flush=True)
def bench_fft(): print("computing fft", end="", flush=True) for shape in shapes: for module in modules: m = importlib.import_module(module) data = gen_data(numpy, numpy.random.random, shape) data = m.asarray(data) res, rt = run_benchmark(m, m.fft.fft, data) if module is 'numpy': res_np = res elif module is 'nlcpy': res_vp = res set_dict(module, 'multiple\n1-D fft', data.nbytes, rt) print(".", end="", flush=True) numpy.testing.assert_allclose(res_np, res_vp) print("done", flush=True)
def bench_matmul(): compute_func = lambda data: data @ data print("computing matmul", end="", flush=True) for shape in shapes: for module in modules: m = importlib.import_module(module) data = gen_data(numpy, numpy.random.random, shape) data = m.asarray(data) res, rt = run_benchmark(m, compute_func, data) if module is 'numpy': res_np = res elif module is 'nlcpy': res_vp = res set_dict(module, 'matrix\nmultiplication', data.nbytes, rt) print(".", end="", flush=True) numpy.testing.assert_allclose(res_np, res_vp) print("done", flush=True)
def bench_unary(): for op in unary_ops: print("computing {}".format(op), end="", flush=True) for shape in shapes: for module in modules: m = importlib.import_module(module) compute_func = getattr(m, op) data = gen_data(numpy, numpy.random.random, shape) data = m.asarray(data) if op in not_float_ops: data = data.astype(dtype=int) res, rt = run_benchmark(m, compute_func, data, is_binary=False) if module is 'numpy': res_np = res elif module is 'nlcpy': res_vp = res set_dict(module, op, data.nbytes, rt) print(".", end="", flush=True) numpy.testing.assert_allclose(res_np, res_vp) print("done", flush=True)