Continuum Analytics: Documentation

# Generalized Ufuncs

The GUFuncVectorize module of NumbaPro creates a fast “generalized ufunc” 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.

## Imports

    from numbapro import float32, float64, int32
    from numbapro import guvectorize
    import numpy as np

Basic generalized ufuncs are available in Numba. In addition to the basic generalized ufuncs, NumbaPro provides a CUDA-accelerated generalized ufunc.

`numbapro.``guvectorize`(ftylist, signature, target='cpu', identity=None, **kws)

  A decorator to create numpy generialized-ufunc object from Numba compiled code.

  Parameters:

  - ftylist (iterable) – An iterable of type signatures, which are either function type object or a string describing the function type.
  - signature (str) – A NumPy generialized-ufunc signature. e.g. “(m, n), (n, p)->(m, p)”
  - identity (int, str, or None) – The identity (or unit) value for the element-wise function being implemented. Allowed values are None (the default), 0, 1, and “reorderable”.
  - target (str) – A string for code generation target. Defaults to “cpu”.

  Returns: |
  Return type: | A NumPy generialized universal-function

  Example

  @guvectorize([‘void(int32[:,:], int32[:,:], int32[:,:])’,
    ‘void(float32[:,:], float32[:,:], float32[:,:])’], ‘(x, y),(x, y)->(x, y)’)
  def add_2d_array(a, b):
    for i in range(c.shape[0]):
      for j in range(c.shape[1]):
        c[i, j] = a[i, j] + b[i, j]

To see how generalized ufuncs work, we refer the reader to Numba gufuncs.

## Generalized CUDA ufuncs

Generalized ufuncs may also be executed on the GPU using CUDA, analogous to the CUDA ufunc functionality. Jump to the documentation for CUDA ufunc for continued discussion on generalized ufuncs.