def test_execution(): a = NDArray([1, 2, 3, 4], datashape('4, float32')) b = NDArray([5, 6, 7, 8], datashape('4, float32')) c = NDArray([9, 10, 11, 12], datashape('4, float32')) out = NDArray([0, 0, 0, 0], datashape('4, float32')) graph = a + b * c out[:] = graph print list(out.data.ca)
def test_conversion(): a = NDArray([1, 2, 3, 4], datashape('2, 2, int32')) b = NDArray([5, 6, 7, 8], datashape('2, 2, float32')) c = NDArray([9, 10, 11, 12], datashape('2, 2, int32')) graph = a + b * c result_graph, executors = convert_graph(graph) assert result_graph.spine.label == 'Executor', result_graph.spine assert len(executors) == 1 executor_id, executor = executors.popitem()
def test_conversion(): """ >>> test_conversion() [LLVMExecutor(chunked, (op0 + (op1 * op2)))('%0' '%1' '%2')] ['%0', '%1', '%2'] """ a = NDArray([1, 2, 3, 4], datashape('2, 2, int32')) b = NDArray([5, 6, 7, 8], datashape('2, 2, float32')) c = NDArray([9, 10, 11, 12], datashape('2, 2, int32')) graph = a + b * c instructions, executors, symbols = convert_graph(graph) assert len(instructions) == len(executors) == 1 print instructions print sorted(symbols)
def test_execution(): """ >>> test_execution() [ 46. 62. 80. 100.] """ a = NDArray([1, 2, 3, 4], datashape('4, float32')) b = NDArray([5, 6, 7, 8], datashape('4, float32')) c = NDArray([9, 10, 11, 12], datashape('4, float32')) out = NDArray([0, 0, 0, 0], datashape('4, float32')) graph = a + b * c out[:] = graph # print list(out.data.ca), hex(out.data.ca.leftover_array.ctypes.data) # print "*" * 100 # print out.data.ca.leftover_array.dtype print out.data.ca
def get_datashape(dshape_aterm): "Assemble datashape from aterm dshape" args = [] for arg in dshape_aterm.args: if isinstance(arg, paterm.AInt): args.append(arg.n) elif isinstance(arg, paterm.AString): args.append(arg.s) else: raise NotImplementedError return datashape(*args)
def get_datashape(term): "Assemble datashape from aterm dshape" type = term.annotation.ty args = [] for arg in type.args: if isinstance(arg, paterm.AInt): args.append(arg.n) elif isinstance(arg, paterm.AString): args.append(arg.s) else: raise NotImplementedError return datashape(*args)
def unannotate_dtype(aterm): """ Takes a term with a datashape annotation and returns the NumPy dtype associate with it >>> term x{dshape("2, 2, int32")} >>> unannotate_dtype(term) int32 """ # unpack the annotation {'s': 'int32'} unpack = paterm.matches('dshape(s);*', aterm.annotation['type']) ds_str = unpack['s'] dshape = datashape(ds_str.s) dtype = coretypes.to_dtype(dshape) return dtype
dtype associate with it >>> term x{dshape("2, 2, int32")} >>> unannotate_dtype(term) int32 """ # unpack the annotation {'s': 'int32'} unpack = paterm.matches('dshape(s);*', aterm.annotation['type']) ds_str = unpack['s'] dshape = datashape(ds_str.s) dtype = coretypes.to_dtype(dshape) return dtype def minitype(dtype): return minitypes.map_dtype(dtype) def substitute_llvm_executors(aterm_graph, executors): translator = ATermToAstTranslator(executors) return translator.visit(aterm_graph) if __name__ == '__main__': a = NDArray([1, 2, 3, 4], datashape('2, 2, int')) ops, funcdef = convert_graph(a + a) # print getsource(funcdef) # print result # import doctest # doctest.testmod()