<div dir="ltr">Two things that might help you create generalized ufuncs: <div><br></div><div>1) Look at Numba --- it makes it very easy to write generalized ufuncs in simple Python code.  Numba will compile to machine code so it can be as fast as writing in C.   Here is the documentation for that specific feature: <a href="http://numba.pydata.org/numba-doc/0.21.0/user/vectorize.html#the-guvectorize-decorator">http://numba.pydata.org/numba-doc/0.21.0/user/vectorize.html#the-guvectorize-decorator</a>.     One wart of the interface is that scalars need to be treated as 1-element 1-d arrays (but still use '()' in the signature).  <div><br></div><div>2) Look at the linear algebra module in NumPy which now wraps a bunch of linear-algebra based generalized ufuncs (all written in C):  <a href="https://github.com/numpy/numpy/blob/master/numpy/linalg/umath_linalg.c.src">https://github.com/numpy/numpy/blob/master/numpy/linalg/umath_linalg.c.src</a></div><div><br></div><div>-Travis</div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 25, 2015 at 7:06 AM,  <span dir="ltr"><<a href="mailto:eleanore.young@artorg.unibe.ch" target="_blank">eleanore.young@artorg.unibe.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div style="word-wrap:break-word">
Dear Numpy maintainers and developers,<br>
<br>
Thanks for providing such a great numerical library!<br>
<br>
I’m currently trying to implement the Dynamic Time Warping metric as a set of generalised numpy ufuncs, but unfortunately, I have lasting issues with pointer arithmetic and segmentation faults. Is there any way that I can<br>
use GDB or some such to debug a python/numpy extension? Furthermore: is it necessary to use pointer arithmetic to access the function arguments (as seen on <a href="http://docs.scipy.org/doc/numpy/user/c-info.ufunc-tutorial.html" target="_blank">http://docs.scipy.org/doc/numpy/user/c-info.ufunc-tutorial.html</a>)<br>
or is element access (operator[]) also permissible?<br>
<br>
To break it down quickly, I need to have a fast DTW distance function dist_dtw() with two vector inputs (broadcasting should be possible), two scalar parameters and one scalar output (signature: (i), (j), (), () -> ()) usable in python for a 1-Nearest Neighbor
 classification algorithm. The extension also implements two functions compute_envelope() and piecewise_mean_reduction() which are used for lower-bounding based on Keogh and Ratanamahatana, 2005. The source code is available at <a href="http://pastebin.com/MunNaP7V" target="_blank">http://pastebin.com/MunNaP7V</a> and
 the prominent segmentation fault happens somewhere in the chain dist_dtw() —> meta_dtw_dist() —> slow_dtw_dist(), but I fail to pin it down.<br>
<br>
Aside from my primary questions, I wonder how to approach errors/exceptions and unit testing when developing numpy ufuncs. Are there any examples apart from the numpy manual that I could use as reference implementations of generalised numpy ufuncs?<br>
<br>
I would greatly appreciate some insight into properly developing generalised ufuncs.<br>
<br>
Best,<br>
Eleanore<br>
<br>
</div>

<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><b><br>Travis Oliphant</b></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><i>Co-founder and CEO</i></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><i><br></i></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><img src="https://docs.google.com/a/continuum.io/uc?id=0B8_D9l6ZUhNIaF9HbGZSV09TNHc&export=download" width="200" height="37"></div></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><br></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)">@teoliphant</div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)">512-222-5440</div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><a href="http://www.continuum.io" target="_blank">http://www.continuum.io</a></div></div></div></div></div></div>
</div>