Module JBLAS::MatrixConvertMixin
In: lib/jblas/mixin_convert.rb

Mixin for conversion options.

Collected in MatrixMixin.

Methods

Public Instance methods

[Source]

# File lib/jblas/mixin_convert.rb, line 78
    def columns_to_a
      (0...columns).map do |j|
        column(j).to_a
      end
    end

Return an a representation of this object.

[Source]

# File lib/jblas/mixin_convert.rb, line 68
    def inspect
      s = "<#{self.class} of size #{rows} #{columns}: #{to_s}>"
    end

[Source]

# File lib/jblas/mixin_convert.rb, line 72
    def rows_to_a
      (0...rows).map do |i|
        row(i).to_a
      end
    end

Convert the matrix to an array.

If the matrix

[Source]

# File lib/jblas/mixin_convert.rb, line 87
    def to_ary
      to_a
    end

[Source]

# File lib/jblas/mixin_convert.rb, line 100
    def to_matrix
      self
    end

Convert this matrix to a string.

This methods takes a few extra arguments to control how the result looks like.

fmt is a format as used by sprintf, coljoin is the string used to join column, rowjoin is what is used to join rows. For example,

   x.to_s('%.1f', ' ', "\n")

Returns a matrix where columns are separated by spaces, rows by newlines and each element is shown with one digit after the comma.

[Source]

# File lib/jblas/mixin_convert.rb, line 52
    def to_s(fmt=nil, coljoin=', ', rowjoin='; ')
      if fmt
        x = rows_to_a
        '[' + x.map do |r|
          if Enumerable === r
            r.map {|e| sprintf(fmt, e)}.join(coljoin)
          else
            sprintf(fmt, r)
          end
        end.join(rowjoin) + ']'
      else
        toString
      end
    end

[Validate]