Ruby and science?

I am really puzzled.

I am a scientist and I have been using ruby for years. I like thinking
and programming in ruby, but feel more and more uneasy. I’ll try to
express my feelings below (I am not a native English speaker).

The ruby language and the ruby ecosystem (and the wonderful ruby
community) fit perfectly with small applications, scripting, web
frameworks, and so on. When you come to science, it is another story.
Numerical computing, statistics, whatever, cannot be coded in pure ruby
and you have to rely on specialized libraries. There are tentative gems
(generally obsolete and not maintained) to connect ruby to these
librairies.

Take for instance ‘linalg’ for linear algebra. It is based on LAPACK.
You need a Fortran to c converter, but f2c was deprecated, was replaced
by g2c, and g2c is deprecated but not replaced, waiting for gfortran…
Moreover, the compilation chain uses uncompatible versions of the c
compiler (or even of ruby itself). Whether on Linux (Ubuntu Lucid) or on
Windows, I had to give up. I understand the situation is not different
on OSX.

The situation is quite similar when you try to connect to the R language
for statistics, or whatever similar. The web is full of old posts asking
for help in similar situations with zero answer.

Am I wrong ? Maybe I am too clumsy. But, after all, a programming
environment is a tool to do your job and deliver. My job is to deliver
science and I end spending my time compiling (I mean failing to compile)
libraries.

The advice I usually get is : shift to Python. A very sad perspective
indeed.

More generally, is there a future for ruby outside its present niches ?

_md

On Thu, Dec 16, 2010 at 11:19 AM, Michel D. [email protected]
wrote:

Am I wrong ? Maybe I am too clumsy. But, after all, a programming
environment is a tool to do your job and deliver. My job is to deliver
science and I end spending my time compiling (I mean failing to compile)
libraries.

If you need the proper tools Right Now, then, well, you have to pick
another tool from your toolbox.

The advice I usually get is : shift to Python. A very sad perspective
indeed.

More generally, is there a future for ruby outside its present niches ?

Of course there is. However, the support (especially in the sciences)
requires two abilities: A solid understanding of the problem space,
and a solid understanding of programming to implement solutions that
fit the problem space.

IOW: scientific Ruby libraries need scientists who can write Ruby code
(and/or C code to wrap binaries or to provide Ruby interfaces to
tools).

I’d love to do my computations for EE in Ruby however, since there’s
pretty much no support for the kinds of maths I need to use (linear
algebra, complex numbers), I’m pretty much stuck with Maple. And I
neither have the time, nor the skill, to implement this properly for
other people using Ruby. Unfortunately (though, a complex number
library shouldn’t be too difficult to implement).

Though, I wonder:

Numerical computing, statistics, whatever, cannot be coded in pure ruby
and you have to rely on specialized libraries.

Why? Unless you need more accuracy than the IEEE float provides, you
should be fine in Ruby, unless performance is a major issue, where you
can drop down to C code, if need be (for example with Ruby Inline[0]).

Or is the data parsing / presentation / plotting the issue?

[0] rubyinline | software projects | by ryan davis

Phillip G.

Though the folk I have met,
(Ah, how soon!) they forget
When I’ve moved on to some other place,
There may be one or two,
When I’ve played and passed through,
Who’ll remember my song or my face.

Phillip G. wrote in post #968809:

Numerical computing, statistics, whatever, cannot be coded in pure ruby
and you have to rely on specialized libraries.

Why? Unless you need more accuracy than the IEEE float provides, you
should be fine in Ruby, unless performance is a major issue, where you
can drop down to C code, if need be (for example with Ruby Inline[0]).

The issue is internal representation. For instance a matrix 1000 x
100000, even of small ints. You need an internal representation of
Fortran type. Actually, ‘narray’ does that perfectly, but is very
limited in scope (only one real method : LU decomposition). The good
answer seems an interface to the big tools : MathLab, SciLab,… This is
more or less what PyMaths is about, as I understand well.

More generally, bigs things with many indices cannot be really managed
with towers of enumerators…

_md

On Thu, Dec 16, 2010 at 12:19 PM, Michel D. [email protected]
wrote:

Take for instance ‘linalg’ for linear algebra. It is based on LAPACK.
You need a Fortran to c converter, but f2c was deprecated, was replaced
by g2c, and g2c is deprecated but not replaced, waiting for gfortran…
Moreover, the compilation chain uses uncompatible versions of the c
compiler (or even of ruby itself). Whether on Linux (Ubuntu Lucid) or on
Windows, I had to give up. I understand the situation is not different
on OSX.

Have you seen Ruby/GSL?

http://rb-gsl.rubyforge.org/

It just got a new release last month, and looks like it has decent
coverage of GSL.

Regards,
Ammar

Ammar A. wrote in post #968816:

Have you seen Ruby/GSL?

http://rb-gsl.rubyforge.org/

It just got a new release last month, and looks like it has decent
coverage of GSL.

Good news. I’ll look. Thanks !
_md

On Thu, Dec 16, 2010 at 11:54 AM, Michel D. [email protected]
wrote:

The issue is internal representation. For instance a matrix 1000 x
100000, even of small ints. You need an internal representation of
Fortran type. Actually, ‘narray’ does that perfectly, but is very
limited in scope (only one real method : LU decomposition). The good
answer seems an interface to the big tools : MathLab, SciLab,… This is
more or less what PyMaths is about, as I understand well.

More generally, bigs things with many indices cannot be really managed
with towers of enumerators…

That’s true. But it’s not like they are much more manageable in for
and while loops, either. But having to deal with enumerations, instead
of “just” using a method call, is cumbersome at best, error prone at
worst, especially when working on the code alone.


Phillip G.

Though the folk I have met,
(Ah, how soon!) they forget
When I’ve moved on to some other place,
There may be one or two,
When I’ve played and passed through,
Who’ll remember my song or my face.

Michel D. wrote in post #968819:

Ammar A. wrote in post #968816:

Have you seen Ruby/GSL?

http://rb-gsl.rubyforge.org/

It just got a new release last month, and looks like it has decent
coverage of GSL.

Good news. I’ll look. Thanks !
_md

Works ! (Ubuntu Lucid)
_md

On Thu, Dec 16, 2010 at 3:19 AM, Michel D.
[email protected]wrote:

Take for instance ‘linalg’ for linear algebra. It is based on LAPACK.
You need a Fortran to c converter, but f2c was deprecated, was replaced
by g2c, and g2c is deprecated but not replaced, waiting for gfortran…
Moreover, the compilation chain uses uncompatible versions of the c
compiler (or even of ruby itself). Whether on Linux (Ubuntu Lucid) or on
Windows, I had to give up. I understand the situation is not different
on OSX.

Have you considered trying to use a library like JAMA with JRuby?

http://math.nist.gov/javanumerics/jama/

On Thu, Dec 16, 2010 at 6:36 PM, Michel D.
[email protected]wrote:

Tony A. wrote in post #968904:

Have you considered trying to use a library like JAMA with JRuby?

JAMA: Java Matrix Package

I am still reluctant to a jump to jruby. I’ll first check GSL on MRI
(1.9.2).

Doing fairly intensive actuarial type calculations I’ve found:

  1. JRuby is currently(?) and anecdotally somewhat slower than MRI 1.9,
    but
    not so much slower as to be a problem.
  2. Integration with Java seems to be easy: I’m not a Java programmer,
    but
    I’ve found it easy to write Java code to do the number crunching, and
    mostly
    easy to integrate the “compiled” Java code with JRuby. (I say mostly
    because
    at the start I couldn’t find a way to compile the Java code in a way
    that
    would reliably work with JRuby, but that was essentially me not
    understanding how Java packages really worked. I still don’t understand
    how
    Java packages really work, but I’ve found a way to compile that reliably
    works for me with JRuby!) That’s a big plus because I definitely don’t
    understand at the moment how to compile C code and integrate that with
    MRI
    Ruby.

On Dec 16, 2010, at 02:34 , Phillip G. wrote:

Why? Unless you need more accuracy than the IEEE float provides, you
should be fine in Ruby, unless performance is a major issue, where you
can drop down to C code, if need be (for example with Ruby Inline[0]).

[0] rubyinline | software projects | by ryan davis

And thanks to Rocket Scientists, it does Fortran too!

Tony A. wrote in post #968904:

Have you considered trying to use a library like JAMA with JRuby?

JAMA: Java Matrix Package

I am still reluctant to a jump to jruby. I’ll first check GSL on MRI
(1.9.2). But thanks for the useful link.

Ryan D. wrote in post #968969:

On Dec 16, 2010, at 02:34 , Phillip G. wrote:

And thanks to Rocket Scientists, it does Fortran too!

Which means my problem was just finding where to look up !

Actually, is there a place, with a FAQ like : if you want to do this
with ruby, then use that ?

_md

On Thursday, December 16, 2010 05:15:59 pm Colin B. wrote:

  1. JRuby is currently(?) and anecdotally somewhat slower than MRI 1.9, but
    not so much slower as to be a problem.

And JRuby is getting faster all the time. It’s not clear whether one
will
necessarily beat the other.

In particular, I remember hearing discussions of a commandline flag in
JRuby
which one could use to disallow altering methods on the core numeric
types.
This would basically make Ruby math compile down to Java math. I imagine
most
scientific applications wouldn’t care about altering the core numeric
types,
while most scientific applications would care about fast math.

  1. Integration with Java seems to be easy: I’m not a Java programmer,

I am, and it is trivial. Every now and then I open up irb and pull in
some
Java things, just for fun:

require ‘java’
import java.util.ArrayList
a = ArrayList.new
a << 5
a << ‘ten’
a.each{|x| puts x}

Basically, you think “How would I want this to work?” And then you
“require
‘java’” and do it, and it works. It’s beautiful.

About the only unintuitive thing I ever found was implementing a Java
interface, and while it’s somewhat unintuitive, it’s still trivial:

require ‘java’
import java.util.PriorityQueue
import java.util.Comparator

singleton comparator

comp = Class.new {
include Comparator
def compare a,b
a.to_s <=> b.to_s
end
}.new

pq = PriorityQueue.new 11, comp
pq << 2
pq << 3
pq << 10
pq.remove # => 10
pq.remove # => 2
pq.remove # => 3

Aside from that, connecting to a Java class from Ruby is pretty much:
Read the
Javadoc, open up irb, try to use it, watch it do exactly what you think
it
should.

Oracle’s behavior lately is making me kind of iffy about the future of
Java as
a platform, but JRuby is just made of awesome.

That’s a big plus because I definitely don’t
understand at the moment how to compile C code and integrate that with MRI
Ruby.

ruby-inline is very cool, but it’s still not quite as easy as being able
to
write a Java class, pretend it’s a Ruby class, and have it work.

I’d say, give it a spin. Worst thing that happens is you make the core
of your
project portable among Ruby implementations.

On Friday, December 17, 2010, Michel D. [email protected]
wrote:

Actually, is there a place, with a FAQ like : if you want to do this
with ruby, then use that ?

Not quite, but have a look at ruby-toolbox.com (IIRC), which gives an
overview of what’s available fir what. And there’s the Ruby
Application Archive, of course.


Phillip G.

Though the folk I have met,
(Ah, how soon!) they forget
When I’ve moved on to some other place,
There may be one or two,
When I’ve played and passed through,
Who’ll remember my song or my face.

Phillip G. wrote in post #969006:

Not quite, but have a look at ruby-toolbox.com (IIRC), which gives an
overview of what’s available fir what. And there’s the Ruby
Application Archive, of course.

‘gsl’ was not in the toolbox, and (stupid me) I did not look in the RAA
!
_md

Howdy-

How to unsubscribe ?

You can’t; the Ruby mailing lists are broken and the mailing list owner
is unresponsive.

I’ve been trying unsuccessfully to unsubscribe for years. Just setup
filters on your end and curse under your breath every time a message
(like yours) slips through.

Best,
Kent

How to unsubscribe ?

-----邮件原件-----
发件人: Michel D. [mailto:[email protected]]
发送时间: 2010年12月17日 16:57
收件人: ruby-talk ML
主题: Re: Ruby and science ?

Phillip G. wrote in post #969006:

Not quite, but have a look at ruby-toolbox.com (IIRC), which gives an
overview of what’s available fir what. And there’s the Ruby
Application Archive, of course.

‘gsl’ was not in the toolbox, and (stupid me) I did not look in the RAA
!
_md

Hi,

In message “Re: 答复: Ruby and science ?”
on Sat, 18 Dec 2010 01:45:59 +0900, “Kent R. Spillner”
[email protected] writes:

|Howdy-
|
|> How to unsubscribe ?
|
|You can’t; the Ruby mailing lists are broken and the mailing list owner is
unresponsive.
|
|I’ve been trying unsuccessfully to unsubscribe for years. Just setup filters on
your end and curse under your breath every time a message (like yours) slips
through.
|
|Best,
|Kent

No way. See the header:

List-Unsubscribe:
mailto:[email protected]?body=unsubscribe

and if you still fail to unsubscribe, just tell us at
[email protected].

          matz.

p.s. The original poster has been unsubscribed successfully.

On Fri, Dec 17, 2010 at 5:45 PM, Kent R. Spillner [email protected]
wrote:

Howdy-

How to unsubscribe ?

You can’t; the Ruby mailing lists are broken and the mailing list owner is
unresponsive.

I’ve been trying unsuccessfully to unsubscribe for years. Just setup filters on
your end and curse under your breath every time a message (like yours) slips
through.

Or: You look at the source of the email, find the List-Unsubscribe
header, and find out that you can mail to [email protected]
with a body of “unsubscribe”, will generate automatic cancellation of
the subscription.

Alternatively, you can go to
Mailing Lists and use the
“Unsubscribe” option from the form’s Action dropdown.

Just saying.


Phillip G.

Though the folk I have met,
(Ah, how soon!) they forget
When I’ve moved on to some other place,
There may be one or two,
When I’ve played and passed through,
Who’ll remember my song or my face.

On Dec 16, 2010, at 23:22 , Michel D. wrote:

Ryan D. wrote in post #968969:

On Dec 16, 2010, at 02:34 , Phillip G. wrote:

And thanks to Rocket Scientists, it does Fortran too!

Which means my problem was just finding where to look up !

gem install RubyInlineFortran

I haven’t even looked at it in years… but as far as I know, nasa uses
it.