Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from cffi import FFI
- import numpy as np
- ffi = FFI()
- ffi.cdef("""
- void test_numpy_array(unsigned long size, float *data, float* (*resize)(int args...);
- """)
- C = ffi.dlopen("rust-lib/target/debug/libdata_reader.so")
- commData = C.init()
- def resize(array, *args):
- shape = tuple(args)
- array = np.resize(array, shape)
- return ffi.cast("float *", ffi.from_buffer(array))
- def curry_resize(array):
- def inner(*shape):
- resize(array, *shape)
- return inner
- arr = np.empty((2,3,4), dtype=np.float32)
- cptr = ffi.cast("float *", ffi.from_buffer(arr))
- callback = curry_resize(arr)
- ffi.callback("float *(int...)", callback)
- C.test_numpy_array(2*3*4, cptr, callback)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement