[pythran] Re: pattern detection

  • From: serge Guelton <serge.guelton@xxxxxxxxxxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Thu, 21 Nov 2013 11:34:52 +0100

On Thu, Nov 21, 2013 at 11:16:45AM +0100, pierrick Brunet wrote:
> Hi everyone,
> 
> I know there is some more important thinks to do for now (like PyHPC :-) )  
> but
> we spoke about detecting some common python pattern to compute them more
> efficiently.

yes

> 
> For example : len(set(...)) is a common pattern to compute number of unique
> elements in a list or iterator.

That's the motivating example :-) The optimization pass should take a
pattern and the replacing function as input. At first the pattern could
be a single expression. A Statement would be great, but that's much more
difficult.

> a way to do is to create our own python library and change len(set(...)) ->
> pythran_lib.unique_elts(...) and then we just have to implement efficient
> computation like with others library. The problem is that new code will not be
> python compliant code as this library doesn't exists so constantFolding will
> not work.

True. 

> Of course, we can implement a python library doing correct think but it is not
> really what pythran should do IMO.

That would work, but that would require extra work too.

> Another solution is to do it AFTER constantfolding but the real question is :
> why in this case constantfolding is not done before all others modifications?

That's the way to go.
Conceptually, constant folding is an optimization, so it should not be
applied before IR refinement.
> 
> Have a good week end everyone :-)

That was interesting, but I am 100% jet lagged :-$
> 
> PS : serge I am on your PR :-)
Integrated, thanks!

Other related posts: