You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prasun Anand edited this page Mar 4, 2017
·
2 revisions
NMatrix is supported on Ruby-MRI as well as JRuby.
NMatrix for JRuby currently supports:
dtype => float64
stype => dense
Hacking NMatrix for JRuby:
The frontend exclusive to NMatrix-JRuby resides in lib/nmatrix/jruby.
The backend of NMatrix-JRuby resides in ext/nmatrix_java. The backend is built by building a wrapper around Apache Commons Math.
NMatrix object can be represented as:
@s stores elements, @shape stores the shape of the matrix, while @dtype and @stype store the data type and storage type respectively.
Two Dimensional NMatrix
Linear algebra is mostly about two-dimensional matrices. In NMatrix, when performing calculations in a two-dimensional matrix, a one-dimensional array is converted to a two-dimensional matrix. A two-dimensional matrix is stored in the JRuby implementation as a BlockRealMatrix or Array2DRowRealMatrix.
To learn how to call Java code on JRuby, have a look at this resource..
Why use a Java method instead of Ruby method?
Memory Usage and Garbage Collection: A scientific library is memory intensive and hence, every step counts. The JRuby interpreter doesn’t need to dynamically guess the data type and uses less memory, typically around one-tenth of it. If the memory is properly utilized, when the GC kicks in, the GC has to clear less used memory space.
Speed: Using java method greatly improves the speed — by around 1000 times, when compared to using the Ruby method.