Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing list of booleans changes result #2010

Open
gamask opened this issue Jul 22, 2022 · 1 comment
Open

Accessing list of booleans changes result #2010

gamask opened this issue Jul 22, 2022 · 1 comment

Comments

@gamask
Copy link

gamask commented Jul 22, 2022

I get different results depending on whether a variable I just set is immediately accessed or not.
Variable "ro".
Right after I define it there's a line that just says "#ro".

If that line is commented out, I get the wrong result.
If it's live, I get the right result.

Casting the elements in "ro" to int also makes it work.
Printing "ro" makes it work.

To test, call gga like this:
gga (65, 60, 0, True, 1, [65., 65.], [4100., 2000.], 1.)

Correct output is:
B
234.0

If "#ro" is commented out you'll get this instead:
C
0.0

import math

gis_t4 = {
    0       : 123,
    2000    : 234,
    7000    : 345,
}

def f (data, tx, s):
    txu = tx * s
    
    keys = sorted(list(data.keys()))
    
    for i in range(len(keys) - 1, -1, -1):
        k = keys[i]
        if txu >= k:
            return data[k] / s
    
    return data[0] / s


#pythran export gga (
#   int, int, int, bool, int, float64 list, float64 list, float64
#)
def gga (b, c, y, m, cnum, osa, tx, s):
    other_cnum = 1 - cnum
    
    tca = (b if cnum == 0 else c) + y
    oca = (b if other_cnum == 0 else c) + y
    
    tto = max(osa[other_cnum] - oca, 0.)
    if tto == 0:
        fraction = 1.
    else:
        fraction = max (1 - tto, 0.)
    
    ro = [
        (b + y) >= math.floor(osa[cnum]),
        (c + y) >= math.floor(osa[other_cnum]),
    ]
    #ro
    
    if not m:
        print ('A')
        return 0.
    else:
        if ro[other_cnum] and tca >= 60 and tca <= 64:
            print ('B')
            return f (gis_t4, tx[cnum] + tx[other_cnum], s) * fraction
        else:
            print ('C')
            return 0.
@serge-sans-paille
Copy link
Owner

The preprocessed code as output by pythran -P mycode.py shows that some forward substitution happen, that's probably the reason. I'll be offline for a few weeks, but I'll have a look afterward. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants