def test_memcpy_htod(): a = [1, 2, 3, 4] src = numpy.array(a).astype(numpy.float32) x = numpy.zeros_like(src) x_c = x.ctypes.data_as(C.POINTER(C.c_float)) arg = Argument(numpy=x, ctypes=x_c) cfunc = CFunctions() cfunc.memcpy_htod(arg, src) assert all(arg.numpy == 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)) 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_memset(): 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) cfunc = CFunctions() cfunc.memset(arg, 0, x.nbytes) output = numpy.ctypeslib.as_array(x_c, shape=(4, )) print(output) assert all(output == numpy.zeros(4)) assert all(x == numpy.zeros(4))
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)