if_else yields the exit block of the if

0 views
Skip to first unread message

Colton Williams

unread,
Dec 2, 2017, 9:38:27 PM12/2/17
to Numba Public Discussion - Public
when you do something like

with if_else as (then, otherwise):
    with then as then_block:
        <<code>>
    with otherwise as otherwise_block:
        <<code>>

the 'then_block' and 'otherwise_block' above are references to the same block, which is the endif block. I don't understand the motivation for that choice. If those blocks were actually the 'if' and 'else' blocks they could be more useful. For example you could do something like...

with builder.if_else as (then, otherwise):
    with then as then_block:
        var1 = builder.add(x,y)
    with otherwise as otherwise_block:
        var2 = builder.add(i, j)

phi = builder.phi()
phi.add_incoming(var1, then_block)
phi.add_incoming(var2, otherwise_block)


Does this seem like a good idea? The code change to do this is trivial (I'm using it in a forked repo). I'd be happy to create a PR if this would be useful to more people. All of the tests still pass in my forked version and I looked through the numba codebase and I couldn't find any instances where the yielded value of the then and otherwise was even being captured.

Siu Kwan Lam

unread,
Dec 4, 2017, 12:35:22 PM12/4/17
to numba...@continuum.io
The motivation comes from that the "endif" block is exposed only via code like "with then as endif", and that the "then_block" or "else_block" can always be accessed as "builder.basic_block".  When the code calls for a manual jump from within the if-else body to the "endif", the current behavior is more useful.  

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.
To post to this group, send email to numba...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/9314dfce-03e2-4f4b-a74b-670b1bfca4e7%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
--
Siu Kwan Lam
Software Engineer
Continuum Analytics

Colton Williams

unread,
Dec 4, 2017, 12:55:46 PM12/4/17
to Numba Public Discussion - Public
I don't see how you can directly access the then and else blocks. I know that the code you write within their context goes inside them, but they are not directly accessible from what I can tell. What if they yielded a tuple? Something like..............

with if_else as (then, otherwise):
    with then as (then, end):
        <<code>>
    with otherwise as (else_, end)
        <<code>>

Siu Kwan Lam

unread,
Dec 5, 2017, 11:18:13 AM12/5/17
to numba...@continuum.io

Colton Williams

unread,
Dec 5, 2017, 8:46:37 PM12/5/17
to Numba Public Discussion - Public
I understand. That makes complete sense now. I really appreciate you taking the time to explain that to me.
Reply all
Reply to author
Forward
0 new messages