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

Chris Seaton chris.seaton at oracle.com
Tue Oct 16 13:30:18 PDT 2018


I don't completely understand the problem - an issue we have is that our Ruby people don't know R very well and our R people don't know Ruby very well, so you might have the most understanding of how this should work of anyone.

From talking to the R people, I think what you want is a table with columns something like (name, age, height), and then rows with values for each of those columns.

You want a Ruby object that can be used to provide the data for that table without copying.

We might normally define an array of rows like this where each row is an object.

[
  {name: 'Chris', age: 20, height: 181},
  {name: 'John', age: 35, height: 179}
]

This isn't what R is expecting though - it wants a column-oriented format.

{
  name: ['Chris', 'John'],
  age: [20, 25],
  height: [181, 179]
}

We can convert but that's the copying you don't want to do.

def copy_rows_to_columns(rows)
  rows.first.keys.map { |key|
    [key, rows.map { |row| row[key] }]
  }.to_h
end

Can we provide a view that provides this format from the former structure? This does that using an mock array for each column.

class Column

  def initialize(rows, name)
    @rows = rows
    @name = name
  end

  def size
    @rows.size
  end

  def [](index)
    @rows[index][@name]
  end

end

def view_rows_to_columns(rows)
  rows.first.keys.map { |key|
    [key, Column.new(rows, key)]
  }.to_h
end

But this won't do what you want at the moment, because Column isn't an Array, and only arrays appear to be arrays to foreign languages (only arrays respond to HAS_SIZE). Maybe that's wrong?

We can try to subclass Array, but this will start to mess things up very quickly. You'll have to define your own #inspect for example, and the array is allocating the storage we aren't using.

class ArrayColumn < Array

  def initialize(rows, name)
    @rows = rows
    @name = name
  end

  def size
    @rows.size
  end

  def [](index)
    @rows[index][@name]
  end

  def inspect
    '[' + (0...size).map { |n| self[n] }.join(', ') + ']'
  end

end

def view_rows_to_columns_array(rows)
  rows.first.keys.map { |key|
    [key, ArrayColumn.new(rows, key)]
  }.to_h
end

p view_rows_to_columns_array(rows)

Maybe it should be easier to create proxy arrays in Ruby for interop?


> On 15 Oct 2018, at 21:19, Rodrigo Botafogo <rodrigo.a.botafogo at gmail.com> wrote:
> 
> Great post...
> 
> It shows there how to wrap a Java array with ProxyArray to build an R dataframe.  Is something similar possible with Ruby?  Is there any way to wrap a Ruby array, or any other class for that matter, in such a way that it can be converted to an R dataframe with the same Ruby backed data?
> 
> Thanks!
> 
> On Fri, Oct 12, 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. MethodHandle and VarHandles for GraalVM 11 (Kasper Nielsen)
>    2. new blog post: Faster R with FastR (Oleg ?elajev)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Fri, 12 Oct 2018 09:38:19 +0100
> From: Kasper Nielsen <kasperni at gmail.com>
> Subject: [graalvm-users] MethodHandle and VarHandles for GraalVM 11
> To: graalvm-users at oss.oracle.com
> Message-ID:
>         <CAPs6151ORh9EmppysEq7THx235psBpCWF=m3+3EcBj8J_dfyZA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> Hi,
> 
> With MethodHandles and VarHandles being the only safe way to access members
> across module boundaries for Java 11 and greater.
> How will the limits outlined here
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_oracle_graal_blob_master_substratevm_LIMITATIONS.md-23invokedynamic-2Dbytecode-2Dand-2Dmethod-2Dhandles&d=DwIBaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=eB7NOfFFa-lNWC35epoJT1gnKeKzO4v-75i3-xj8iOA&s=-fRbUyYzG85Nd8Gb8E_fR0Zo8rqDRDzTWxFwOMqK2FM&e=
> be effected.
> I assume as a minimum things such as MethodHandle.Lookup.unreflect* and
> MethodHandle.Lookup.find* will work for runtime reflected members?
> 
> Cheers
>   Kasper
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20181012/24af8789/attachment-0001.html 
> 
> ------------------------------
> 
> Message: 2
> Date: Fri, 12 Oct 2018 14:01:01 +0300
> From: Oleg ?elajev <OLEG.SELAJEV at ORACLE.COM>
> Subject: [graalvm-users] new blog post: Faster R with FastR
> To: graalvm-users at oss.oracle.com
> Message-ID: <6CD6D41A-4DFF-4E97-90E7-3128A4196BF8 at ORACLE.COM>
> Content-Type: text/plain; charset="utf-8"
> 
> Hi, 
> 
> ?t?p?n ?indel?? wrote a very instructive article on FastR, the GraalVM's implementation of R: https://medium.com/graalvm/faster-r-with-fastr-4b8db0e0dceb <https://medium.com/graalvm/faster-r-with-fastr-4b8db0e0dceb>
> 
> In which he talks about the compatibility with GNU-R, polyglot and using R from Java and Python, and some performance benchmarks. 
> If you didn't get acquainted with FastR yet (actually even if you did look at it in the past), it's really good material to go over! 
> 
> 
> Oleg
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20181012/26c4b98d/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 7, Issue 3
> *******************************************
> 
> 
> -- 
> Rodrigo Botafogo
> Integrando TI ao seu negócio
> 21-3010-4802/11-3010-1802
> _______________________________________________
> GraalVM-Users mailing list
> GraalVM-Users at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/graalvm-users




More information about the GraalVM-Users mailing list