def execute_datadescriptor_ooc_2(dd, res_name=None): res_ds = dd.dshape res_shape, res_dt = to_numpy(dd.dshape) lifted = dd.kerneltree._fused.kernel.lift(1,'C') cf = lifted.ctypes_func res_ctype = cf.argtypes[-1]._type_ args = [(ct._type_, arr.arr._data.element_reader(1), arr.arr.dshape.shape[1:]) for ct, arr in izip(cf.argtypes[:-1], dd.args)] res_dd = BLZDataDescriptor(blz.zeros((0,) + res_shape[1:], dtype = res_dt, rootdir = res_name)) with res_dd.element_appender() as dst: for i in xrange(res_shape[0]): # advance sources tpl = (i,) cf_args = [_mk_array_c_ref(t, er.read_single(tpl), sh) for t, er, sh in args ] with dst.buffered_ptr() as dst_ptr: cf_args.append(_mk_array_c_ref(res_ctype, dst_ptr, res_shape[1:])) cf(*cf_args) return blaze.Array(res_dd)
def execute_datadescriptor_ooc(dd, res_name=None): # only lift by one res_ds = dd.dshape res_shape, res_dt = to_numpy(dd.dshape) lifted = dd.kerneltree._fused.kernel.lift(1,'C') cf = lifted.ctypes_func # element readers for operands args = [(ct._type_, arr.arr._data.element_reader(1), arr.arr.dshape.shape[1:]) for ct, arr in izip(cf.argtypes[:-1], dd.args)] res_dd = BLZDataDescriptor(blz.zeros((0,) + res_shape[1:], dtype = res_dt, rootdir = res_name)) res_ct = ctypes.c_double*3 res_buffer = res_ct() res_buffer_entry = (cf.argtypes[-1]._type_, ctypes.pointer(res_buffer), res_shape[1:]) with res_dd.element_appender() as ea: for i in xrange(res_shape[0]): args_i = [(t, er.read_single((i,)), sh) for t, er, sh in args] args_i.append(res_buffer_entry) cf_args = [_convert(*foo) for foo in args_i] cf(*[ctypes.byref(x) for x in cf_args]) ea.append(ctypes.addressof(res_buffer),1) return blaze.Array(res_dd)