Reputation: 309
I am using Cython to wrap some C code. This is the declaration of a typical routine (the actual ones involve about 13 to 17 arguments).
void my_func(double *__restrict__ lhs, const int xlhs, const int oxlhs);
Right now, in the .pyx file this is how I define the wrapper
def preCond1D(np.ndarray[double, ndim=2] lhs not None, xlhs not None, oxlhs not None):
preCond1D_func( <double*> np.PyArray_DATA(lhs), xlhs, oxlhs)
Would there be any benefit (performance or otherwise) if instead I explicitly declare (i.e. typing) the int variables, as
def preCond1D(np.ndarray[double, ndim=2] lhs, xlhs: cython.int32, oxlhs: cython.int32):
preCond1D_func( <double*> np.PyArray_DATA(lhs), xlhs, oxlhs)
Upvotes: 1
Views: 135
Reputation: 30929
Cython does use type hints, so generally they are useful. You can control this by the annotation_typing
directive.
In this case though they'll make absolutely no difference. You will get exactly one set of data conversions from Python values to C types. With the type hints they'll happen right at the start of preCond1D
. Without the type hints they'll happen at the call to preCond1D_func
.
The only benefit would be the documentation that the type hints provide.
Upvotes: 1