Slashdot Mirror


SciRuby: Science and Matrix Libraries For Ruby

Aciel writes "Ruby has long been popular in the web/business community, while Python dominates the scientific community. One new project seeks to bring balance to the force: SciRuby. We've already introduced a linear algebra library called NMatrix (currently alpha status). There's at least one fellowship available for students interested in working on the project this summer."

26 of 138 comments (clear)

  1. "while Python dominates the scientific community." by Anonymous Coward · · Score: 2

    *cough* bullshit *cough*

  2. Re:"while Python dominates the scientific communit by mooingyak · · Score: 4, Funny

    *cough* bullshit *cough*

    You first have to realize that there are exactly two programming languages in all existence: ruby and python.

    The rest makes more sense if you start from there.

    --
    William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
  3. I always thought by outsider007 · · Score: 2

    That Python is for C programmers who want to take a break from semicolons. And ruby is the same but for Java programmers.

    --
    If you mod me down the terrorists will have won
    1. Re:I always thought by phantomfive · · Score: 3, Interesting

      Because people like using different indentation styles, which sometimes can be clearer. For example, something like this:

      //ensure all sides are checked
      if(!checkedUp() ) checkUp();
      if(!checkedDown() ) checkDown();
      if(!checkedLeft() ) checkLeft();
      if(!checkedRight() ) checkRight();

      can be a lot more concise and readable than a forced indentation method. Flexibility is a good thing. It is ok if you don't like the style I just demonstrated, but you should be able to understand that other people do.

      --
      "First they came for the slanderers and i said nothing."
    2. Re:I always thought by seanzig · · Score: 3, Interesting

      Nothin' wrong with that, my friend. To translate to Python:

      # ensure all sides are checked
      if not checkedUp(): checkUp()
      if not checkedDown(): checkDown()
      if not checkedLeft(): checkLeft()
      if not checkedRight(): checkRight()

    3. Re:I always thought by FrootLoops · · Score: 2

      Python already has a single-line if:

      if (not checkedUp()): checkUp()
      if (not checkedDown()): checkDown()

      is valid Python. I've never felt constrained by Python's indentation style. My experience isn't extensive, though; maybe a few thousand lines.

    4. Re:I always thought by Riskable · · Score: 2

      The most "Pythonic" way to handle your scenario is both efficient and chimes well with your readability standards:

      # Assuming you've got a threading.Lock or multiprocessing.Lock object called 'my_lock'...
      with my_lock:
              code()
              moreCode()
              yetMoreCode()
      # ...and that's it!

      Note that there's no need to call something like releaseLock() since Lock() objects support the 'with statement' (aka context manager). The indentation rules mean that the lock is released at the end of the 'with' block. Another advantage of this solution ('with statements') is that if one of those functions causes an exception the lock will be released in an orderly fashion. This is very effective at:

      1) Preventing deadlock situations.
      2) Making code concise and easy-to-read.

      Also, thanks to Python's dynamic nature you can extend your lock objects to make them perform additional actions in the event of an exception (among other things).

      --
      -Riskable
      "Those who choose proprietary software will pay for their decision!"
  4. Re:"while Python dominates the scientific communit by phantomfive · · Score: 2, Interesting

    Given that Python and Ruby are 8th and 11th respectively on the Tiobe index with a combined rating of 5%, it's more like the Special Olympics. (yes, mod me troll)

    --
    "First they came for the slanderers and i said nothing."
  5. Re:"while Python dominates the scientific communit by Jane+Q.+Public · · Score: 2

    It's not that. There are at least a couple of major issues here:

    (1) The languages at the top of the Tiobe Index (even given that we can assume it has some claim to validity... I'm not so sure) are all compiled languages, or at least compilable to bytecode. Except PHP, which dominated the Web world for a long time but is sliding, and for good reasons.

    (2) The languages at the top of the Tiobe index will always have distorted figures because they represent the majority of code that is already installed and being maintained, rather than new programs.

    When compiled Ruby has become more mature (there are things like JRuby which is coming along nicely, and Ruby 3.0 will supposedly be compilable to bytecode) you will see an increase in its use, because then it will be more commercially viable and appropriate for desktop applications.

    In the meantime, languages that have been mostly used for scripting like Ruby and Python are not used so much for business because all your code is exposed to any would-be customers. That says absolutely nothing about the features of the language itself, except that it is more difficult to compile dynamic languages.

  6. Re:Wrapped C lib, I hope by seanzig · · Score: 2

    Funny you should mention Fortran. Actually, this Ruby thing might actually work, but only if numerical analysts, scientists, engineers, etc. (non-CS types) like it better than Python. Many such domain experts seem to prefer Fortran or C/C++, perhaps because they learned it in school and/or because everyone in their field before them used it to build the existing code bases. Python does have a hell of a head start, though.

  7. Re:"while Python dominates the scientific communit by Pseudonym · · Score: 2

    Precisely. If any language can be said to dominate the scientific community these days, it's probably Excel, with Matlab and R close behind.

    --
    sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  8. Tell me one thing this brings to the table by ubergeek · · Score: 4, Insightful

    This seems like a terrible idea. What could scientific computing with Ruby possibly offer that SciPy doesn't already? Way to split the potential work force guys. If you want to develop a scientific computing library for a rich dynamic language, then contribute to SciPy. What a wasted effort.

    1. Re:Tell me one thing this brings to the table by FrootLoops · · Score: 3, Informative

      The SciRuby Manifesto does discuss the question, "Why Ruby?"

      Why Ruby?

      First and least, Ruby is a language with a sense of humor.

      But more importantly, numerical computation and visualization can be done much better in Ruby, for a number of reasons:

              ''Everything returns a value.'' Ruby's better object model means better chaining of computation.
              ''Iterators'' are way better than ''for'' loops (each_slice, each_cons, etc.).
              ''Readability.'' Ruby is incredibly readable, which makes it uber-maintainable.
              ''Metaprogramming.'' Sometimes the simplest solution is to write a [http://github.com/wycats/thor code generator]. Sometimes, eigenclasses are the cleanest.
              ''Integration into Rails.'' The influence of Rails on Ruby is undeniable. Web-based visualization for scientific projects is the future.
              ''R is nice but clunky.'' The learning curve is enormous. It does some things very well, and others not very well at all (try doing a multi-line plot in R).

      Unfortunately it ignores the alternative of just using Python.

      There's also a (I'll be charitable) silly discussion in this vein on the same page:

      Ruby has no equivalent to the beautifully constructed numpy, scipy, and matplotlib libraries for Python. We believe that the time for a Ruby science and visualization package has come and gone. Sometimes when a solution of sugar and water becomes super-saturated, from it precipitates a pure, delicious, and diabetes-inducing crystal of sweetness, induced by no more than the tap of a finger. So it is, we believe, with the need for numeric and visualization libraries in Ruby.

      IMO, this is a misguided waste of time and it's nearly inactive anyway.

    2. Re:Tell me one thing this brings to the table by bwv549 · · Score: 4, Interesting

      Unfortunately it ignores the alternative of just using Python

      The option of using python is implicitly rejected. Why would the contributors spend time on sciruby when they clearly know scipy exists? Speaking for myself, I've used python and scipy (both numpy and matplotlib) for several projects, but I much prefer coding in ruby to python. All the functionality of scipy isn't going to be duplicated with sciruby, but if the most common use cases are implemented, then I can use ruby for most projects.

      this is a misguided waste of time

      why? It's easier to re-implement (i.e., borrow from scipy) than implement in the first place, so it doesn't take all that much time. And, as pointed out, this is currently a minor project compared to scipy, so if it is a waste of time then it's not a lot of it.

      Python has a "there is only one true way" mentality, so there isn't a lot of room to try and innovate within scipy. Perhaps sciruby will innovate in significant ways and scipy will draw a little from it one day.

      and it's nearly inactive anyway

      The fellowship and nmatrix commit history would suggest otherwise.

    3. Re:Tell me one thing this brings to the table by Anonymous Coward · · Score: 3, Interesting

      No, seriously, that's the most significant thing it brings to the table. With a minimal amount of functionality implemented, far more scientific problems can be addressed in ruby and integrated into a larger, thriving ecosystem (>38,000 ruby gems and counting). Ruby already has strong web applications; complemented with better science libraries a lot of great science can be accomplished (opentox is an interesting example of this kind of integration)

      Sciruby brings ruby to the scientific programming table. Anything else sciruby accomplishes is icing on the cake.

  9. Re:Wrapped C lib, I hope by busyqth · · Score: 3, Funny

    This is why I'm developing "FORTRUBY".

    FORTRUBY is an all new implemenation of Fortran on top of Ruby.

    With FORTRUBY, scientists and engineers can jump right in and start programming in what they're most comfortable with, Fortran, but the Fortran code isn't actually compiled,it's interpreted by a Fortran interpreter written in Ruby.

    This allows scientists and engineers to transition gracefully to a modern language like Ruby. At first, they can just write in Fortran and insert calls to the Ruby library. When they're ready to move on, they can actually insert Ruby code into their Fortran programs that gracefully accomodates Fortran data types and arrays by using the special 'RUBY' statement like this:

    DIMENSION M(10)
    RUBY(FORMAT (5HSUM=0))
    RUBY(FORMAT (27HM.EACH DO /X/ SUM=SUM+X END))

    Finally, they can transition to full fledged Ruby by just writing the whole program inside RUBY statements. Finally scientists and engineers can move into the 21st century without leaving all their current hard-earned skills behind.

  10. Non-story by FrootLoops · · Score: 3, Insightful

    The fellowship is a summer long with only a $1,500 stipend. The most recent commit is from December 1st, 2011. The wiki and issue tracker appear to be similarly inactive. Even if the project does something, it probably won't do much; contrast it with numpy commits which are recent and numerous.

    This story should never have been accepted. There are a million minor projects like this that similarly aren't newsworthy enough to discuss.

    1. Re:Non-story by bwv549 · · Score: 3, Interesting

      The slowdown in commits to sciruby proper is due to the recent efforts on nmatrix (the subject of the story). The github commit history is easily accessible and shows a flurry of activity. Many projects associated with sciruby are also not housed directly under the sciruby name (e.g., rubyvis)

      There are a million minor projects like this that similarly aren't newsworthy enough to discuss

      ... yet here we are...

      The lack of comparable scientific libraries is the primary reason many folks choose python over ruby. It's true that sciruby is young and doesn't yet compete with scipy/numpy, but the point is that it continues to pick up steam. A lot of folks who would rather code in ruby think this matters.

  11. Re:"while Python dominates the scientific communit by Pseudonym · · Score: 3, Insightful

    Excel isn't a language.

    You know that and I know that. But I've worked for physicists, chemists and biologists, and believe me, that little detail doesn't stop them one little bit. A little birdie tells me that it's even worse in the social sciences.

    MatLab might beat Python, but it's been losing ground.

    Very slowly, and in the fields I've worked in, invariably to R.

    R? I love R, but it's not a general purpose language and very few scientists know how to use it.

    Those two little details don't stop scientists either.

    In my experience, scientists will do just about anything to convince themselves that they're not actually programming, if only to avoid pesky annoyances like source code control. The less it looks like a programming language, the better.

    --
    sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  12. Re:"while Python dominates the scientific communit by Samantha+Wright · · Score: 4, Interesting

    In my experience, scientists will do just about anything to convince themselves that they're not actually programming, if only to avoid pesky annoyances like source code control. The less it looks like a programming language, the better.

    Oh god. That would explain why none of their code looks like it's written in a programming language.*

    * I work with biologists. By 'they,' I mean biologists. I know you physicists and quantum chemists have it lucky. Stop bragging. You're making me feel bad.

    --
    Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
  13. Re:Do we really need this? by Zapotek · · Score: 3, Insightful
    I've been writing Ruby for a couple of years now and a couple of weeks ago I went for an interview about a position with heavy Ruby coding.
    During one of the interviews, the guy hit the nail on the head:

    A lot of people don't write Ruby when they're coding in Ruby.

    In reality, Ruby practices make a lot of sense under the context of the language and when you get comfortable with them then you've reached a position when you can take advantage of what Ruby has to offer -- mainly brevity (without sacrificing clarity) and flexibility (crazy introspection and meta-programming capabilities).

    There are a lot of things in the Ruby universe that suck (the interpreter can be quirky, gem management can bit flaky, documentation could be better), the language proper is not one of them.
    However, (surprise, surprise) like with anything else in life, you've got to weigh the pros and cons and find something that suits you and/or your needs.
    Ruby suits a lot of people's needs, that's why it exists, obviously -- so no, we're not where we were 20 years ago, not by a looong shot.

  14. Matlab (and possibly R) vs any other language by pmontra · · Score: 2

    I've been using Octave (an open source version of Matlab) in Stanford's online PGM course. My first reaction was "great matrix manipulation library, extremely bad language". It's like time travelling to the 70's and discarding every progress CS made in the last forty years. Actually Matlab has object oriented classes now but somebody commented in the PGM forums that it's not so good. (Octave uses an older Matlab OO syntax I'll be merciful not to comment about.) I don't have any direct experience with R but on the PGM forum I read that its status is not so different.

    My suggestion to the scientific community is to work on replacing those old languages with something modern, even Python which I cordially hate because of that white space thing. Obviously you need a fast (written in C) scientific library and an interactive prompt is extremely handy. Python and Ruby are sensible choices IMHO. Matlab and R won't disappear, Cobol didn't go away, but there is no reason why a 20 years old student shouldn't start coding with a modern language, if it's on par with the old ones (a big if, I know).

    1. Re:Matlab (and possibly R) vs any other language by loufoque · · Score: 3, Insightful

      What people fail to understand is that OOP is a bad paradigm for numerical computing. It's ill-suited to vectorization and parallelization.

  15. Re:"while Python dominates the scientific communit by Anonymous Coward · · Score: 4, Insightful

    It cuts both ways. I'm a geneticist, and it's painful having to work with tech guys who don't know the first thing about even basic biology, never mind genetics.

    It's the same here on Slashdot. I always cringe every time I load up the comments on a story about genetics or evolution, because I know there'll be a slew of ignorant comments modded up to +5 insightful. At least most scientists know their limitations at programming, but the same cannot be said with regard to non-engineering subjects for many engineers, who feel themselves qualified to comment on just about any topic under the sun, regardless of their lack of knowledge.

  16. Re:"while Python dominates the scientific communit by Samantha+Wright · · Score: 2

    Physicists are perhaps more famous for the same folly; one example I recently stumbled upon was David Boehm, who, in conjunction with a psychologist, developed a completely nonsensical theory of higher brain function and the emergence of independent thought based on nothing more than the appeal of physics concepts to a biological problem.

    If it consoles you any, rectifying such misconceptions is one of the reasons I make a habit of posting here. Experience more suggests, however, that not reading the article is more commonly a source of error—but perhaps that's an artefact of the same presumptiveness.

    --
    Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
  17. Re:"while Python dominates the scientific communit by GravidMind · · Score: 2

    Let's not forget Mathematica (my personal favorite) and Lab View (used for programming National Instruments cards, but soms people start using it as a general programming language because that's what they know -- visual interface, more like circuit design, quite interesting actually).