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

Problem still exist with resizing an array previously declared in a tuple. #1572

Closed
jeanlaroche opened this issue Jun 22, 2020 · 11 comments · May be fixed by #1641
Closed

Problem still exist with resizing an array previously declared in a tuple. #1572

jeanlaroche opened this issue Jun 22, 2020 · 11 comments · May be fixed by #1641

Comments

@jeanlaroche
Copy link
Contributor

Pythran still misbehaves with the code below:
self[0] is initializes as a (1,1) array, then when an attempt is made to give it a shape of (100,100) this fails.

# pythran export test()
import numpy as np

def A():
    self_xx = np.zeros((1,1))
    self = tuple([self_xx])
    return self

def B(self, D, C):
    print(D, C)
    self[0] = np.zeros((D, C))
    print('self[0]', self[0].shape)

def test():
    fr = A()
    B(fr, 100, 100)
@jeanlaroche
Copy link
Contributor Author

jeanlaroche commented Jun 22, 2020

OK my bad. Adding a print('fr[0]', fr[0].shape) in test() fixes the issue. Argh. I was trying to isolate a real issue I'm seeing along these lines. My real issue is the same, i.e. impossible to resize a member of a tuple after it's been created.
I'm finding that the problem goes away if I use --config pythran.optimizations=pythran.optimizations.ListToTuple
Can someone explain why that would be the case? Does pythran.optimizations=pythran.optimizations.ListToTuple indicate that that's the only optimization being run?

@jeanlaroche
Copy link
Contributor Author

jeanlaroche commented Jun 23, 2020

Question:
why is:

pythran -lblas TD.py --config 'pythran.optimizations=pythran.optimizations.ConstantFolding pythran.optimizations.PartialConstantFolding pythran.optimizations.DeadCodeElimination pythran.optimizations.IterTransformation pythran.optimizations.ComprehensionPatterns pythran.optimizations.ListCompToGenexp pythran.optimizations.LoopFullUnrolling pythran.optimizations.ModIndex pythran.optimizations.PatternTransform pythran.optimizations.RangeLoopUnfolding pythran.optimizations.RangeBasedSimplify pythran.optimizations.Square pythran.optimizations.Inlining pythran.optimizations.InlineBuiltins pythran.optimizations.ListToTuple pythran.optimizations.TupleToShape pythran.optimizations.RemoveDeadFunctions pythran.optimizations.ForwardSubstitution pythran.optimizations.ListToTuple'

different than

pythran -lblas TD.py

The former lists all the optimizations available (from the init.py file in the optimizations directory). So I would imagine all of these are on by default, but I get different results in both cases. The former works, the latter does not.

@serge-sans-paille
Copy link
Owner

The list of optimization used is defined in pythran/pythran.cfg. order matters!

@serge-sans-paille
Copy link
Owner

Does pythran.optimizations=pythran.optimizations.ListToTuple indicate that that's the only optimization being run?

yes

@serge-sans-paille
Copy link
Owner

As a side note: the code above is not valid Python:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in test
  File "<stdin>", line 3, in B
TypeError: 'tuple' object does not support item assignment

@jeanlaroche
Copy link
Contributor Author

Yes, of course, I'm aware of that! I'm bending the rules because pythran allows me to do it (and it's really the only way I can create and use a tuple from the C++ created by pythran!).

serge-sans-paille added a commit that referenced this issue Sep 21, 2020
Introduce an explicit cast on rvalues to deal with combiner applied on
non-reference nodes.

Fix #1572
@jeanlaroche
Copy link
Contributor Author

Cool. I'm going to check it this pm

@jeanlaroche
Copy link
Contributor Author

Well, it's still not working for me:
This is the typical situation: These values are declared in my init function.

        flux                =    np.zeros(0)
        #flux                =    np.zeros(int(0*bogus) # < - this makes it work.
       

Later in my code, during run time, I get this assertion:

Assertion failed: (N == v && "consistent init"), function check_type, file /Users/jlaroche/pyent.py3.Darwin.x86_64/lib/python3.7/site-packages/pythran-0.9.6-py3.7.egg/pythran/pythonic/include/types/tuple.hpp, line 157.

The code, again, is too complex to post here. But maybe that will give you an idea for what's going on?

@serge-sans-paille
Copy link
Owner

@jeanlaroche can you double check if this is fixed or not in the latest release?

@jeanlaroche
Copy link
Contributor Author

@serge-sans-paille Nope. I get exactly the same assert with the latest release. I might be able to make a pruned-down example if that's useful.

@jeanlaroche
Copy link
Contributor Author

I'm going to close this, and open a new bug that has a smaller example.

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

Successfully merging a pull request may close this issue.

2 participants