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

712effd8673463d44a730bac4cd29311?d=identicon&s=25 Martin Prout (monkstone)
on 2014-04-14 07:54
In processing (processing.org 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
https://github.com/jashkenas/ruby-processing/blob/...
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.
http://yokolet.blogspot.co.uk/2011/05/extending-jruby.html.
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)
http://learning-ruby-processing.blogspot.co.uk/201....

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
to
do all those complex calls and don't just import java methods to jruby.

Cheers,

Rodrigo
Em 26/04/2014 13:18, "Martin Prout" <lists@ruby-forum.com> escreveu:
712effd8673463d44a730bac4cd29311?d=identicon&s=25 Martin Prout (monkstone)
on 2014-04-27 20:19
I was only going on this
https://twitter.com/headius/status/349225854842306560 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
https://github.com/ruby-processing/RVecMath
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
https://github.com/ruby-processing/RVecMath 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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.