Inspecting @guvectorize'd

@jit functions have misc inspect_*() functions.

How do I inspect @vectorize and @guvectorize functions?

Especially @guvectorize’d functions appear to be straight up numpy.ufunc and do not appear to have any numba specific funcs :(.

Example:

@guvectorize(
    [(int64[:], int64, int64[:]), (float64[:], float64, float64[:])],
    "(n),()->(n)",
    target="parallel",
    nopython=True,
)
def add_gu(x, y, res=[]):
    for i in range(x.shape[0]):
        res[i] = x[i] + y

[x for x in dir(add_gu) if "inspect" in x]

Expected some inspect_*() methods…

oh and silly question also. You can see I gave default value to res=[] this is to avoid seeing Argument missing for parameter "res". Is there correct/ idiomatic way to avoid seeing warning?

Thanks!

The Numba compilation generates the inner loop of the ufunc or gufunc which you’ve spotted is just a NumPy ufunc - because we’ve no reference to the Numba-compiled function from the ufunc (as far as I’m aware) you can’t get at those methods to inspect things, but you can set config variables before compilation to get Numba to emit the code that you would have got e.g. from inspect_asm() - e.g.:

from numba import config, int64, float64, guvectorize

config.DUMP_ASSEMBLY = 1

@guvectorize(
    [(int64[:], int64, int64[:]), (float64[:], float64, float64[:])],
    "(n),()->(n)",
    target="parallel",
    nopython=True,
)
def add_gu(x, y, res=[]):
    for i in range(x.shape[0]):
        res[i] = x[i] + y

Other config variables for equivalent inspect_() functions are DUMP_LLVM, DUMP_OPTIMIZED, DUMP_IR, etc. - these are documented in their environment variable form at Environment variables — Numba 0.57.0.dev0+1167.g0c0f2b57c.dirty-py3.8-linux-x86_64.egg documentation (e.g. Environment variables — Numba 0.57.0.dev0+1167.g0c0f2b57c.dirty-py3.8-linux-x86_64.egg documentation).

1 Like