What I haven’t decided on is whether the Python wrappers should adhere to the same format as the corresponding C library functions or if they should be more “Pythonic” for example, the C library version of vec_add has the signature
void vec_add(double* out, double* x, double* y, int N);
whereas I've written the Python wrapper homework2.vec_add to have the signature
def vec_add(x, y):
# return the sum of x and y by calling the C vec_add function via ctypes
The wrapper hides the fact that memory is being edited in-place. The current definition, in fact, creates an empty solution array which is then "passed" to the underlying C function.
Would it be clearer / better to have the Python wrapper signature be identical to the C function signature? The answer to "clearer" is not necessarily the same as the answer to "better". For this class I'm not sure how much time I can spend on Python's ctypes. If I shove it under the rug then the answer might change.
Anyway, a penny for your thoughts. I think I'm in favor of the former technique as opposed to the verbose latter technique even if it does hide the C-side.
What I haven’t decided on is whether the Python wrappers should adhere to the same format as the corresponding C library functions or if they should be more “Pythonic” for example, the C library version of
vec_addhas the signaturewhereas I've written the Python wrapper
homework2.vec_addto have the signatureThe wrapper hides the fact that memory is being edited in-place. The current definition, in fact, creates an empty solution array which is then "passed" to the underlying C function.
Would it be clearer / better to have the Python wrapper signature be identical to the C function signature? The answer to "clearer" is not necessarily the same as the answer to "better". For this class I'm not sure how much time I can spend on Python's ctypes. If I shove it under the rug then the answer might change.
Anyway, a penny for your thoughts. I think I'm in favor of the former technique as opposed to the verbose latter technique even if it does hide the C-side.