Forum: JRuby MDArray: Float becomes Double

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
614c621eef67a8fb4fafe71a2ed166e2?d=identicon&s=25 James Joyce (yyoyo)
on 2015-09-25 11: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)
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).
41d4ee7d85eee6a9f8f9d29d3114ad85?d=identicon&s=25 Rodrigo Botafogo (rbotafogo)
on 2015-10-22 14: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.
41d4ee7d85eee6a9f8f9d29d3114ad85?d=identicon&s=25 Rodrigo Botafogo (rbotafogo)
on 2015-10-22 17:43
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
This topic is locked and can not be replied to.