Using FXP for fixed point input to c functions #22
Replies: 2 comments 4 replies
-
Hello @chrisbaldwin2, It would be nice if you provide an example of your problem. |
Beta Was this translation helpful? Give feedback.
-
Doing a quick review of the code, I think the problem is in how arguments are passed to C function. When: c_lib.c_start(x, y_c)
c_lib.c_start(x(), y_c()) # equivalent to c_lib.c_start(x.get_val(), y_c.get_val()) The code above is passing numpy arrays to your C function. It could be also a problem if your C function can't handle ndarray also. In that case you can send python lists just like: c_lib.c_start(x().tolist(), y_c().tolist()) The problem of doing all of this is new objects are created (ndarray or list). So, your pointer are pointing to new objects. A workar around could be: x_ptr = x() # or x_ptr = x().tolist()
y_c_ptr = y_c()
c_lib.c_start(x_ptr, y_c_ptr)
x(x_ptr)
y_c(y_c_ptr) An alternative approach is to return the array modified from C function, so: y_c.equal(lib.c_start(x(), y_c())) A little more elegant :) |
Beta Was this translation helpful? Give feedback.
-
I am using your FXP library for fixed point python and loving it! I am currently working on a tool to translate python to RTL but need some help. I am trying to pass arrays of fixed point values to c functions, but am getting caught with TypeErrors. I am using Vivado's ap_fixed.h library on the C side. I have tried using wrapper functions but would love to see if any of you have tried this.
Please feel free to reach out by email at [email protected]
Beta Was this translation helpful? Give feedback.
All reactions