# MDArray: Float becomes Double

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)
end

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

NameError: no method ‘zMult’ for arguments
(cern.colt.matrix.tdouble.impl.DenseDoubleMatrix2D,cern.colt.matrix.tfloat.impl.Dense
… (long bla bla on Java stuff).

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.

James,

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])
a.print
print “\n”
p a.class
print “\n\n”

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

b = a * b
b.print
print “\n”
p b.class

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

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

2 x 1 matrix
32,0000
77,0000
FloatMDMatrix2D