<div dir="ltr"><div><div><div><div><div><div><div><div><div>All,<br></div><br></div>I have a C function func that takes in scalar arguments, and an array of fixed dimension that is modified in place to provide the output. The prototype is something like:<br>
<br></div>`void func(double a, double b, double c, double *arr);`<br><br></div>I've wrapped this in Cython and called it from python with no problem. What I'd like to do now though is get it set up to broadcast over the input arguments and return a 3 dimensional array of the results. By this I mean<br>
<br></div>a = array([1, 2, 3])<br></div>b = array([2.0, 3.0, 4.0])<br></div>c = array([3, 4, 5])<br><br></div><div>func(a, b, c) -> a 3d array containing the results of func for (a, b, c) = (1, 2.0, 3), (2, 3.0, 4), (3, 4.0, 5)<br>
</div><div><br></div>I'm not sure if this would qualify as a ufunc, as the result of one function call isn't a scalar but an array, but the effect I'm looking for is similar. Ideally it would handle datatype conversions (in the above `a` and `c` aren't double, but `func` takes in double). It would also be awesome to allow an argument to be a scalar and not an array, and have it be broadcast as if it were. <br>
<br>I'm just wondering what the best way for me to hook my code up to the internals of numpy and get this kind of behavior in an efficient way. I've read the "writing your own ufunc" part of the docs, but am unsure if what I'm looking for qualifies. Note that I can change the inner workings of `func` if this is required to achieve this behavior.<br>
<br></div>Thanks!<br></div>