Pure Python Math Library
Does anyone know of a pure python math library? I've been playing around with berp <https://github.com/bjpop/berp/wiki>, which is a python3 to haskell translator and compiler, and it works great as long as you don't go crazy with C extensions. It's highly experimental but fun to play around with. The only thing that I really miss is being able to use the math module. I asked the maintainer if it is possible to map into haskell's math library, but in the mean time a pure python math library would fit nicely since it would be compiled along with the rest of the python. I'm looking for log, log10, ceil, and pow mostly for my personal needs. It's funny now that things like pypy and berp exist. I find myself trying to locate pure python routines (like DFT) that would have no reason to exist with cpython, but make lots of sense with pypy. Anyway, just wondering if anyone had heard of such a thing. How do you even implement log? Thanks, Blaine
On Wed, Nov 16, 2011 at 12:26 PM, Blaine <frikker@gmail.com> wrote:
It's a part of the standard library, it's implemented however the Python VM provides it. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Evelyn Beatrice Hall (summarizing Voltaire) "The people's good is the highest law." -- Cicero
Thanks Alex and Benjamin. I'm sorry - you're right it isn't exactly related to pypy. I hope I didn't break any rules. I was hoping that someone else may have come across this because the only time I've needed to port compiled modules to python is when I wanted to use them with pypy. Blaine On Wed, Nov 16, 2011 at 12:29 PM, Alex Gaynor <alex.gaynor@gmail.com> wrote:
I imagine pypy uses libc math through ctypes, since pypy and ctypes play well together. Thanks for all the tips, I'll probably just wait to see what the maintainer thinks about mapping to haskell's math library. Blaine On Wed, Nov 16, 2011 at 12:36 PM, Benjamin Peterson <benjamin@python.org>wrote:
On Wed, Nov 16, 2011 at 12:38 PM, Blaine <frikker@gmail.com> wrote:
No, PyPy has an RPython math module which calls libc. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Evelyn Beatrice Hall (summarizing Voltaire) "The people's good is the highest law." -- Cicero
http://en.literateprograms.org/Logarithm_Function_(Python) ceil seems pretty easy to implement... pow? Integer only? --C ________________________________ From: Blaine <frikker@gmail.com> To: pypy-dev@python.org Sent: Wednesday, November 16, 2011 9:21 AM Subject: [pypy-dev] Pure Python Math Library Does anyone know of a pure python math library? I've been playing around with berp, which is a python3 to haskell translator and compiler, and it works great as long as you don't go crazy with C extensions. It's highly experimental but fun to play around with. The only thing that I really miss is being able to use the math module. I asked the maintainer if it is possible to map into haskell's math library, but in the mean time a pure python math library would fit nicely since it would be compiled along with the rest of the python. I'm looking for log, log10, ceil, and pow mostly for my personal needs. It's funny now that things like pypy and berp exist. I find myself trying to locate pure python routines (like DFT) that would have no reason to exist with cpython, but make lots of sense with pypy. Anyway, just wondering if anyone had heard of such a thing. How do you even implement log? Thanks, Blaine _______________________________________________ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev
The following code is a lot slower with pypy as compared to CPython. The code mainly measures the time taken to execute a simple SQLite user defined function (UDF) and a more complex one, 1000000 times each. Execution time for both queries is: CPython 2.7: 7 sec 489 msec Pypy nightly build: 28 sec 753 msec Execution time for simple query only is: CPython 2.7: 1 sec 39 msec Pypy nightly build: 13 sec 645 msec Pypy seems to not jit at all when a (pypy) Python function is called from C. Also based on the simple query times, pypy seems to have massive overhead (nearly 13 times slower) when executing callbacks from C code. lefteris. --- code -- import sqlite3 import datetime # Simple function def testfun(*args): return 1 # Complex function def sectohuman(*args): secs=int(args[0]) h='' days=secs/86400 if days > 0: h+=str(days)+' day' if days > 1: h+='s' h+=' ' secs=secs % 86400 hours=secs/3600 if hours > 0: h+=str(hours)+' hour' if hours > 1: h+='s' h+=' ' secs=secs % 3600 mins=secs/60 if mins > 0: h+=str(mins)+' min ' secs=secs % 60 if secs > 0: h+=str(secs)+' sec' return h con=sqlite3.Connection('') con.create_function('testfun', -1, testfun) con.create_function('sectohuman', -1, sectohuman) cur=con.cursor() cur.execute('create table l(a);') cur.execute('begin;') for i in xrange(1000000): cur.execute('insert into l values(?)',(i,)) before=datetime.datetime.now() # Simple query a=list(cur.execute('select sum(testfun(a)) as s from l')) # Complex query a=list(cur.execute('select sum(length(sectohuman(a))) as s from l')) after=datetime.datetime.now() tmdiff=after-before print "Execution time is %s min. %s sec %s msec" %((int(tmdiff.days)*24*60+(int(tmdiff.seconds)/60),(int(tmdiff.seconds)%60),(int(tmdiff.microseconds)/1000)))
participants (6)
-
Alex Gaynor
-
Benjamin Peterson
-
Blaine
-
Charlie Hui
-
Elefterios Stamatogiannakis
-
Peter Cock