<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 11.03.2015 um 23:18 schrieb Dp Docs <<a href="mailto:sdpan21@gmail.com" class="">sdpan21@gmail.com</a>>:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><br class="">On Wed, Mar 11, 2015 at 10:34 PM, Gregor Thalhammer <<a href="mailto:gregor.thalhammer@gmail.com" class="">gregor.thalhammer@gmail.com</a>> wrote:<br class="">><br class="">><br class="">> On the scipy mailing list I also answered to Amine, who is also interested in this proposal.<div class=""><div class="gmail_default" style="font-family:verdana,sans-serif">​​ Can you provide the link of that discussion? I am getting trouble in searching that.</div><br class=""></div><div class=""><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">​>​</div>Long time ago I wrote a package that <div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">​</div><div class=""><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">>​</div>provides fast math functions (ufuncs) for numpy, using Intel’s MKL/VML library, see  <a href="https://github.com/geggo/uvml" class="">https://github.com/geggo/uvml</a> and my comments <div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">​>​</div>there. This code could be easily ported to use other vector math libraries.</div><div class=""><br class=""></div><div class=""><div class="gmail_default" style="font-family:verdana,sans-serif">​When MKL is not available for a System, will this integration work with default numpy maths functions?</div><div class="gmail_default" style="font-family:verdana,sans-serif">​</div></div><div class=""><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">​>​</div> Would be interesting to evaluate other possibilities. Due to <div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">​>​</div>the fact that MKL is non-free, there are concerns to use it with numpy, <div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">​>​</div>although e.g. numpy and scipy using the MKL LAPACK <div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">​>​</div>routines are used frequently (Anaconda or Christoph Gohlkes  binaries). <br class="">><br class="">> You can easily inject the fast math ufuncs into numpy, e.g. with set_numeric_ops() or np.sin = vml.sin. </div><div class=""><div class="gmail_default" style="font-family:verdana,sans-serif"><br class=""></div><div class="gmail_default" style="font-family:verdana,sans-serif">​Can you explain in a bit detail or provide a link where i can see it?​</div></div></div></div></div></blockquote><div><br class=""></div><div>My approach for <a href="https://github.com/geggo/uvml" class="">https://github.com/geggo/uvml</a> was to provide a separate python extension that provides faster numpy ufuncs for math operations like exp, sin, cos, … To replace the standard numpy ufuncs by the optimized ones you don’t need to apply changes to the source code of numpy, instead at runtime you monkey patch it and get faster math everywhere. Numpy even offers an interface (set_numeric_ops) to modify it at runtime. </div><div><br class=""></div><div>Another note, numpy makes it easy to provide new ufuncs, see </div><div><a href="http://docs.scipy.org/doc/numpy-dev/user/c-info.ufunc-tutorial.html" class="">http://docs.scipy.org/doc/numpy-dev/user/c-info.ufunc-tutorial.html</a></div><div>from a C function that operates on 1D arrays, but this function needs to support arbitrary spacing (stride) between the items. Unfortunately, to achieve good performance, vector math libraries often expect that the items are laid out contiguously in memory. MKL/VML is a notable exception. So for non contiguous in- or output arrays you might need to copy the data to a buffer, which likely kills large amounts of the performance gain. This does not completely rule out some of the libraries, since performance critical data is likely to be stored in contiguous arrays.</div><div><br class=""></div><div>Using a library that supports only vector math for contiguous arrays is more difficult, but perhaps the numpy nditer provides everything needed. </div><div><br class=""></div><div>Gregor</div></div></body></html>