Why signature is an unrecognized option?

This script:

import numba

@numba.jit(signature='f4(f4)')
def g(x):
  return x**3

print(g(2))

produces this error:

KeyError: "Unrecognized options: {'signature'}.

The documentation at Just-in-Time compilation — Numba 0+untagged.1510.g1e70d8c.dirty documentation shows that signature is available:

@numba.jit(signature=None, nopython=False, nogil=False, cache=False, forceobj=False, parallel=False, error_model='python', fastmath=False, locals={}, boundscheck=False)

Am I reading it incorrectly? I’m using Numba 0.61.2 with Python 3.12.7.

Incidentally, using signature as a positional argument works, e.g.:

@numba.jit('f4(f4)', fastmath=True, inline='always')
def g(x):
  return x**3

@pauljurczak the documentation is probably not up to date.

The jit decorator can be used with signatures as positional argument:
jit(signatures, **targetoptions) -> jit(function)

You could use a keyword argument “signature_or_function”, too:

@numba.jit(signature_or_function='f4(f4)')
def g(x):
  return x**3

print(g(2))
# 8.0

This is the description:

def jit(signature_or_function=None, locals=MappingProxyType({}), cache=False,
        pipeline_class=None, boundscheck=None, **options):
    """
    This decorator is used to compile a Python function into native code.

    Args
    -----
    signature_or_function:
        The (optional) signature or list of signatures to be compiled.
        If not passed, required signatures will be compiled when the
        decorated function is called, depending on the argument values.
        As a convenience, you can directly pass the function to be compiled
        instead.
1 Like

Thank you, this solution works. Interestingly, the full error message for signature keyword doesn’t list signature_or_function:

KeyError: "Unrecognized options: {'signature'}. Known options are dict_keys(['_dbg_extend_lifetimes', '_dbg_optnone', '_nrt', 'boundscheck', 'debug', 'error_model', 'fastmath', 'forceinline', 'forceobj', 'inline', 'looplift', 'no_cfunc_wrapper', 'no_cpython_wrapper', 'no_rewrites', 'nogil', 'nopython', 'parallel'])"

It is probably missing on purpose. The users should treat signatures as a positional argument.
Have you considered opening an issue on Github to update the documentation?

Done: Signature is an unrecognized option for @jit [documentation issue] · Issue #10049 · numba/numba · GitHub

1 Like