Error when using `numpy.random.normal()` with Numba

I'm exploring a bit Numba to optimize some signal processing codes. According to Numba's documentation, the function from the numpy.random package is well supported by the just-in-time compiler. However, when I run

import numpy as np
from numba import jit

def numba():
    noise = np.random.normal(size=100)

# ...

if __name__ == "__main__":

I get the following error:

Traceback (most recent call last):
  File ".../", line 89, in <module>
  File ".../venv/lib/python3.9/site-packages/numba/core/", line 468, in _compile_for_args
    error_rewrite(e, 'typing')
  File ".../venv/lib/python3.9/site-packages/numba/core/", line 409, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in method normal of numpy.random.mtrand.RandomState object at 0x104355740>) found for signature:
 >>> normal(size=Literal[int](100000))
There are 4 candidate implementations:
  - Of which 4 did not match due to:
  Overload in function '_OverloadWrapper._build.<locals>.ol_generated': File: numba/core/ Line 129.
    With argument(s): '(size=int64)':
   Rejected as the implementation raised a specific error:
     TypingError: unsupported call signature
  raised from .../venv/lib/python3.9/site-packages/numba/core/typing/

During: resolving callee type: Function(<built-in method normal of numpy.random.mtrand.RandomState object at 0x104355740>)
During: typing of call at .../ (65)

File "", line 65:
def numba():
    noise = np.random.normal(size=SIZE)

Am I doing something obviously silly?


  • if you check the current state of documentation, the size argument is not supported yet.

    since numba compiles this to machine code, this is equivalent in terms of speed.

    def numba():
        noise = np.empty(100,dtype=np.float64)
        for i in range(100):
            noise[i] = np.random.normal()
        return noise

    Edit: the numba version is actually twice as fast ... probably because it doesn't parse inputs.