Jason Grout wrote:
> Carlo Hamalainen wrote:
>> On Wed, Sep 16, 2009 at 7:46 PM, Jason Grout
>> <jason-s...@creativetrax.com> wrote:
>>> R has a C interface for lots of functions (like the distribution
>>> functions that I wanted today).  I imagine that a stats module would use
>>> Cython to call the C functions for these sorts of things, but then use
>>> rpy2 for the rest of the interaction with R.
>> Which distribution functions did you want? Are these of any use?
>> http://trac.sagemath.org/sage_trac/ticket/6827
>>
> 
> 
> I tried generating lots of normally distributed values after applying 
> the patch.  It seems that scipy was the winner by far for speed:
> 
> sage: a=RealDistribution('gaussian', 2)
> sage: %timeit [a.get_random_element() for _ in range(1000)]
> 100 loops, best of 3: 2.87 ms per loop
> sage: import scipy.stats
> sage: %timeit scipy.stats.norm.rvs(0,2,size=1000)
> 1000 loops, best of 3: 252 µs per loop
> sage: %timeit r.rnorm(1000,0,2).sage()
> 10 loops, best of 3: 37 ms per loop
> 

Actually, using rpy2 (and R 2.9.2), the new R<->Python interface, we can 
get much closer to the scipy timing:

sage: import rpy2
sage: import rpy2.robjects as robjects
sage: %timeit numpy.array(robjects.r.rnorm(int(1000),int(0),int(2)))
1000 loops, best of 3: 782 µs per loop

lgautier, feel free to correct my example to make it faster!

My draft of an updated R and rpy2 spkg is at 
http://sage.math.washington.edu/home/jason/r-2.9.2.spkg.  There are 
unchecked-in changes in the spkg, and I just ignored a bunch of old 
patches to R because I wasn't sure they applied anymore, so the spkg is 
not finished.

Andrew, if you want to take the spkg and work with William to make sure 
that it is a good spkg (e.g., the appropriate patches get pulled over 
from the old spkg, etc.), go right ahead!  I think someone like William 
or one of the other spkg experts around here will do much better than me 
at untangling the old patches and figuring out if we need to have them 
anymore.


Jason

-- 
Jason Grout


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to