def test_memcpy_dtoh(): a = [1, 2, 3, 4] x = numpy.array(a).astype(numpy.float32) x_c = x.ctypes.data_as(C.POINTER(C.c_float)) output = numpy.zeros_like(x) cfunc = CFunctions() cfunc.arg_mapping = {str(x_c): Argument(str(x.dtype), (4, ))} cfunc.memcpy_dtoh(output, x_c) print(a) print(output) assert all(output == a)
def test_memcpy_dtoh(): a = [1, 2, 3, 4] x = numpy.array(a).astype(numpy.float32) x_c = x.ctypes.data_as(C.POINTER(C.c_float)) arg = Argument(numpy=x, ctypes=x_c) output = numpy.zeros_like(x) cfunc = CFunctions() cfunc.memcpy_dtoh(output, arg) print(a) print(output) assert all(output == a) assert all(x == a)
def test_byte_array_arguments(): arg1 = numpy.array([1, 2, 3]).astype(numpy.int8) cfunc = CFunctions() output = cfunc.ready_argument_list([arg1]) output_arg1 = numpy.ctypeslib.as_array(output[0], shape=arg1.shape) assert output_arg1.dtype == 'int8' assert all(output_arg1 == arg1) dest = numpy.zeros_like(arg1) cfunc.memcpy_dtoh(dest, output[0]) assert all(dest == arg1)
def test_byte_array_arguments(): arg1 = numpy.array([1, 2, 3]).astype(numpy.int8) cfunc = CFunctions() output = cfunc.ready_argument_list([arg1]) output_arg1 = numpy.ctypeslib.as_array(output[0].ctypes, shape=arg1.shape) assert output_arg1.dtype == 'int8' assert all(output_arg1 == arg1) dest = numpy.zeros_like(arg1) cfunc.memcpy_dtoh(dest, output[0]) assert all(dest == arg1)