How to solve a special JRuby and Java syntax conflict?

Dear all,

I’ve posted this previously to the Ruby Forum:

In a JRuby script, I try to use Java code from

to do matrix calculations. This works in principle fine, however,
as described in the accompanying tutorial, Java matrices are
defined with a syntax like so:

double[][] A = { { 1.1, 1.2, 1.3, 1.4 }, { 2.1, 2.2, 2.3, 2.4 }, { 3.1,
3.2, 3.3, 3.4 } };

This syntax clashes in JRuby with the definition of Hashes.
I can’t find another way of writing data into the Matrix.
Is there a way of defining an alias for the curly braces method syntax,
somewhat analogous to the class name renaming example in the JRuby
cookbook ? :

Example 1-7. Creating an alias to avoid class name conflicts
include Java

include_class ‘java.lang.String’ do |package,name|
“JString”
end

p JString.new(“A quick brown fox”).indexOf(“brown”)

If this is not possible, do you know of a good Java matrix calculation
library that includes Singular value decomposition
(http://en.wikipedia.org/wiki/Singular_value_decomposition) ?

Thank you very much for your help!

Best regards,

Axel


GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Axel,

If I understand your problem correctly, you are in a bit of ruby code
and want to define a 2 dimensional array of doubles to pass into a
jmatharray function. You can just define the 2d array like you
normally would in ruby:

ruby_arr = [[0.25, 0.25, 0.25, 0.25],
[0.25, 0.25, 0.25, 0.25],
[0.25, 0.25, 0.25, 0.25],
[0.25, 0.25, 0.25, 0.25]]

Then to pass it into the jmatharray function you run to_java on it:

ruby_arr.to_java Java::double[]

I tested this in this bit of code: http://gist.github.com/210167

Thanks
Carl

On Oct 14, 2009, at 9:23 AM, Axel E. wrote:

defined with a syntax like so:

library that includes Singular value decomposition (http://en.wikipedia.org/wiki/Singular_value_decomposition

Carl Leiby
[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I tested this in this bit of code: http://gist.github.com/210167

Thanks
Carl

Carl,

that’s sweet ! Thank you ever so much !

Best regards,

Axel


Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox
3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs