Generalized Ufuncs
==================

.. raw:: html

	<p>The <cite>GUFuncVectorize</cite> module of NumbaPro creates a fast &#8220;generalized ufunc&#8221; from Numba-compiled code.
	Traditional ufuncs perform element-wise operations, whereas generalized ufuncs operate on entire
	sub-arrays. Unlike other NumbaPro Vectorize classes, the GUFuncVectorize constructor takes
	an additional signature of the generalized ufunc.</p>
	<div class="section" id="imports">
	<h2>Imports<a class="headerlink" href="#imports" title="Permalink to this headline">¶</a></h2>
	<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">numbapro</span> <span class="kn">import</span> <span class="n">float32</span><span class="p">,</span> <span class="n">float64</span><span class="p">,</span> <span class="n">int32</span>
	<span class="kn">from</span> <span class="nn">numbapro</span> <span class="kn">import</span> <span class="n">guvectorize</span>
	<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
	</pre></div>
	</div>
	<p>Basic generalized ufuncs are available in Numba. In addition to the basic generalized
	ufuncs, NumbaPro provides a CUDA-accelerated generalized ufunc.</p>
	<dl class="function">
	<dt id="numbapro.guvectorize">
	<code class="descclassname">numbapro.</code><code class="descname">guvectorize</code><span class="sig-paren">(</span><em>ftylist</em>, <em>signature</em>, <em>target='cpu'</em>, <em>identity=None</em>, <em>**kws</em><span class="sig-paren">)</span><a class="headerlink" href="#numbapro.guvectorize" title="Permalink to this definition">¶</a></dt>
	<dd><p>A decorator to create numpy generialized-ufunc object from Numba compiled
	code.</p>
	<table class="docutils field-list" frame="void" rules="none">
	<col class="field-name" />
	<col class="field-body" />
	<tbody valign="top">
	<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
	<li><strong>ftylist</strong> (<em>iterable</em>) &#8211; An iterable of type signatures, which are either
	function type object or a string describing the
	function type.</li>
	<li><strong>signature</strong> (<em>str</em>) &#8211; A NumPy generialized-ufunc signature.
	e.g. &#8220;(m, n), (n, p)-&gt;(m, p)&#8221;</li>
	<li><strong>identity</strong> (<em>int, str, or None</em>) &#8211; The identity (or unit) value for the element-wise function
	being implemented.  Allowed values are None (the default), 0, 1,
	and &#8220;reorderable&#8221;.</li>
	<li><strong>target</strong> (<em>str</em>) &#8211; A string for code generation target.  Defaults to &#8220;cpu&#8221;.</li>
	</ul>
	</td>
	</tr>
	<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"></p>
	</td>
	</tr>
	<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">A NumPy generialized universal-function</p>
	</td>
	</tr>
	</tbody>
	</table>
	<p class="rubric">Example</p>
	<dl class="docutils">
	<dt>&#64;guvectorize([&#8216;void(int32[:,:], int32[:,:], int32[:,:])&#8217;,</dt>
	<dd>&#8216;void(float32[:,:], float32[:,:], float32[:,:])&#8217;],
	&#8216;(x, y),(x, y)-&gt;(x, y)&#8217;)</dd>
	<dt>def add_2d_array(a, b):</dt>
	<dd><dl class="first last docutils">
	<dt>for i in range(c.shape[0]):</dt>
	<dd><dl class="first last docutils">
	<dt>for j in range(c.shape[1]):</dt>
	<dd>c[i, j] = a[i, j] + b[i, j]</dd>
	</dl>
	</dd>
	</dl>
	</dd>
	</dl>
	</dd></dl>

	<p>To see how generalized ufuncs work, we refer the reader to
	<a class="reference external" href="http://numba.pydata.org/numba-doc/dev/arrays.html#generalized-ufunc-definition">Numba gufuncs</a>.</p>
	</div>
	<div class="section" id="generalized-cuda-ufuncs">
	<h2>Generalized CUDA ufuncs<a class="headerlink" href="#generalized-cuda-ufuncs" title="Permalink to this headline">¶</a></h2>
	<p>Generalized ufuncs may also be executed on the GPU using CUDA, analogous to the CUDA ufunc functionality.
	Jump to the <a class="reference external" href="CUDAufunc.html">documentation for CUDA ufunc</a> for continued discussion on generalized ufuncs.</p>
