[graalvm-users] GraalVM-Users Digest, Vol 3, Issue 7

Rodrigo Botafogo rodrigo.a.botafogo at gmail.com
Mon Jun 18 15:08:36 PDT 2018


Hi Stepan,

I didn’t know about the [<- function. Is this a standard R function or is
this something that is provided by Graal?
I would love to have more detailed documentation that could help me do the
Ruby x R interop. Anything you have is helpful.

Ruby is very flexible and allow overriding operators like “[“. My intention
is actually to write wraps to the whole R
language with Ruby allowing a Ruby programmer to work transparently in R.

You can take a look at:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_rbotafogo_scicom_wiki_A-2D-28not-2Dso-29-2DShort-2DIntroduction-2Dto-2DSciCom&d=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=RBlRYePnq4KmOZDP2Oxeo7XfeGCfeYBwEZkdtOZCU14&s=GADKw3DrBgyEli6xS2LT_0-_cPNt0XoI_nvBUyrXssY&e=
,
for more information on what I intend to with fastR. This already works for
Renjin.
Here for example is a code in Ruby (wrapping R in Renjin).

This is a SciCom script to print the number of days for every month is 2005:

require ‘scicom’

everyday = R.seq(from: R.as__Date('2005-1-1'), to:
R.as__Date('2005-12-31'), by: 'day')
cmonth = everyday.format('%b')
cmonth
 .factor(levels: cmonth.unique, ordered: TRUE)
 .table
 .pp

Thanks
​

On Sun, Jun 17, 2018 at 4:00 PM <graalvm-users-request at oss.oracle.com>
wrote:

> Send GraalVM-Users mailing list submissions to
>         graalvm-users at oss.oracle.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://oss.oracle.com/mailman/listinfo/graalvm-users
> or, via email, send a message with subject or body 'help' to
>         graalvm-users-request at oss.oracle.com
>
> You can reach the person managing the list at
>         graalvm-users-owner at oss.oracle.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of GraalVM-Users digest..."
>
>
> Today's Topics:
>
>    1. Re: How to remove/opearte on an R vector through Interop? (Stepan)
>    2. Re: Testing polyglot libs (Benoit Daloze)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 16 Jun 2018 23:25:39 +0200
> From: Stepan <stepan.sindelar at oracle.com>
> Subject: Re: [graalvm-users] How to remove/opearte on an R vector
>         through Interop?
> To: graalvm-users at oss.oracle.com
> Message-ID: <97018432-d6e7-6d4b-b146-feb6b276b191 at oracle.com>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
> Hi Rodrigo,
>
> I think the idea of Truffle interop is that once the object, in this
> case, R vector, goes into another language, the other language tries to
> treat it as if it were its "native" object. In this case, it means Ruby
> tries to apply the semantics of Ruby indexing to R vector. R vectors are
> immutable and cannot be modified, what looks like you're modifying data
> of a vector in R:
>
> myVector[42] <- newValue
>
> is in fact translated into (btw. you can execute this snippet as is too):
>
> myVector <- `[<-`(myVector, 42, newValue)
>
> There's a function called `[<-` that takes the vector as a first
> parameter and returns a new vector. The old vector stays unchanged (or
> at least any modifications must not be observable).
>
> What you can do is to retrieve the `[<-` function from R and use it:
>
> Ruby code:
> vec = Polyglot.eval("R", "c(1,2,3)")
> subsetAssign = Polyglot.eval("R", "`[<-`")
> vec = subsetAssign.call(vec, 1, 42)
> p vec[0]
>
> I don't know much of Ruby, but if Ruby allows overriding operators like
> "[" you can create a Ruby class that wraps R vector and delegates all
> the Ruby operations to appropriate R operations. This is what Rcpp
> package does with R and C++. Rcpp uses the ability to override various
> operators in C++ to provide R-like embedded DSL in C++ using the R to C
> interface (btw. supported by both GNU R and R in GraalVM). Building
> something like this in Ruby or any such flexible language would be an
> interesting project.
>
> We could, of course, support this approach natively in the Truffle
> interop, but that would mean doing the mapping of one semantics to
> another for all the language pairs, and interop aims to be generic. I
> think the current interop approach provides all the necessary primitives
> to implement such mapping in user code.
>
> Regards,
> Stepan
>
>
>
> ------------------------------
>
> Message: 2
> Date: Sun, 17 Jun 2018 20:31:41 +0200
> From: Benoit Daloze <eregontp at gmail.com>
> Subject: Re: [graalvm-users] Testing polyglot libs
> To: Rodrigo Botafogo <rodrigo.a.botafogo at gmail.com>,
>         graalvm-users at oss.oracle.com
> Message-ID:
>         <
> CANLTa0AgDCDkarivSRbZHHSbS0JoSSVhhfNiOb3fgxeCbrHQsA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Yes, it makes perfect sense.
> Actually we need that capability for mini_racer, where we want multiple
> JavaScript context from one Ruby context.
>
> Could you file an issue on
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_oracle_graal_issues&d=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=k7NRPYUa8hjmUxEjgM1rZa-K7Yt8fd_MlzBgZcYjifE&s=hJCnVwQXTVi6XYSKjhkjsNsQZRzY0vKyr3P7L26UrNs&e=
> with what
> you just explained to track progress on this more easily?
>
> On Fri, Jun 15, 2018 at 1:57 PM, Rodrigo Botafogo <
> rodrigo.a.botafogo at gmail.com> wrote:
>
> > Benoit,
> >
> > Actually, I think I have a pricise use case... let's say I'm building a
> > Web Application that at some point might need to develop a data model for
> > the user.  In this case:
> >
> >    - I don't want my web application to be single threaded just because
> >    eventually I'll need to interface with R to build a data model;
> >    - Since building a data model is time usually consuming, then the best
> >    would be do have a worker thread take care of this model while not
> >    impacting user's interaction;
> >    - Since different users might request different models, it would be
> >    ideal if I could "instantiate" a new R for every users and run that on
> >    there own threads.
> >
> > Makes sense?
> >
> >
> > On Thu, Jun 14, 2018 at 4:54 PM Rodrigo Botafogo <
> > rodrigo.a.botafogo at gmail.com> wrote:
> >
> >> Benoit,
> >>
> >> At this point I don't really have a precise use case.  If there is a
> flag
> >> to force multithread and the user calls R from two threads, I think
> >> crashing would be the safest thing for R to do!
> >>
> >> It just seems a very strong restriction to prevent the code from running
> >> just because there is an integration.  Letting it run with an override
> flag
> >> would allow the use cases to appear.
> >>
> >> Thanks!
> >>
> >> On Thu, Jun 14, 2018 at 4:00 PM Benoit Daloze <eregontp at gmail.com>
> wrote:
> >>
> >>> Indeed, we'd like to allow such a scenario and we are trying to figure
> >>> out how to make this work and still be safe.
> >>>
> >>> One interesting question is: what should happen if R is called from
> >>> another Ruby thread?
> >>>
> >>> If you have a precise use-case in mind, could you post an issue on
> >>>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_oracle_graal_issues&d=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=k7NRPYUa8hjmUxEjgM1rZa-K7Yt8fd_MlzBgZcYjifE&s=hJCnVwQXTVi6XYSKjhkjsNsQZRzY0vKyr3P7L26UrNs&e=
> to track it more easily?
> >>>
> >>> On Thu, Jun 14, 2018 at 7:44 PM, Rodrigo Botafogo <
> >>> rodrigo.a.botafogo at gmail.com> wrote:
> >>>
> >>>> Thanks Benoit!
> >>>>
> >>>> Now, is it really necessary to prevent multithreaded when interfacing
> >>>> Ruby and R?  I understand that since R is not multithreaded, calling
> it
> >>>> from multiple threads will cause weird problems, but if the
> programmer is
> >>>> careful and say, only calls R from the same Ruby thread, everything
> should
> >>>> work fine, no?  If this is the case, then could there be a flag to
> allow
> >>>> multithreaded applications even in the presence of R?
> >>>>
> >>>> Thanks
> >>>>
> >>>>
> >>>> On Thu, Jun 14, 2018 at 2:38 PM Benoit Daloze <eregontp at gmail.com>
> >>>> wrote:
> >>>>
> >>>>> Note that one way to avoid MinitTest creating multiple threads is to
> >>>>> give it `N=0` like
> >>>>>
> >>>>> $ N=0 ruby -Xsingle_threaded=true mytest.rb
> >>>>>
> >>>>> I checked and this seems to work fine with GraalVM RC2 and minitest
> >>>>> 5.10.1 (bundled) and 5.11.3 (latest).
> >>>>>
> >>>>> On Thu, Jun 14, 2018 at 5:25 PM, Rodrigo Botafogo <
> >>>>> rodrigo.a.botafogo at gmail.com> wrote:
> >>>>>
> >>>>>> Hello,
> >>>>>>
> >>>>>> I'm trying to set up testing for my polyglot lib and I'm having a
> >>>>>> hard time.  Sorry if I should post somewhere else...
> >>>>>>
> >>>>>> So I tried to test with rspec, but rspec will run ruby somehow and
> >>>>>> does not pass to ruby the --polyglot --jvm flags.  Polyglot
> complains that
> >>>>>> R is not a known language.  I've googled around and could not find
> an easy
> >>>>>> way to make rspec pass flags to ruby.
> >>>>>>
> >>>>>> Next I tried minitest, since in this case I call ruby directly with
> >>>>>> the required flags... but polyglot complains that R cannot execute
> in
> >>>>>> multithreaded, so I passed -Xsingle_threaded to ruby and minitest
> complains
> >>>>>> that it only runs in a multithreaded environment.
> >>>>>>
> >>>>>> Any suggestions how to move forward?
> >>>>>>
> >>>>>>
> >>>>>> Thanks
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> Rodrigo Botafogo
> >>>>>>
> >>>>>> _______________________________________________
> >>>>>> GraalVM-Users mailing list
> >>>>>> GraalVM-Users at oss.oracle.com
> >>>>>> https://oss.oracle.com/mailman/listinfo/graalvm-users
> >>>>>>
> >>>>>
> >>>>>
> >>>>
> >>>> --
> >>>> Rodrigo Botafogo
> >>>> Integrando TI ao seu neg?cio
> >>>> 21-3010-4802/11-3010-1802
> >>>>
> >>>
> >>>
> >>
> >> --
> >> Rodrigo Botafogo
> >> Integrando TI ao seu neg?cio
> >> 21-3010-4802/11-3010-1802
> >>
> >
> >
> > --
> > Rodrigo Botafogo
> > Integrando TI ao seu neg?cio
> > 21-3010-4802/11-3010-1802
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://oss.oracle.com/pipermail/graalvm-users/attachments/20180617/09c63ed8/attachment-0001.html
>
> ------------------------------
>
> _______________________________________________
> GraalVM-Users mailing list
> GraalVM-Users at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/graalvm-users
>
> End of GraalVM-Users Digest, Vol 3, Issue 7
> *******************************************
>


-- 
Rodrigo Botafogo
Integrando TI ao seu negócio
21-3010-4802/11-3010-1802
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20180618/960aa521/attachment-0001.html 


More information about the GraalVM-Users mailing list