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.

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


>
>  -- William
>
>
>
>
>
>
>
>
>
>
>
> > Maybe we need to upgrade the rpy2 in Sage...
>
> > William
>
> >> On May 18, 2:14 pm, William Stein <wst...@gmail.com> wrote:
> >>> Hi,
>
> >>> I was preparing a lecture [1] on rpy2 [2] in Sage (version 4.6.2) and 
> >>> notice
> >>> that the following very important central bit of rpy2 functionality --
> >>> namely converting a numpy array to R -- seems to be horribly broken:
>
> >>> sage: import rpy2.robjects as robjects      # standard
> >>> sage: import rpy2.robjects.numpy2ri         # enable automatic
> >>> conversion from numpy to R
> >>> sage: import numpy                                   # make numpy 
> >>> available
> >>> sage: print robjects.r(numpy.array([1,2,3], dtype=float))       # try
> >>> it out; sad result.
> >>> [1] 3
>
> >>> The output *should* be a vector with 3 entries, I think.
> >>> There are similar problems with numpy arrays.
>
> >>> The same problem happens with 4.7.rc1.
>
> >>> I've never used rpy2 seriously before now, so if I'm just confused,
> >>> can somebody who knows rpy2 better let me know.
>
> >>>  -- William
>
> >>> [1]  http://flask.sagenb.org/home/pub/57/
> >>> [2]http://rpy.sourceforge.net/rpy2/doc-2.0/html/numpy.html
>
> >>> --
> >>> William Stein
> >>> Professor of Mathematics
> >>> University of Washingtonhttp://wstein.org
>
> >> --
> >> 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 
> >> athttp://groups.google.com/group/sage-devel
> >> URL:http://www.sagemath.org
>
> > --
> > William Stein
> > Professor of Mathematics
> > University of Washington
> >http://wstein.org
>
> --
> William Stein
> Professor of Mathematics
> University of Washingtonhttp://wstein.org

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