Code Monkey home page Code Monkey logo

pythran's Introduction

Pythran

https://pythran.readthedocs.io

What is it?

Pythran is an ahead of time compiler for a subset of the Python language, with a focus on scientific computing. It takes a Python module annotated with a few interface descriptions and turns it into a native Python module with the same interface, but (hopefully) faster.

It is meant to efficiently compile scientific programs, and takes advantage of multi-cores and SIMD instruction units.

Until 0.9.5 (included), Pythran was supporting Python 3 and Python 2.7. It now only supports Python 3.

Installation

Pythran sources are hosted on https://github.com/serge-sans-paille/pythran.

Pythran releases are hosted on https://pypi.python.org/pypi/pythran.

Pythran is available on conda-forge on https://anaconda.org/conda-forge/pythran.

Debian/Ubuntu

Using pip

  1. Gather dependencies:

    Pythran depends on a few Python modules and several C++ libraries. On a debian-like platform, run:

    $> sudo apt-get install libatlas-base-dev
    $> sudo apt-get install python-dev python-ply python-numpy
    
  2. Install with pip:

    $> pip install pythran
    

Using mamba or conda

  1. Using mamba (https://github.com/conda-forge/miniforge#mambaforge) or conda (https://github.com/conda-forge/miniforge)

  2. Run:

    $> mamba install -c conda-forge pythran
    

    or:

    $> conda install -c conda-forge pythran
    

Mac OSX

Using brew (https://brew.sh/):

$> pip install pythran
$> brew install openblas
$> printf '[compiler]\nblas=openblas\ninclude_dirs=/usr/local/opt/openblas/include\nlibrary_dirs=/usr/local/opt/openblas/lib' > ~/.pythranrc

Depending on your setup, you may need to add the following to your ~/.pythranrc file:

[compiler]
CXX=g++-4.9
CC=gcc-4.9

ArchLinux

Using pacman:

$> pacman -S python-pythran

Fedora

Using dnf:

$> dnf install pythran

Windows

Windows support is on going and only targets Python 3.5+ with either Visual Studio 2017 or, better, clang-cl:

$> pip install pythran

Note that using clang-cl.exe is the default setting. It can be changed through the CXX and CC environment variables.

Other Platform

See MANUAL file.

Basic Usage

A simple pythran input could be dprod.py

"""
Naive dotproduct! Pythran supports numpy.dot
"""
#pythran export dprod(int list, int list)
def dprod(l0,l1):
    """WoW, generator expression, zip and sum."""
    return sum(x * y for x, y in zip(l0, l1))

To turn it into a native module, run:

$> pythran dprod.py

That will generate a native dprod.so that can be imported just like the former module:

$> python -c 'import dprod' # this imports the native module instead

Documentation

The user documentation is available in the MANUAL file from the doc directory.

The developer documentation is available in the DEVGUIDE file from the doc directory. There is also a TUTORIAL file for those who don't like reading documentation.

The CLI documentation is available from the pythran help command:

$> pythran --help

Some extra developer documentation is also available using pydoc. Beware, this is the computer science incarnation for the famous Where's Waldo? game:

$> pydoc pythran
$> pydoc pythran.typing
$> pydoc -b  # in the browser

Examples

See the pythran/tests/cases/ directory from the sources.

Contact

Praise, flame and cookies:

The mailing list archive is available at https://www.freelists.org/archive/pythran/.

Citing

If you need to cite a Pythran paper, feel free to use

@article{guelton2015pythran,
  title={Pythran: Enabling static optimization of scientific python programs},
  author={Guelton, Serge and Brunet, Pierrick and Amini, Mehdi and Merlini,
                  Adrien and Corbillon, Xavier and Raynaud, Alan},
  journal={Computational Science \& Discovery},
  volume={8},
  number={1},
  pages={014001},
  year={2015},
  publisher={IOP Publishing}
}

Authors

See AUTHORS file.

License

See LICENSE file.

pythran's People

Contributors

adamjstewart avatar aguinet avatar aguinetqb avatar angus-g avatar artas360 avatar ashwinvis avatar charlotte12l avatar christophecoue avatar coyotte508 avatar cycomanic avatar dapid avatar dwesl avatar flothesof avatar hainm avatar hroncok avatar jeanlaroche avatar jfinkels avatar jwakely avatar kynan avatar lsix avatar lysnikolaou avatar mattip avatar mkoeppe avatar nagadum avatar paugier avatar pbrunet avatar rgommers avatar serge-sans-paille avatar xantares avatar xmar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pythran's Issues

typing in loop

Hey,

Another issue in typing:

  1 #pythran export test()
  2 
  3 def test():
  4     a = [[]]
  5     b = []
  6     for j in a:
  7         b += [j] + [[1]]
  8     a = b

with this code, type of j is list<empty_list>
it should be list

this code compile fine but if you add another loop, it will not work

#pythran export test()

def test():
    a = [[]]
    for i in range(2):
        b = []
        for j in a:
            b += [j] + [[1]]
        a = b

it is because new type of a (which is the type of b) is define after the second for loop

sorry ....

OpenMP representation

Hi,

I notice that OpenMP Node are not always handle by ast parsing/visiting.

If we use the code : pythran/tests/openmp.legacy/omp_parallel_if.py we can notice that UsedDefChain for control doesn't contains the control in the omp if clause.
It means that some transformation may not be correctly handled.

Also, we can notice that context for ast.Name in omp construct are not consistent.

if we have

"""omp parallel for if(a==2)"""
for i in xrange(10):
    ...

a is considered as a ast.Param context while it should be a ctx.Load. But if it is done this way, aliasing fails as it doesn't handle openmp construct and certainly others issue will appear.

I tried to do some modification for that but I don't really understand the origin of the problem (OMPDirective node not visited) so I would prefer know if I have to dig in these modification or if someone else want to do these modifications? (Or if we keep this buggy construction).

Consider making code not require C++11

I don't see any reason why pythran needs to target C++11.
First, decltype could be replaced with other things in C++03.

Second, I'm not even sure this is required at all, since things like

decltype(std::declval<g>()(std::declval<__type0>()))

could be replaced by

typename g::template type<__type0>::type

(of course operators would have to be handled differently)

openmp linkage

To enable openmp, we have to use -fopenmp flag. But if we use "import omp", the correct linkage should be done automaticaly instead of crashing

Style: writing "readable" types

I encountered functions like:

        template<class Iterable>
             types::dict<typename std::tuple_element<0, typename std::remove_reference<Iterable>::type::iterator::value_type>::type ,
             typename std::tuple_element<1, typename std::remove_reference<Iterable>::type::iterator::value_type>::type >
                 dict( Iterable&& iterable) {
                     types::dict<typename std::tuple_element<0, typename std::remove_reference<Iterable>::type::iterator::value_type>::type ,
                     typename std::tuple_element<1, typename std::remove_reference<Iterable>::type::iterator::value_type>::type > out=types::empty_dict();
                     for(auto const & i : iterable)
                         out[std::get<0>(i)] = std::get<1>(i);
                     return out;
                 }
  1. I found tough to reverse-engineer the type system
  2. the code is so small in the middle of huge types

I would rewrite something like this:

namespace {
// Type helpers

  template<typename Iterable>
  using IterableValue = std::remove_reference<Iterable>::type::iterator::value_type;

  template<typename Iterable, int which>
  using IterableUnpack = typename std::tuple_element<which, IterableValue<Iterable>::type;

  template<typename Iterable>
  using DictKeyFromIterable =  IterableUnpack<Iterable, 0>;

  template<typename Iterable>
  using DictValueFromIterable =  IterableUnpack<Iterable, 1>;

  template<typename Iterable>
  using DictFromIterable = types::dict<DictKeyFromIterable<Iterable>,
                                       DictValueFromIterable<Iterable>>;


}



template<class Iterable>
DictFromIterable<Iterable> dict( Iterable&& iterable) {
  DictFromIterable<Iterable> out=types::empty_dict();
  for(auto const & i : iterable)
    out[std::get<0>(i)] = std::get<1>(i);
  return out;
}

segfault on nested list

Has I am looking at some long code, I found a segfault.

The code is : pythran/tests/cases/matmul.py

The test case it : python -c "import matmul; a=[ [ float(i) for i in xrange(600)] for j in xrange(400)]; matmul.matrix_multiply(a, a)

It is really weird as : python -c "import matmul; a=[ [ float(i) for i in xrange(600)] for j in xrange(600)]; matmul.matrix_multiply(a, a) works.

lambda issue

Here is a code that cause a segfault :

def test():
    perf = lambda n: n == sum(i for i in xrange(1, n) if n % i == 0)
    print map(perf, xrange(20))

Type inference on return

Is it allowed to have two return with different types? I think so, but it fails for tests/cases/pivot.cpp :

pivot.cpp:156:12: error: no viable conversion from 
    'decltype(_make_tuple<are_same<list<list<long> > &, list<long> &>::value, pythonic::core::list<pythonic::core::list<long> > &, pythonic::core::list<long> &>( (std::forward<pythonic::core::list<pythonic::core::list<long> > &>(types), std::forward<pythonic::core::list<long> &>(types)))' 
   (aka 'tuple<pythonic::core::list<pythonic::core::list<long> > &, pythonic::core::list<long> &>')
   to 'typename pivot::type<long, long, list<list<long> > &, list<long> &>::result_type' 
   (aka 'pythonic::none<std::__1::tuple<pythonic::core::list<pythonic::core::list<long> >, pythonic::core::list<long> > >')
    return core::make_tuple(a, b);

valgrind error in np.from_iter

==30115== Conditional jump or move depends on uninitialised value(s)
==30115==    at 0x5DF90AC1: __pythran_test_np_fromiter0::__generator__g::next() (tmpddNWmt.cpp:75)
==30115==    by 0x5DF95E64: __pythran_test_np_fromiter0::__generator__g::begin() (tmpddNWmt.cpp:31)
==30115==    by 0x5DF95BFC: pythonic::core::ndarray<std::remove_cv<std::remove_reference<__pythran_test_np_fromiter0::__generator__g&>::type>::type::value_type, 1ul> pythonic::
numpy::fromiter<__pythran_test_np_fromiter0::__generator__g&, float>(__pythran_test_np_fromiter0::__generator__g&, float, long) (numpy.h:1780)
==30115==    by 0x5DF93E02: _ZNK8pythonic5numpy5proxy8fromiterclIJRN27__pythran_test_np_fromiter014__generator__gEfEEEDTclsr8pythonic5numpyE8fromiterspclsr3stdE7forwardIT_Efp_E
EEDpOS7_ (numpy.h:1790)
==30115==    by 0x5DF90BEE: __pythran_test_np_fromiter0::np_fromiter0::operator()() const (tmpddNWmt.cpp:92)
==30115==    by 0x5DF90C17: np_fromiter00() (tmpddNWmt.cpp:98)
==30115==    by 0x5DF94F97: _object* boost::python::detail::invoke<boost::python::to_python_value<pythonic::core::ndarray<long, 1ul> const&>, pythonic::core::ndarray<long, 1ul>
 (*)()>(boost::python::detail::invoke_tag_<false, false>, boost::python::to_python_value<pythonic::core::ndarray<long, 1ul> const&> const&, pythonic::core::ndarray<long, 1ul> (
*&)()) (invoke.hpp:75)
==30115==    by 0x5DF94EFD: boost::python::detail::caller_arity<0u>::impl<pythonic::core::ndarray<long, 1ul> (*)(), boost::python::default_call_policies, boost::mpl::vector1<py
thonic::core::ndarray<long, 1ul> > >::operator()(_object*, _object*) (caller.hpp:221)
==30115==    by 0x5DF948A6: boost::python::objects::caller_py_function_impl<boost::python::detail::caller<pythonic::core::ndarray<long, 1ul> (*)(), boost::python::default_call_
policies, boost::mpl::vector1<pythonic::core::ndarray<long, 1ul> > > >::operator()(_object*, _object*) (py_function.hpp:38)
==30115==    by 0x104687BA: boost::python::objects::function::call(_object*, _object*) const (in /usr/lib/libboost_python-py27.so.1.49.0)
==30115==    by 0x104689D7: ??? (in /usr/lib/libboost_python-py27.so.1.49.0)
==30115==    by 0x104718BA: boost::python::handle_exception_impl(boost::function0<void>) (in /usr/lib/libboost_python-py27.so.1.49.0)
==30115== 
==30115== Conditional jump or move depends on uninitialised value(s)
==30115==    at 0x5DF90AD8: __pythran_test_np_fromiter0::__generator__g::next() (tmpddNWmt.cpp:75)
==30115==    by 0x5DF95E64: __pythran_test_np_fromiter0::__generator__g::begin() (tmpddNWmt.cpp:31)
==30115==    by 0x5DF95BFC: pythonic::core::ndarray<std::remove_cv<std::remove_reference<__pythran_test_np_fromiter0::__generator__g&>::type>::type::value_type, 1ul> pythonic::
numpy::fromiter<__pythran_test_np_fromiter0::__generator__g&, float>(__pythran_test_np_fromiter0::__generator__g&, float, long) (numpy.h:1780)
==30115==    by 0x5DF93E02: _ZNK8pythonic5numpy5proxy8fromiterclIJRN27__pythran_test_np_fromiter014__generator__gEfEEEDTclsr8pythonic5numpyE8fromiterspclsr3stdE7forwardIT_Efp_E
EEDpOS7_ (numpy.h:1790)
==30115==    by 0x5DF90BEE: __pythran_test_np_fromiter0::np_fromiter0::operator()() const (tmpddNWmt.cpp:92)
==30115==    by 0x5DF90C17: np_fromiter00() (tmpddNWmt.cpp:98)
==30115==    by 0x5DF94F97: _object* boost::python::detail::invoke<boost::python::to_python_value<pythonic::core::ndarray<long, 1ul> const&>, pythonic::core::ndarray<long, 1ul> (*)()>(boost::python::detail::invoke_tag_<false, false>, boost::python::to_python_value<pythonic::core::ndarray<long, 1ul> const&> const&, pythonic::core::ndarray<long, 1ul> (*&)()) (invoke.hpp:75)
==30115==    by 0x5DF94EFD: boost::python::detail::caller_arity<0u>::impl<pythonic::core::ndarray<long, 1ul> (*)(), boost::python::default_call_policies, boost::mpl::vector1<pythonic::core::ndarray<long, 1ul> > >::operator()(_object*, _object*) (caller.hpp:221)
==30115==    by 0x5DF948A6: boost::python::objects::caller_py_function_impl<boost::python::detail::caller<pythonic::core::ndarray<long, 1ul> (*)(), boost::python::default_call_policies, boost::mpl::vector1<pythonic::core::ndarray<long, 1ul> > > >::operator()(_object*, _object*) (py_function.hpp:38)
==30115==    by 0x104687BA: boost::python::objects::function::call(_object*, _object*) const (in /usr/lib/libboost_python-py27.so.1.49.0)
==30115==    by 0x104689D7: ??? (in /usr/lib/libboost_python-py27.so.1.49.0)
==30115==    by 0x104718BA: boost::python::handle_exception_impl(boost::function0<void>) (in /usr/lib/libboost_python-py27.so.1.49.0)

Pythran fails to handle functions with large body

Try to compile this:

def main():
    # It took too long to find the solution by brute force, so try numbers
    # with lots of distinct small prime factors
    products = set()
    for ii in range(3):
        for jj in range(3):
            for kk in range(3):
                for ll in range(3):
                    for mm in range(3):
                        for nn in range(3):
                            product = (2 ** ii * 3 ** jj * 5 ** kk * 7 ** ll *
                              11 ** mm * 13 ** nn)
                            products.add(product)

with loop unrolling activated, and a larger INSTRUCTION_COUNT value. Type inference and alias analysis both lead to memory burst.

Conception issue with ContextManager and multiple inheritance from Analysis and Transformation

There is a multiple inheritance spaghetti around Analysis and Transformation. Both derive from ContextManager but not in the same order. As a matter of consequence super(ContextManager,self) does not resolve the same way. This seems... obscure to me, and the lack of doc/comment does no help to understand what is going on here (moreover you have to know precisely the python way of resolving inheritance with super()).

Here is the simplified snippet :

class NodeVisitor(object):
    def visit(self):
        print "Visit in NodeVisitor"

class ContextManager(object):
    def visit(self):
        print "Visit in context manager"
        super(ContextManager, self).visit()

    def run_visit(self):
        return self.visit()    


class Analysis(NodeVisitor, ContextManager):
    def vide():
        pass


class Transformation(ContextManager, NodeVisitor):
    def vide():
        pass


print "*** Analysis"
a = Analysis()
a.run_visit()

print "*** Transformation"
t = Transformation()
t.run_visit()

which outputs:

*** Analysis
Visit in NodeVisitor
*** Transformation
Visit in context manager
Visit in NodeVisitor

Validation portability

Two issues, first I don't think you can add cflags/ldflags options to the test command line (either setup.py or py.test directly), and secondly since the check environment does more than a check but make a choice (boost_python-mt instead of boost_python) it means that the check HAS to take place.

The following diff shows the changes required to run the validation on OSX using a MacPort boost-python install.

diff --git a/pythran/tests/test_env.py b/pythran/tests/test_env.py
index 0b19821..0622fe9 100644
--- a/pythran/tests/test_env.py
+++ b/pythran/tests/test_env.py
@@ -12,7 +12,7 @@ class TestEnv(unittest.TestCase):

 # default options used for the c++ compiler
 PYTHRAN_CXX_FLAGS = ["-O0", "-fno-implicit-inline-templates", "-fopenmp",
  •        '-Wall', '-Wno-unknown-pragmas']
    
  •        '-Wall', '-Wno-unknown-pragmas','-L/opt/local/lib']
    

    def assertAlmostEqual(self, ref, res):
    if hasattr(ref, 'iter'):
    @@ -71,7 +71,7 @@ class TestEnv(unittest.TestCase):
    cxx_compiled = pythran_compile(os.environ.get("CXX", "c++"),
    cxx_code,
    cxxflags=TestEnv.PYTHRAN_CXX_FLAGS,

  •                                       check=False)
    
  •                                       check=True)
         prelude and prelude()
         pymod = load_dynamic(modname, cxx_compiled)
    

Default return not properly inserted

When dealing with the following code

def r(a):
    try:
        if a: raise a
        else: return a
    except:
        pass

no return None is inserted at the end of the except branch, while it should...

Unit Tests should be pep8 compliant

One line tests are just unreadable and then unmaintable.

Just compare

    def test_permutations(self):
        self.run_test("def permutations_(l0,a): from itertools import permutations; return sum(map(lambda (x,y) : x*y, permutations(l0,a)))", [0,1,2,3,4,5], 2, permutations_=[[int],int])

with:

    def test_permutations_2(self):
        self.run_test("def permutations_2_(l0): "
                      "  from itertools import permutations;"
                      "  return sum(map(lambda (x,y) :"
                      "                    x*y, permutations(l0)))",
                      [0, 1, 2, 3],
                      permutations_=[[int]])

Pythran cannot compile when print numpy.array

Compile error when printing arrays in some cases, this might

For example:

#pythran export foo()
import numpy as np

def foo():
    a = np.ones((6, 8))
    b = np.ones((2, 4))
    d = a[1:3, 4:] + b[:, :]
    print d

foo()

This is mainly due to temporary expressions generated in pythran.
To avoid this problem for the moment, we can print 2 times the same array.

aliasing issue

using the following code, pythran is crashing on the AugAssign operator because of aliasing pass

#pythran export foo()
def foo():
    try:
        a = 1
    except:
        a += a
    return a

Numpy matrix assignment failed

In my 32bits machine, suppose u and tempU are two matrix with the same shape:

u[:, :] = tempU[:, :] # E:Compile error!

At the moment, to avoid this problem:

u = tempU
# then reallocate a matrix to tempU

Coding guidelines for pythonic++

Are there any rules? Pythran has a nice PEP8 compliance rule but what about the C++ code? I mean for instance you don't accept lines >78 char in Python but >160 is not a problem in C++ ?

abs is not available for complex

See:

  • tests/cases/caxpy.py
  • tests/cases/crotg.py
  • tests/cases/gauss.py
  • tests/cases/guerre.py
  • tests/cases/pivot.py

caxpy.cpp:99:10: error: no matching function for call to object of type 'builtin::proxy::abs'

Pythran do not support 32 bits machines

The code didn't consider the data shape of numpy for local machines

// file: pythran.h (line: 1333)
new (storage) core::ndarray< T, N>((T*)PyArray_BYTES(obj_ptr), PyArray_DIMS(obj_ptr)); 

// file: pythran.h (line: 1565)
PyObject* result = PyArray_SimpleNewFromData(N, n.shape.data(), c_type_to_numpy_type<T>::value, n.buffer);

module intiialization is slow

Depending on the use case, calling

init_array()
register_exception ...
register_exception ...

even when not needed leads to a small performance loss

Pythran running on several modules in one execution?

Is Pythran able to run itself on several python files? It seems weird to me, but it seems to happen.

I get this error when running the tests: http://pastebin.com/tQYHcgyk. It happens because I added the current module's name to the global modules variable. Then pythran tries to import all of that, so I make sure to test module_name != current_module when it does that, so as to not import itself.

But here, it seems that when running the cases/blacksholes.py case, it has cases/allpairs.py leftover in memory, according the error.

This all seems to happen in the testenv test. (By the way, I couldn't figure out how to run the test on its own, python test_env.py didn't work.)

Error message for recursive typing not user friendly

When writing code where return type definition recurses, I get the following message

Traceback (most recent call last):
  File "./build/scripts-2.7/pythran", line 36, in <module>
    module = pythran.cxx_generator(module_name, file(args.input_file).read(), specs)
  File "/home/mgaunard/dev/pythran/build/lib.linux-x86_64-2.7/pythran/interface.py", line 70, in cxx_generator
    content = cxx_backend(module_name,ir)
  File "/home/mgaunard/dev/pythran/build/lib.linux-x86_64-2.7/pythran/backend.py", line 467, in cxx_backend
    return CxxBackend(module_name).visit(node)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/home/mgaunard/dev/pythran/build/lib.linux-x86_64-2.7/pythran/backend.py", line 39, in visit_Module
    self.types=type_all(node)
  File "/home/mgaunard/dev/pythran/build/lib.linux-x86_64-2.7/pythran/typing.py", line 439, in type_all
    Reorder(t.types).visit(node)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/home/mgaunard/dev/pythran/build/lib.linux-x86_64-2.7/pythran/typing.py", line 46, in visit_Module
    newdef = [ f for f in nx.topological_sort(self.typedeps, ordered_global_declarations(node)) if isinstance(f, ast.FunctionDef) ]
  File "/usr/lib/pymodules/python2.7/networkx/algorithms/dag.py", line 104, in topological_sort
    raise nx.NetworkXUnfeasible("Graph contains a cycle.")
networkx.exception.NetworkXUnfeasible: Graph contains a cycle.

This is arguably not very user-friendly.

gmp functions

Some function doesn't work with gmp:
sum
min max
map
xrange et range
print list
chr
bin
cmp
all
any
hex
oct
pow
round
functions in module math
and may be some others.

It leads to Fail in test for 32bits architecture as pow(15,18) doesn't exist in a 32bits architecture.

Failing test

def mix_builtin_foo(a):
    return ((bar((a + 42)) + foo(a)) + numpy.arange(10).sum())
def bar(a):
    return (a + 42)
def foo(a):
    return (a + (2 * 42))
def entry(a):
    return mix_builtin_foo(a)
CRITICAL Leave the vessel! Women and children first!
C++ compiler failed to compile translated code.
E: Compile error!

******** Command line was: ********
'g++-mp-4.8' '/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp0CmSek.cpp' '-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7' '-I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/numpy' '-I/Users/amini/projects/pythran/install/lib/python2.7/site-packages/.' '-I/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran' '-DENABLE_PYTHON_MODULE' '-DUSE_GMP' '-I' '/opt/local/include/' '-std=c++11' '-O2' '-shared' '-o' 'test.so' '-L/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config' '-lpython2.7' '-L/opt/local/lib' '-lboost_python-mt' '-lgmp' '-lgmpxx' '-fPIC' '-L' '/opt/local/lib/gcc48/'

******** Output :  ********

In file included from /Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:5:0,
                 from /var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp0CmSek.cpp:7:
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/types/numpy_type.hpp: In instantiation of 'struct pythonic::types::numpy_type<long int>':
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:12:72:   required by substitution of 'template<class T, class U, class S, class dtype> pythonic::types::ndarray<typename pythonic::types::numpy_type<dtype>::type, 1ul> pythonic::numpy::arange(T, U, S, dtype) [with T = long int; U = long int; S = long int; dtype = long int]'
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:32:40:   required from 'pythonic::types::ndarray<T, 1ul> pythonic::numpy::arange(T) [with T = long int]'
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:34:9:   required from 'decltype (pythonic::numpy::arange((forward<Types>)(pythonic::numpy::proxy::arange::operator()::types)...)) pythonic::numpy::proxy::arange::operator()(Types&& ...) const [with Types = {long int}; decltype (pythonic::numpy::arange((forward<Types>)(pythonic::numpy::proxy::arange::operator()::types)...)) = pythonic::types::ndarray<long int, 1ul>]'
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp0CmSek.cpp:110:111:   required from 'typename __pythran_test::mix_builtin_foo::type<argument_type0>::result_type __pythran_test::mix_builtin_foo::operator()(const argument_type0&) const [with argument_type0 = long int; typename __pythran_test::mix_builtin_foo::type<argument_type0>::result_type = long int]'
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp0CmSek.cpp:115:31:   required from 'typename __pythran_test::entry::type<argument_type0>::result_type __pythran_test::entry::operator()(const argument_type0&) const [with argument_type0 = long int; typename __pythran_test::entry::type<argument_type0>::result_type = long int]'
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp0CmSek.cpp:121:36:   required from here
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/types/numpy_type.hpp:12:50: error: expression cannot be used as a function
                 typedef decltype(std::declval<T>()()) type;
                                                  ^
In file included from /var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp0CmSek.cpp:7:0:
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp: In instantiation of 'pythonic::types::ndarray<T, 1ul> pythonic::numpy::arange(T) [with T = long int]':
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:34:9:   required from 'decltype (pythonic::numpy::arange((forward<Types>)(pythonic::numpy::proxy::arange::operator()::types)...)) pythonic::numpy::proxy::arange::operator()(Types&& ...) const [with Types = {long int}; decltype (pythonic::numpy::arange((forward<Types>)(pythonic::numpy::proxy::arange::operator()::types)...)) = pythonic::types::ndarray<long int, 1ul>]'
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp0CmSek.cpp:110:111:   required from 'typename __pythran_test::mix_builtin_foo::type<argument_type0>::result_type __pythran_test::mix_builtin_foo::operator()(const argument_type0&) const [with argument_type0 = long int; typename __pythran_test::mix_builtin_foo::type<argument_type0>::result_type = long int]'
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp0CmSek.cpp:115:31:   required from 'typename __pythran_test::entry::type<argument_type0>::result_type __pythran_test::entry::operator()(const argument_type0&) const [with argument_type0 = long int; typename __pythran_test::entry::type<argument_type0>::result_type = long int]'
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp0CmSek.cpp:121:36:   required from here
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:32:40: error: no matching function for call to 'arange(long int, long int&)'
                 return arange(T(0), end);
                                        ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:32:40: note: candidates are:
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:12:72: note: template<class T, class U, class S, class dtype> pythonic::types::ndarray<typename pythonic::types::numpy_type<dtype>::type, 1ul> pythonic::numpy::arange(T, U, S, dtype)
             types::ndarray<typename types::numpy_type<dtype>::type, 1> arange(T begin, U end, S step=S(1), dtype d=dtype())
                                                                        ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:12:72: note:   substitution of deduced template arguments resulted in errors seen above
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:31:34: note: template<class T> pythonic::types::ndarray<T, 1ul> pythonic::numpy::arange(T)
             types::ndarray<T, 1> arange(T end) {
                                  ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:31:34: note:   template argument deduction/substitution failed:
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:32:40: note:   candidate expects 1 argument, 2 provided
                 return arange(T(0), end);
                                        ^

Clang++

******
CRITICAL Leave the vessel! Women and children first!
C++ compiler failed to compile translated code.
E: Compile error!

******** Command line was: ********
'clang++' '/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp' '-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7' '-I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/numpy' '-I/Users/amini/projects/pythran/install/lib/python2.7/site-packages/.' '-I/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran' '-DENABLE_PYTHON_MODULE' '-DUSE_GMP' '-I' '/opt/local/include/' '-stdlib=libc++' '-std=c++11' '-O2' '-shared' '-o' 'test.so' '-L/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config' '-lpython2.7' '-L/opt/local/lib' '-lboost_python-mt' '-lgmp' '-lgmpxx' '-fPIC' '-L' '/opt/local/lib/gcc48/'

******** Output :  ********

In file included from /var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:7:
In file included from /Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:6:
In file included from /Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/types/ndarray.hpp:24:
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/types/numpy_iexpr.hpp:156:64: error: no member named 'accumulate' in namespace 'std'
                long size() const { return /*arg.size()*/ std::accumulate(shape.begin() + 1, shape.end(), *shape.begin(), std::multiplies<long>()); }
                                                          ~~~~~^
In file included from /var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:7:
In file included from /Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:6:
In file included from /Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/types/ndarray.hpp:25:
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/types/numpy_gexpr.hpp:283:33: error: no member named 'accumulate' in namespace 'std'
                    return std::accumulate(shape.begin() + 1, shape.end(), *shape.begin(), std::multiplies<long>());
                           ~~~~~^
In file included from /var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:7:
In file included from /Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:5:
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/types/numpy_type.hpp:12:34: error: called object type 'long' is not a function or function pointer
                typedef decltype(std::declval<T>()()) type;
                                 ^~~~~~~~~~~~~~~~~
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:12:44: note: in instantiation of template class 'pythonic::types::numpy_type<long>' requested here
            types::ndarray<typename types::numpy_type<dtype>::type, 1> arange(T begin, U end, S step=S(1), dtype d=dtype())
                                           ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:32:24: note: while substituting deduced template arguments into function template 'arange' [with T = long, U = long, S = <no value>, dtype = <no value>]
                return arange(T(0), end);
                       ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:34:32: note: in instantiation of function template specialization 'pythonic::numpy::arange<long>' requested here
        PROXY(pythonic::numpy, arange);
                               ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/utils/proxy.hpp:21:35: note: expanded from macro 'PROXY'
#define PROXY(ns,f) FPROXY(ns, f, f)
                                  ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/utils/proxy.hpp:15:28: note: expanded from macro 'FPROXY'
                return ns::f(std::forward<Types>(types)...); \
                           ^
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:110:107: note: in instantiation of function template specialization 'pythonic::numpy::proxy::arange::operator()<long>' requested here
    return ((bar()((a + 42L)) + foo()(a)) + pythonic::numpy::proxy::sum{}(pythonic::numpy::proxy::arange{}(10L)));
                                                                                                          ^
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:115:12: note: in instantiation of function template specialization '__pythran_test::mix_builtin_foo::operator()<long>' requested here
    return mix_builtin_foo()(a);
           ^
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:121:33: note: in instantiation of function template specialization '__pythran_test::entry::operator()<long>' requested here
  return __pythran_test::entry()(a0);
                                ^
In file included from /var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:7:
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:32:24: error: call to function 'arange' that is neither visible in the template definition nor found by argument-dependent lookup
                return arange(T(0), end);
                       ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:34:32: note: in instantiation of function template specialization 'pythonic::numpy::arange<long>' requested here
        PROXY(pythonic::numpy, arange);
                               ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/utils/proxy.hpp:21:35: note: expanded from macro 'PROXY'
#define PROXY(ns,f) FPROXY(ns, f, f)
                                  ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/utils/proxy.hpp:15:28: note: expanded from macro 'FPROXY'
                return ns::f(std::forward<Types>(types)...); \
                           ^
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:110:107: note: in instantiation of function template specialization 'pythonic::numpy::proxy::arange::operator()<long>' requested here
    return ((bar()((a + 42L)) + foo()(a)) + pythonic::numpy::proxy::sum{}(pythonic::numpy::proxy::arange{}(10L)));
                                                                                                          ^
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:115:12: note: in instantiation of function template specialization '__pythran_test::mix_builtin_foo::operator()<long>' requested here
    return mix_builtin_foo()(a);
           ^
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmpemQ77S.cpp:121:33: note: in instantiation of function template specialization '__pythran_test::entry::operator()<long>' requested here
  return __pythran_test::entry()(a0);
                                ^
/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/pythonic/numpy/arange.hpp:12:72: note: 'arange' should be declared prior to the call site
            types::ndarray<typename types::numpy_type<dtype>::type, 1> arange(T begin, U end, S step=S(1), dtype d=dtype())
                                                                       ^
4 errors generated.

Type inference

Pythran doesn't succeed type inference with rvalue as a parameter to nested function. (cf euler02.py)

Compilation error in translated code in rosetta fft

This function test gives a compilation error. It seems that the error comes a conversion issue in pythonic++/core/list.h

  2 from cmath import exp, pi
  3 
  4 def fft(x):
  5     N = len(x)
  6     if N <= 1: return x
  7     even = fft(x[0::2])
  8     odd =  fft(x[1::2])
  9     return [even[k] + exp(-2j*pi*k/N)*odd[k] for k in xrange(N/2)] + \
 10            [even[k] - exp(-2j*pi*k/N)*odd[k] for k in xrange(N/2)]
 11 
 12 #pythran export test()
 13 def test():
 14    z = fft([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0])
 15    return z

gmp conversion allocation error

according to valgrind

==1157== 
==1157== Invalid read of size 4
==1157==    at 0x546D0E: PyObject_Free (obmalloc.c:969)
==1157==    by 0x52CDCC: long_to_decimal_string.17557 (longobject.c:2353)
==1157==    by 0x50BA6B: PyObject_Str (object.c:430)
==1157==    by 0x15AFD054: python_to_pythran<__gmp_expr<__mpz_struct [1], __mpz_struct [1]> >::construct(_object*, boost::python::converter::rvalue_from_python_stage1_data*) (pythran_gmp.h:202)
==1157==    by 0x15AF3DE2: boost::python::converter::arg_rvalue_from_python<__gmp_expr<__mpz_struct [1], __mpz_struct [1]> >::operator()() (arg_from_python.hpp:314)
==1157==    by 0x15AF3ADE: _object* boost::python::detail::invoke<boost::python::to_python_value<bool const&>, bool (*)(__gmp_expr<__mpz_struct [1], __mpz_struct [1]>), boost::python::arg_from_python<__gmp_expr<__mpz_struct [1], __mpz_struct [1]> > >(boost::python::detail::invoke_tag_<false, false>, boost::python::to_python_value<bool const&> const&, bool (*&)(__gmp_expr<__mpz_struct [1], __mpz_struct [1]>), boost::python::arg_from_python<__gmp_expr<__mpz_struct [1], __mpz_struct [1]> >&) (invoke.hpp:75)
==1157==    by 0x15AF3985: boost::python::detail::caller_arity<1u>::impl<bool (*)(__gmp_expr<__mpz_struct [1], __mpz_struct [1]>), boost::python::default_call_policies, boost::mpl::vector2<bool, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> > >::operator()(_object*, _object*) (caller.hpp:221)
==1157==    by 0x15AF3036: boost::python::objects::caller_py_function_impl<boost::python::detail::caller<bool (*)(__gmp_expr<__mpz_struct [1], __mpz_struct [1]>), boost::python::default_call_policies, boost::mpl::vector2<bool, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> > > >::operator()(_object*, _object*) (py_function.hpp:38)
==1157==    by 0x112637BA: boost::python::objects::function::call(_object*, _object*) const (in /usr/lib/libboost_python-py27.so.1.49.0)
==1157==    by 0x112639D7: ??? (in /usr/lib/libboost_python-py27.so.1.49.0)
==1157==    by 0x1126C8BA: boost::python::handle_exception_impl(boost::function0<void>) (in /usr/lib/libboost_python-py27.so.1.49.0)
==1157==    by 0x11261CA4: ??? (in /usr/lib/libboost_python-py27.so.1.49.0)
==1157==  Address 0x66eb020 is not stack'd, malloc'd or (recently) free'd

numpy.linalg

Hello all,

i'm trying to use numpy.linalg functions with pythran but I receive an error : Attribute 'linalg' unknown.

How can I fix this ?

thanks,
Fausto

Redundant space after print

The print result form pythran is not the same as python.
Here is an example: a.py

#pythran export foo(int)
def foo(n):
    print n

Then call the foo(n) from a shell:

$> pythran a.py
$> python -c 'import a;a.foo(111)'>a.out

We expect '111' but will get '111 ' in the a.out

exception

exception in c++ are not forwarded to python. Error message is missing and we only have "std::exception" as a message

Compile error with hashes

here's the error: http://pastebin.com/DNzti0pT

For that code:

"""def gb():
    global a;
    a = 2;

def gb2():
    global a;
    a = 3;
"""
#pythran export test()
def test():
    #gb();
    a = 1
    print (a);
    #gb2();
    print (a);

Is my configuration wrong?

(I made sure to have serge's master fully merged and up to date)

Compilation issue with rosetta/yin_and_yang.py (std::hash(int) and array inside)

Add #pythran export test() in the file and try to compile it with pythran yin_and_yang.py -v

The output is:

INFO     Command line: 'c++' '/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp9nkn8T.cpp' '-I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7' '-I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy' '-I….//pythran/install/lib/python2.7/site-packages/.' '-I….//pythran/install/lib/python2.7/site-packages/pythran' '-I….//pythran/install/lib/python2.7/site-packages/pythran/pythonic++' '-DENABLE_PYTHON_MODULE' '-O2' '-g' '-std=c++11' '-O2' '-shared' '-o' 'yin_and_yang.so' '-L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config' '-lpython2.7' '-L/opt/local/lib' '-lboost_python-mt' '-lgmp' '-lgmpxx' '-fPIC'
CRITICAL Leave the vessel! Women and children first!
C++ compiler failed to compile translated code.
E: Compile error!

******** Command line was: ********
'c++' '/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp9nkn8T.cpp' '-I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7' '-I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy' '-I….//pythran/install/lib/python2.7/site-packages/.' '-I….//pythran/install/lib/python2.7/site-packages/pythran' '-I….//pythran/install/lib/python2.7/site-packages/pythran/pythonic++' '-DENABLE_PYTHON_MODULE' '-O2' '-g' '-std=c++11' '-O2' '-shared' '-o' 'yin_and_yang.so' '-L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config' '-lpython2.7' '-L/opt/local/lib' '-lboost_python-mt' '-lgmp' '-lgmpxx' '-fPIC'

******** Output :  ********

In file included from /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1728:0,
                 from /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17,
                 from /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:15,
                 from ….//pythran/install/lib/python2.7/site-packages/./pythran/pythran.h:817,
                 from /var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp9nkn8T.cpp:2:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
  ^
In file included from ….//pythran/install/lib/python2.7/site-packages/pythran/pythonic++/pythonic++.h:9:0,
                 from ….//pythran/install/lib/python2.7/site-packages/./pythran/pythran.h:7,
                 from /var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp9nkn8T.cpp:2:
….//pythran/install/lib/python2.7/site-packages/pythran/pythonic++/core/tuple.h: In instantiation of 'std::size_t std::hash<std::array<_Tp, _Nm> >::operator()(const std::array<_Tp, _Nm>&) const [with T = long int; long unsigned int N = 2ul; std::size_t = long unsigned int]':
/opt/local/include/gcc48/c++/bits/hashtable_policy.h:1103:22:   required from 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true>::__hash_code std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true>::_M_hash_code(const _Key&) const [with _Key = std::array<long int, 2ul>; _Value = std::pair<const std::array<long int, 2ul>, pythonic::core::string>; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash<std::array<long int, 2ul> >; _H2 = std::__detail::_Mod_range_hashing; std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true>::__hash_code = long unsigned int]'
/opt/local/include/gcc48/c++/bits/hashtable_policy.h:487:49:   required from 'std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::mapped_type& std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::operator[](const key_type&) [with _Key = std::array<long int, 2ul>; _Pair = std::pair<const std::array<long int, 2ul>, pythonic::core::string>; _Alloc = std::allocator<std::pair<const std::array<long int, 2ul>, pythonic::core::string> >; _Equal = std::equal_to<std::array<long int, 2ul> >; _H1 = std::hash<std::array<long int, 2ul> >; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>; std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::mapped_type = pythonic::core::string; std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::key_type = std::array<long int, 2ul>]'
/opt/local/include/gcc48/c++/bits/unordered_map.h:596:20:   required from 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type&) [with _Key = std::array<long int, 2ul>; _Tp = pythonic::core::string; _Hash = std::hash<std::array<long int, 2ul> >; _Pred = std::equal_to<std::array<long int, 2ul> >; _Alloc = std::allocator<std::pair<const std::array<long int, 2ul>, pythonic::core::string> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type = pythonic::core::string; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type = std::array<long int, 2ul>]'
….//pythran/install/lib/python2.7/site-packages/pythran/pythonic++/core/dict.h:138:62:   required from 'V& pythonic::core::dict<K, V>::operator[](const K&) [with K = std::array<long int, 2ul>; V = pythonic::core::string]'
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp9nkn8T.cpp:487:10:   required from 'typename __yin_and_yang::yinyang::type<argument_type0>::result_type __yin_and_yang::yinyang::operator()(argument_type0&&) const [with argument_type0 = long int; typename __yin_and_yang::yinyang::type<argument_type0>::result_type = pythonic::core::string]'
/var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp9nkn8T.cpp:530:22:   required from here
….//pythran/install/lib/python2.7/site-packages/pythran/pythonic++/core/tuple.h:162:32: error: no match for call to '(std::hash<long int>) (const std::array<long int, 2ul>&)'
                     seed ^= h(l) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
                                ^
In file included from /opt/local/include/gcc48/c++/bits/basic_string.h:3035:0,
                 from /opt/local/include/gcc48/c++/string:52,
                 from /opt/local/include/gcc48/c++/bits/locale_classes.h:40,
                 from /opt/local/include/gcc48/c++/bits/ios_base.h:41,
                 from /opt/local/include/gcc48/c++/ios:42,
                 from /opt/local/include/gcc48/c++/ostream:38,
                 from /opt/local/include/gcc48/c++/iterator:64,
                 from ….//pythran/install/lib/python2.7/site-packages/pythran/pythonic++/core/utils.h:5,
                 from ….//pythran/install/lib/python2.7/site-packages/pythran/pythonic++/pythonic++.h:5,
                 from ….//pythran/install/lib/python2.7/site-packages/./pythran/pythran.h:7,
                 from /var/folders/b6/s_v2kl3918s2v6lf3xpqnp100000gn/T/tmp9nkn8T.cpp:2:
/opt/local/include/gcc48/c++/bits/functional_hash.h:107:3: note: candidate is:
   _Cxx_hashtable_define_trivial_hash(long)
   ^
/opt/local/include/gcc48/c++/bits/functional_hash.h:107:3: note: std::size_t std::hash<long int>::operator()(long int) const
   _Cxx_hashtable_define_trivial_hash(long)
   ^
/opt/local/include/gcc48/c++/bits/functional_hash.h:107:3: note:   no known conversion for argument 1 from 'const std::array<long int, 2ul>' to 'long int'

Aliases analysis crashes on attributes handling

import numpy
import math as m
def mix_builtin_foo(a):
    return ((bar((a + 42)) + foo(a)) + m.floor(numpy.cos(2)))
def bar(a):
    return (a + 42)
def foo(a):
    return (a + (2 * 42))
def entry(a):
    return mix_builtin_foo(a)

#pythran export entry(int)

End of stack trace:

  File "/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/passmanager.py", line 55, in visit
    return super(ContextManager, self).visit(node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/analysis.py", line 678, in visit_Attribute
    return self.add(node, {Aliases.access_path(node)})
  File "/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/analysis.py", line 586, in access_path
    return rec(modules, node)
  File "/Users/amini/projects/pythran/install/lib/python2.7/site-packages/pythran/analysis.py", line 581, in rec
    return rec(w, n.value)[n.attr]
TypeError: string indices must be integers, not str

typing issue

Here is a code which doesn't work:

#pythran export s_perm(int list)

def s_perm(seq):
    if not seq:
        return [[]]
    else:
        new_items = []
        for item in s_perm(seq[:-1]):
            new_items += [item + seq for i in range(1)]
        return new_items

return type of s_perm is list<empty_list> which is not correct.

It happen because new_items is a combine of something depending of test. Test is weak as it is not in self.current_global_declaration as it is recursif. It is add in this dict only after the generic_visit.
I tried to move the self.current_global_declaration assignment but It is not safe and I don't know if it is meaningful.

Good luck serge :)

Tuple in Generator Expression -> Compilation fails

When a generator expression uses tuples, compilation fails.

Example :

def foo(n):
    return sum(b + c for x in range(n) for b,c in zip(range(x),range(x)))

( The only purpose of x here is to prevents transformation into imap(...))

Simpler example (requires to desactivate the proper transformation)

def foo(n):
    return sum(b + c for for b,c in zip(range(n),range(n)))

Error message from gcc :

/tmp/tmpasc2PJ.cpp:119:119: warning: jump to label ‘yield_point1’ [-fpermissive]
/tmp/tmpasc2PJ.cpp:108:46: warning:   from here [-fpermissive]
/tmp/tmpasc2PJ.cpp:118:18: error:   crosses initialization of ‘std::tuple<long int, long int> __tuple11’

clang :

/tmp/tmpasc2PJ.cpp:108:41: error: goto into protected scope
switch(__generator_state) { case 1: goto yield_point1; };
                                    ^
/tmp/tmpasc2PJ.cpp:118:18: note: jump bypasses variable initialization
        auto __tuple11= *__target2;

py.test output is a mess

When the compilation of a unittest fails, the output is full of useless python stuff while the detailed error from gcc or clang is incomplete.

It would also be nice to save temporary files in this case along with the compile command used so that reproduction is trivial. Let's say that if gcc/clang compilation fails then an archive is produced containing the input python, the intermediate c++, and the command line that failed.

setup test

now, test is running on pythonpath instead of ".". So it should test installation. I think python setup.py test should trigger python setup.py installation before (or reinstallation maybe to keep --prefix information for example)

euler test cases fail to run

These test cases pass the unittest because they are only compiled but not run.
If we run with the euler files, we can find that:

  • euler26 cause infinite loop
  • euler14, euler22, euler42, euler56 have segmentation faults
  • euler53 has a floating point exception
  • euler 55: python: pythran/pythran/pythonic++/core/string.h:55: pythonic::core::string_view::const_iterator pythonic::core::string_view::end() const: Assertion `slicing.step==1' failed.
    Aborted (core dumped)

lastly, euler47 and euler58 are even not supported by python.(the code is not correct but can be compiled however by pythran)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.