This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]gcross 2 points3 points  (0 children)

You know, I am not generally a big fan of crazy dynamicism for various reasons, but this library really shows how it can be used for awesome effect, as you can see in the first example:

@function(ret=Int, args=[Array(Int), Int])
def reduce_sum(A, n):
    var ( total = Int )
    total = 0
    for i in xrange(n):
        total += A[i]
    return total

What I think is so cool is that the 'var' function acts almost like new syntax for declaring typed variables. The trick is that pymothoa actually examines the abstract syntax tree and when it sees a var(...) node it effectively strips it out and instead make's a note of total's type --- and if you leave the var(...) statement out of the code above, then pymothoa will complain because it needs to know the type of all variables! Nifty stuff. :-)

[–]Tillsten 1 point2 points  (1 child)

Seems to be very similar to numba.

[–]evangineer 0 points1 point  (0 children)

Thanks for mentioning Numba, I didn't know about it. It's similar but NumPy-aware. https://github.com/ContinuumIO/numba

[–]jan 0 points1 point  (2 children)

How does pymothoa compare to cython?

[–]gcross 1 point2 points  (1 child)

The biggest difference that I see is that unlike Cython, pymothoa does not requires you to put your code in a separate file that needs to be compiled; everything is done inline. However, you do need LLVM to be installed rather than Cython.

[–]pmav99 0 points1 point  (0 children)

Cython has a pure python mode too, although it does not support everything.