The RTensor library (rtensor.so and rtensor_sup.rb) provides the tensor (multi-dimensional matrix) functionality for the Ruby programming language. It is built for Windows only (and only 32-bit Windows XP and Vista have been tested) with RubyInstaller 1.9.2-p290 and DevKit-tdm-32-4.5.2-20110712-1620-sfx.exe.
Currently Ruby has Matrix as part of its Standard Library. The more powerful matrix-related computations are available as part of Ruby/GSL. However, the multi-dimensional matrix is available as part of NArray. Therefore, the current effort is to provide, at least, an example on how to unify the (multi-dimensional) matrix-related computational power in Ruby. There are methods "to_matrix", "to_gsl" and "to_narray", and similarly "from_matrix", "from_gsl" and "from_narray". Furthermore, Gnuplot can be used to provide some graphical capabilities and GiNaC can be used for certain symbolic computations.
Although the library is still in development, the following improvements are brought about by RTensor with respect to the existing ones (as can also be seen in Comparison Table):
(There is also a Ruby interface to Octave: octave-ruby; but its matrix doesn't seem to support Ruby objects.)
This Ruby project was started on Sep 20, 2011, whereas the underlying C++ project was started on Aug 18, 2011. The original dream was to provide Matlab/Octave functionality into Ruby, but then the dream has changed to having Ruby's version of Sage, and to certain extent, SimPy. After I wake up, I think I'll just provide some Ruby interface to Sage.
The followings are used in considering the naming convention (such as "size" and "shape"), in the order of precedence:
The lowercase "tensor" term is used to represent multi-dimensional matrix. The uppercase "Tensor" and "Tnsr" are used to represent the particular classes in RTensor library, and both can be referred as "tensor" and sometimes abbreviated as "tsr".
In RTensor library, the number of dimensions of a tensor is at least two. Therefore, a "matrix" is a tensor that has dimensions m X n, a "vector" is a tensor that has dimensions m X 1 (column vector) or 1 X n (row vector), a "scalar" is a tensor that has dimensions 1 X 1 (but hardly used), and an "empty tensor" is a tensor that has dimensions 0 X 0. Note that an "array" has only one dimension k.
Because the number of dimensions of a tensor is at least two, the indexing of tensor elements is done through "multi-index" [idx1, idx2, idx3, ...]. However, it is also possible to use "single index" [idx]; in this case the tensor is considered as one long array.
|Features||Ruby Matrix||Ruby/GSL Matrix||NArray||Matlab/Octave||RTensor||Notes|
|Indexing||Always 2D||1D or 2D||Multi-D||Multi-D||Multi-D||---|
|Start Index||0||0||0||1||1 or 0 (or any natural number)||---|
|Types of Indexing||integers only||integers, submatrices||integers, ranges, masks, indirects||integers, ranges, masks, indirects||integers, ranges, masks, indirects||RTensor is based on C++.|
|Ordering||Use Ruby Array||Row Order||Row Order||Column Order||Column Order or Row Order||GSL uses row order.|
|Vector separate from Matrix?||Yes||Yes||Yes||No||No||---|
|Types||Ruby object||int, double, cdouble||Ruby object, uchar, short, int, float, double, cfloat, cdouble||string, bool, char, uchar, short, ushort, int, unsigned, long, ulong, llong, ullong, float, double, cchar, cuchar, cshort, cushort, cint, cunsigned, clong, culong, cllong, cullong, cfloat, cdouble||Ruby object, string, bool, char, uchar, short, ushort, int, unsigned, long, llong, ullong, float, double, ldouble, cchar, cuchar, cshort, cushort, cint, cunsigned, clong, culong, cllong, cullong, cfloat, cdouble, cldouble||---|