Module JBLAS::MatrixAccessMixin
In: lib/jblas/mixin_access.rb

Mixin for all kinds of element access.

This mixin is collected into MatrixMixin.

You have the following options of accessing elements:

  • Linear access: accessing all elements linearly, going down rows first (x[i], x.get(i), x.put(i))
  • Two-dimensional access: Accessing element in row i, column j (x[i,j], x.get(i,j), x.put(i,j)
  • Accessing rows and columns: get_row(i), get_column(i), put_row(i), put_column(i), and also get_rows(i), get_columns(i).
  • Accessing row and column ranges: get_row_range, get_column_range, get_range

As indices, you can use one of the following:

  • Numbers: x[10], x[3,4], x.getRow(3), etc.
  • Indices as int[] arrays: Unfortunately, these are bit hard to construct in JRuby ([1,2,3].to_java :int), therefore the emthod to_indices is added to Numeric, Enumerable, Array, and the matrices. Then: `i = [1,2,3]; x`.
  • Matrices: In that case, x.find_indices is called to find the non-zero elements and use those as indices.
  • Ranges: See JBLAS::Ranges

For some access functions (in particular getting rows and columns), you can also specify where to copy the result to get better performance through suppressing object creations.

Methods

Public Instance methods

Get the entry at i, j. If j is omitted, linear addressing is used (that is, i just enumerates all entries going down rows first.)

As indices you can use numbers, int[] arrays, matrices (non-zero elements are taken as indices then), and ranges.

[Source]

# File lib/jblas/mixin_access.rb, line 90
    def [](i, j=nil)
      if j
        get(i.to_indices, j.to_indices)
      else
        get(i.to_indices)
      end
    end

Set the entry at i, j to v. If j is omitted, linear addressing is used (that is, i just enumerates all entries going down rows first.)

As indices you can use numbers, int[] arrays, matrices (non-zero elements are taken as indices then), and ranges.

[Source]

# File lib/jblas/mixin_access.rb, line 104
    def []=(i, j, v=nil)
      if v
        put(i.to_indices, j.to_indices, v)
      else
        put(i.to_indices, j)
      end
    end

Get a column of a matrix. Unlike column(i) method, this method returns a copy of the given column.

[Source]

# File lib/jblas/mixin_access.rb, line 125
    def get_column(i); JAVA_METHOD; end

Get a copy of columns j1 .. j2 - 1 from row i.

[Source]

# File lib/jblas/mixin_access.rb, line 137
    def get_column_range(i, j1, j2); JAVA_METHOD; end

Get a number of rows.

As indices you can use numbers, int[] arrays, matrices (non-zero elements are taken as indices then), and ranges.

[Source]

# File lib/jblas/mixin_access.rb, line 131
    def get_columns(i); JAVA_METHOD; end

Get a copy of the submatrix with rows i1 .. i2 - 1 and columns j1 .. j2 - 1.

[Source]

# File lib/jblas/mixin_access.rb, line 141
    def get_range(i1, i2, j1, j2); JAVA_METHOD; end

Get row of a matrix. Unlike the row(i) method, this method returns a copy of the given row. If result is given, the row is copied in that matrix.

[Source]

# File lib/jblas/mixin_access.rb, line 115
    def get_row(i, result=nil); JAVA_METHOD; end

Get a copy of rows i1 .. i2 - 1 from column j.

[Source]

# File lib/jblas/mixin_access.rb, line 134
    def get_row_range(i1, i2, j); JAVA_METHOD; end

Get a number of rows.

As indices you can use numbers, int[] arrays, matrices (non-zero elements are taken as indices then), and ranges.

[Source]

# File lib/jblas/mixin_access.rb, line 121
    def get_rows(i); JAVA_METHOD; end

Return an array usable as an index.

[Source]

# File lib/jblas/mixin_access.rb, line 144
    def to_indices
      self
    end

[Validate]