Universal Functions

Numba provides a set of decorators to create NumPy universal functions-like routines that are JIT compiled. Although, a close analog to NumPy universal functions Numba’s @vectorize are not fully compatible with a regular NumPy ufunc.. Refer Creating NumPy universal functions for details.

numba.vectorize decorator is supported. numba.guvectorize decorator is not supported yet. Another present limitation is that ufunc kernels cannot invoke numba_dpex.kernel functions. Ongoing work is in progress to address these limitations.

Example 1: Basic Example

Full example can be found at numba_dpex/examples/vectorize.py.

@vectorize(nopython=True)
def ufunc_kernel(x, y):
    return x + y

Example 2: Calling numba.vectorize inside a numba_dpex.kernel

Full example can be found at numba_dpex/examples/blacksholes_njit.py.

@numba.vectorize(nopython=True)
def cndf2(inp):
    out = 0.5 + 0.5 * math.erf((math.sqrt(2.0) / 2.0) * inp)
    return out

Note

numba.cuda requires target='cuda' parameter for numba.vectorize and numba.guvectorize functions. numba-dpex eschews the target parameter for @vectorize and infers the target from the dpctl.device_context in which the numba.vectorize function is called.

Full Examples

  • numba_dpex/examples/vectorize.py

  • numba_dpex/examples/blacksholes_njit.py