Forum: JRuby MDArray: Float becomes Double

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.
James J. (Guest)
on 2015-09-25 13:17
How do I transform objects of class "DoubleMDMatrix2D" into
"FloatMDMatrix2D"? And does it matter?

require 'MDArray'

A = MDMatrix.float([m,m],[graph]) # a sparse matrix, m×m
y = MDMatrix.float([m,1],[vector]) # a one-column vector (of m-length)

A.class #=> FloatMDMatrix2D
y.class #=> FloatMDMatrix2D

20.times do
y = A * y

A.class #=> FloatMDMatrix2D (same)
y.class #=> DoubleMDMatrix2D (changed by calculations)

The loop breaks after the first run, because A can't be multiplied with
y anymore —

NameError: no method 'zMult' for arguments
... (long bla bla on Java stuff).
Rodrigo B. (Guest)
on 2015-10-22 16:18
Hi James,

I did not see your message before.  This is actually a bug.  'y' should
still be a float after the first iteration and not a double.  If you
can, please open an issue on MDArray github.  Anyway,  I´ll take a look
at it and try to make a new version.  Of course, the workaround should
be to use doubles for all matrices.
Rodrigo B. (Guest)
on 2015-10-22 19:43

Can you be more specific with your actual example?  I´ve implemented the
code bellow and I still get a float after matrix multiplication.

a = MDMatrix.float([2, 3], [1, 2, 3, 4, 5, 6])
print "\n"
p a.class
print "\n\n"

b = MDMatrix.float([3, 1], [4, 5, 6])
print "\n"
p b.class
print "\n\n"

b = a * b
print "\n"
p b.class

2 x 3 matrix
1,00000 2,00000 3,00000
4,00000 5,00000 6,00000

3 x 1 matrix

2 x 1 matrix
This topic is locked and can not be replied to.