Created
December 20, 2019 18:37
-
-
Save michelp/8844418f749079aaafe1993bc40a4921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BF_tuple = Record.make_c_struct([ | |
('w', double), | |
('h', uint64), | |
('pi', uint64), | |
]) | |
src = """ | |
typedef struct BF_tuple { | |
double w; | |
uint64_t h; | |
uint64_t pi; | |
} BF_tuple; | |
typedef double (*bf_lmin)(BF_tuple*); | |
""" | |
f = FFI() | |
f.cdef(src) | |
data = f.new('BF_tuple[1]') | |
ptr = f.cast('BF_tuple*', data) | |
ptr[0].w = 0.1 | |
ptr[0].h = 0 | |
ptr[0].pi = 1 | |
from numba import cffi_support | |
cffi_support.map_type(f.typeof('BF_tuple'), use_record_dtype=True) | |
sig = cffi_support.map_type(f.typeof('bf_lmin'), use_record_dtype=True) | |
from numba import cfunc, carray | |
@cfunc(sig) | |
def bf_lmin(z_): | |
z = carray(z_, 1)[0] | |
return z.w | |
# if (x[0].w[0] < y.w | |
# or (x.w == y.w and x.h < y.h) | |
# or (x.w == y.w and x.h == y.h and x.pi < y.pi)): | |
# if (z != x): | |
# z[0] = x[0] | |
# else: | |
# z[0] = y[0] | |
addr = int(f.cast('size_t', ptr)) | |
print("address of data:", hex(addr)) | |
bf_lmin.ctypes(addr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment