question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

doc and impl of RewriteArrayExprs are inconsistent

See original GitHub issue
def test_single_array_expr():
    def _test_impl(array):
        ret = array >= 0.1
        return ret

    jitted = numba.jit()(_test_impl)
    arr = np.random.rand(10)
    jit_ret = jitted(arr)

Code above will be rewritten by RewriteArrayExprs Pass. But array >= 0.1 only has one operator. Is it necessary to rewrite this expression, since loop fusion and shortcut deforestation optimizations don’t seem to work? And in numba developer doc, it wrote (https://numba.readthedocs.io/en/latest/developer/rewrites.html):

RewriteArrayExprs.match(): The rewrite pass looks for two or more array operations that form an array expression.

Is it inconsistent between doc and impl?

If this can be confirmed as a real inconsistency, I would like to contribute some code to fix it.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
sklamcommented, Apr 12, 2022

My first guess is that the doc is wrong and arrayexpr is needed to map array operations to ufunc. But the code was written years ago and I need to look at it to confirm.

1reaction
gmarkallcommented, Apr 12, 2022

IR is not in SSA form, but SSA IR is in SSA form. For example, if you have:

from numba import njit

@njit('int32(boolean)')
def f(c):
    if c:
        a = 1
    else:
        a = 2
    return a

Then the dumps are:

$ NUMBA_DUMP_IR=1 NUMBA_DUMP_SSA=1 python repro.py 
-----------------------------------IR DUMP: f-----------------------------------
label 0:
    c = arg(0, name=c)                       ['c']
    bool4 = global(bool: <class 'bool'>)     ['bool4']
    $4pred = call bool4(c, func=bool4, args=(Var(c, repro.py:6),), kws=(), vararg=None, target=None) ['$4pred', 'bool4', 'c']
    branch $4pred, 6, 14                     ['$4pred']
label 6:
    a = const(int, 1)                        ['a']
    $12return_value.2 = cast(value=a)        ['$12return_value.2', 'a']
    return $12return_value.2                 ['$12return_value.2']
label 14:
    a = const(int, 2)                        ['a']
    $20return_value.2 = cast(value=a)        ['$20return_value.2', 'a']
    return $20return_value.2                 ['$20return_value.2']

---------------------------------SSA IR DUMP: f---------------------------------
label 0:
    c = arg(0, name=c)                       ['c']
    bool4 = global(bool: <class 'bool'>)     ['bool4']
    $4pred = call bool4(c, func=bool4, args=(Var(c, repro.py:6),), kws=(), vararg=None, target=None) ['$4pred', 'bool4', 'c']
    branch $4pred, 6, 14                     ['$4pred']
label 6:
    a = const(int, 1)                        ['a']
    $12return_value.2 = cast(value=a)        ['$12return_value.2', 'a']
    return $12return_value.2                 ['$12return_value.2']
label 14:
    a.1 = const(int, 2)                      ['a.1']
    $20return_value.2 = cast(value=a.1)      ['$20return_value.2', 'a.1']
    return $20return_value.2                 ['$20return_value.2']

The IR is not SSA form because there are multiple assignments to a - in the SSA form, the second assignment is to a new variable, a.1. The introductory paragraphs of the Wikipedia article provide a reasonable summary: https://en.wikipedia.org/wiki/Static_single_assignment_form

Read more comments on GitHub >

github_iconTop Results From Across the Web

Release Notes — Numba 0.56.4+0.g288a38bbd.dirty-py3.7 ...
Version 0.56.4 (3 November, 2022) . This is a bugfix release to fix a regression in the CUDA target in relation to...
Read more >
目录 - Gitee
Historically inconsistent support by major hardware vendors (compiler bugs, ... Random impl in Numba follows CPython rather than NumPy, which makes it hard ......
Read more >
Analysis Report numba-0.48.0-cp37-cp37m-win_amd64.whl
Those CPython APIs are private and can change in incompatible ways at. ... The implementation of the hash table (_Numba_hashtable_t) is based on...
Read more >
numba - bytemeta
doc and impl of RewriteArrayExprs are inconsistent. PABannier. PABannier OPEN · Updated 6 months ago · `Jitclass` decorator removes the method signatures of ......
Read more >
transfer of primordials package - Nodejs/Security-Wg - IssueHint
To document the transfer and finish it, this issue is created by me. ... doc and impl of RewriteArrayExprs are inconsistent, 10, 2022-04-07,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found