aesara icon indicating copy to clipboard operation
aesara copied to clipboard

Consider turning on bounds checking by default for Numba compiled code

Open brandonwillard opened this issue 1 year ago • 5 comments

As a follow-up to the conversation in #1081, we should consider turning on bounds checking by default. One requirement is that NUMBA_BOUNDSCHECK be honored.

brandonwillard avatar Aug 25 '22 20:08 brandonwillard

Is NUMBA_BOUNDSCHECK set to False by default?

ricardoV94 avatar Aug 25 '22 21:08 ricardoV94

Is NUMBA_BOUNDSCHECK set to False by default?

Essentially.

brandonwillard avatar Aug 25 '22 21:08 brandonwillard

Then we can't turn checks by default. Or did you mean something else?

ricardoV94 avatar Aug 25 '22 21:08 ricardoV94

Then we can't turn checks by default. Or did you mean something else?

We can turn bounds checking on by default in a "localized" way using the njit decorator, but we also need to honor the NUMBA_BOUNDSCHECK setting when/if it's set by the user.

brandonwillard avatar Aug 25 '22 22:08 brandonwillard

I didn't really expect this behavior myself until I read the docs some time ago, but the environment variable overrides the keyword argument:

%env NUMBA_BOUNDSCHECK=0

import numpy as np
import numba

@numba.njit(boundscheck=True)
def foo(x):
    return x[3]

foo(np.ones(2))  # No exception but undefined output

So I think we can just set the boundscheck argument to whatever we think is a appropriate default in that function.

aseyboldt avatar Aug 25 '22 22:08 aseyboldt