On Wed, May 18, 2011 at 10:59 PM, lgautier <lgaut...@gmail.com> wrote:
>
>
> On May 18, 11:21 pm, William Stein <wst...@gmail.com> wrote:
>> On Wed, May 18, 2011 at 2:16 PM, William Stein <wst...@gmail.com> wrote:
>> > On Wed, May 18, 2011 at 12:24 PM, kcrisman <kcris...@gmail.com> wrote:
>> >> On the page you linked to:
>> >> "This the documentation for what will be soon the older version of
>> >> rpy2. Do consider the upcoming 2.1.x releases if you are starting a
>> >> project now."
>>
>> >> If you look athttp://rpy.sourceforge.net/rpy2/doc-2.2/html/changes.html
>> >> it also seems like in higher-numbered releases there are changes in
>> >> this functionality.  Maybe this is a known bug; can you try
>>
>> >> from rpy2.robjects.numpy2ri import numpy2ri
>> >> ro.conversion.py2ri = numpy2ri
>>
>> >> as on the 2.2 documentation and see if that works.
>>
>> > Nope, not at all.
>>
>> >> That said, I never use it - I always use the Sage pexpect interface to
>> >> R.  But now I will bookmark this worksheet if I get the chance to give
>> >> another R/Sage talk!
>>
>> > The Sage pexpect is slow and brittle if the size of data you need to
>> > move into or out of R is large.  The rpy2 interface is much more
>> > robust in this regard.
>> > But rpy2 is also somewhat weird and wacky, as I learned today.
>>
>> And, surprisingly, it is not very fast for evaluating basic
>> expression.   It's really *shockingly* slow for a C library interface.
>>  I don't know how it can be so bad:
>>
>> sage: import rpy2.robjects as robjects
>> sage: R = robjects.r
>> sage: print R('2 + 3')  # the rpy2 cython interface (note the import!)
>
> I don't think that Cython is currently used anywhere in rpy2.

I know.  I meant "C library" interface. Sorry for the confusion.

>
>> [1] 5
>> sage: timeit("r('2+3')")
>> 5 loops, best of 3: 1.46 ms per loop
>> sage: timeit("R('2+3')")
>> 625 loops, best of 3: 686 µs per loop
>> sage: timeit("pari('2+3')")
>> 625 loops, best of 3: 5.64 µs per loop
>>
>> Seriously?   686 microseconds to do 2+3?     Our PARI C library
>> interface does that in 5.64 microseconds.
>
> You may want to check your settings. Here I have with Python 2.7 /
> R-2.13 / rpy2-2.2.0beta3 :
>
>>>> import timeit
>>>> t = timeit.Timer(stmt="R('1+2')", setup="import rpy2.robjects; R = 
>>>> rpy2.robjects.r")
>>>> print "%.2f usec/pass" % (10000 * t.timeit(number=1000)/1000)
> 1.37 usec/pass

I get the same horrible timings (around 305 microseconds) on Linux as
well, so it's not some trivial setting issue.
>From your benchmark, the problem must be either the version of R,
Python, or rpy2 that we
ship with Sage.  All are older than the versions you're testing above.
  I'm very glad that
there is some future version of rpy2 where it isn't so slow; thanks
for letting me know.
I hope somebody will update rpy2 (and/or) in Sage.

 -- William

-- 
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