Forum: JRuby Is there any sense in trying to write a fast math?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
712effd8673463d44a730bac4cd29311?d=identicon&s=25 Martin Prout (monkstone)
on 2014-04-14 07:54
In processing ( programming language) many people
implement fast sin/cos math using lookup tables, with either limited
precision but accurate degree input. Or with limited precision (say 0.25
degree) and limited accuracy, with radian input (and typically table is
stored as array of floats). Is there any point in trying to wrap a java
version into jruby (not for everyone, but just local to say
ruby-processing) for graphical work.

On a related note I have written a 2D and 3D vector library
in purely ruby for use with ruby-processing, would I gain anything by
re-implementing it in java and writing a jruby wrapper, like yokolets
Fraction, that wraps Apache Commons Math API to provide a ruby version.
712effd8673463d44a730bac4cd29311?d=identicon&s=25 Martin Prout (monkstone)
on 2014-04-26 18:17
OK no-one replied, I did more research and decided to put my foot in the
water. Here is progress so far at implementing my 2D ruby vector library
in JRuby (java)

I did this because it looks to me that the biggest slowdown is calling
java from ruby and vice-versa. I have yet to test performance, but it
was an interesting exercise.
B97f192e676f1a67e0ef18f022671406?d=identicon&s=25 Rodrigo Botafogo (Guest)
on 2014-04-27 16:32
(Received via mailing list)
Hi Martin,

Why don't you use MDMatrix class from MDArray?

I haven't replied before because I don't really understand why you need
do all those complex calls and don't just import java methods to jruby.


Em 26/04/2014 13:18, "Martin Prout" <> escreveu:
712effd8673463d44a730bac4cd29311?d=identicon&s=25 Martin Prout (monkstone)
on 2014-04-27 20:19
I was only going on this from Charlie. In
my experiments it is almost pointless trying to do speed ups in java as
these will not come through to ruby-processing performance. The point of
ruby-processing is to be able to write regular ruby code. If you only
wanted performance you would stick to vanilla processing. Performance is
not bad, even with my Vecmath libary written in ruby, I reasoned that if
it were pre-compiled it might work even better. From the users point of
view my library will appear as though it were written in ruby.
712effd8673463d44a730bac4cd29311?d=identicon&s=25 Martin Prout (monkstone)
on 2014-04-28 08:36
I have now made my experimental JRuby extension available at github
I'm hesitant to offer it as possible template because it is my first
attempt, and there is an absolute dearth of examples (apart from
yokolets excellent example without which I would have never started).
However judging my spec test it at least all seems to work. I have
expanded yokolets example to include a static method (other than new)
methods which take a variable number of arguments etc. Many of these
additional features were partly achieved by trial and error. If I was
confident I was right I would write a guide.
712effd8673463d44a730bac4cd29311?d=identicon&s=25 Martin Prout (monkstone)
on 2014-05-04 22:29
I have now added to the functionality of my Vecmath library which will very likely get
incorporated into ruby-processing. Perhaps the most useful feature is
that of the ArcBall functionality, which can be implemented on the ruby
side with a one liner (by making use of java reflection in processing).
Less interesting is the degree input and degree precision sine / cosine
lookup tables that manage at best 30-40% performance gain over regular
Math.sin and Math.cos. In practice this (ie in a ruby-processing sketch)
performance gain may be even more marginal.
This topic is locked and can not be replied to.