class Matrix(T)

Superclass hierarchy

Object
Reference
Matrix(T)

Included Modules

Enumerable(T), Iterable

Defined in:

Class Method Summary

Instance Method Summary

Macro Summary

Class Method Detail

def self.[](*rows)

Alias for Matrix.rows.


def self.column(*values)

Creates a single column matrix with the given values.


def self.columns(columns : Array(Array) | Tuple)

Creates a matrix interpreting each argument as a column.


def self.diagonal(*values)

Creates a diagonal matrix with the supplied arguments. Best suited to numeric matrices.


def self.identity(row_or_col_size : Int)

Creates a Matrix(Int32), whose diagonal values are 1 and the rest are 0.


def self.new(rows : Int, columns : Int, &block : Int32, Int32, Int32 -> T)

Creates a matrix with the given number of rows and columns. It yields the linear, row and column indexes in that order.


def self.row(*values)

Creates a single row matrix with the given values.


def self.rows(rows : Array(Array) | Tuple)

Creates a matrix interpreting each argument as a row.


def self.new(rows : Int, columns : Int, value : T)

def self.new(rows : Int, columns : Int)

Instance Method Detail

def &(other : T | Number)

def *(other : T | Number)

def *(other : Matrix)

Performs multiplication with another matrix.


def **(other : Int)

Performs exponentiation


def +(other : T | Number)

def +(other : Matrix)

Performs addition with another matrix.


def -(other : Matrix)

Performs substraction with another matrix.


def -(other : T | Number)

def -

Returns a new matrix of the same size after calling the unary #- method on every element. Best suited to numeric matrices.


def /(other : Matrix)

Performs division with another matrix.


def /(other : T | Number)

def <<(other : T | Number)

def ==(other : Matrix)

Checks equality between self and another matrix.


def >>(other : T | Number)

def [](index : Int)

Retrieves the element at the given linear index. Raises IndexError.


def [](row : Int, column : Int)

Retrieves the element at the given row and column indexes. Raises IndexError.


def []=(row : Int, column : Int, value : T)

Replaces the element at the given row and column with the given value.


def []=(index : Int, value : T)

Replaces the element at the given linear index with the given value.


def []?(row : Int, column : Int)

Retrieves the element at the given row and column indexes. Returns nil if out of bounds.


def []?(index : Int)

Retrieves the element at the given linear index. Returns nil if out of bounds


def ^(other : T | Number)

def at(index : Int)

Retrieves the element at the given linear index. Raises if out of bounds.


def at(index : Int, &block)

Retrieves the element at the given linear index. Yields if out of bounds.


def at(row : Int, column : Int, &block)

Retrieves the element at the given row and column indexes. Yields if out of bounds.


def at(row : Int, column : Int)

Retrieves the element at the given row and column indexes. Raises IndexError.


def clone

Creates an identical matrix.


def column(column_index : Int)

Returns an iterator for the elements of the column at the given index.


def column(index : Int, &block)

Yields elements of the column at the given index.


def column_count

The number of columns.


def column_vectors

Returns an array of smaller matrices, each representing a column from self.


def columns

Returns an array of arrays that correspond to the columns of the matrix.


def cycle(which = :all : Symbol)

def determinant

Returns the determinant of the matrix. Only useful for numeric matrices.


def diagonal?

Returns true if all non-diagonal elements are 0.


def dimensions

def each(which = :all : Symbol)

def each(which : Symbol, &block)

Like #each but with a Symbol directive that causes the method to skip certain indices: :all -> equivalent to a simple #each (yields every element) :diagonal -> yields elements in the diagonal :off_diagonal -> yields elements not in the diagonal :lower -> yields elements at or below the diagonal :strict_lower -> yields elements below the diagonal :upper -> yields elements at or above the diagonal :strict_upper -> yields elements above the diagonal


def each(&block)

Yields every element of the matrix linearly: First the elements of the first row, then the elements of the second row, etc.


def each_index(which = :all : Symbol, &block)

Yields every row and column index. See #each for the optional directives.


def each_index(which = :all : Symbol)

def each_with_index(which = :all : Symbol, &block)

Yields every element along with its row and column index. See #each for the optional directives.


def empty?

Returns true if the matrix has either 0 rows or 0 columns.


def hash

def index(value : T, which = :all : Symbol)

Returns the row and column index of the first occurrence of "value" in the matrix, nil otherwise.


def index(&block : T, Int32, Int32, Int32 -> Bool)

Returns the row and column index of the first ocurrence of the block returning true, nil otherwise


def inspect(io : IO)

def inverse

Returns the inverse of the matrix. Only useful for numeric matrices.


def lower_triangular?

Returns true if the matrix is a lower triangular matrix.


def map(&block)

Returns a new matrix with the return values of the block. Yields the element and its linear, row and column indices in that order.


def map!(&block : T, Int32, Int32, Int32 -> _)

Changes the values of the matrix according to the return values of the block. Yields the element and its linear, row and column indices in that order.


def minor(start_row : Int, rows : Int, start_col : Int, columns : Int)

Returns a subsection of the matrix.


def minor(row_range : Range(Int, Int), col_range : Range(Int, Int))

Returns a subsection of the matrix.


def permutation?

Returns true if the matrix is a permutation matrix.


def rank

Returns the rank of the matrix. Only useful for numeric matrices.


def regular?

Returns true if the matrix is regular.


def reverse

def reverse!

Reverses the order of the matrix.


def row(index : Int, &block)

Yields elements of the row at the given index.


def row(row_index : Int)

Returns an iterator for the elements of the row at the given index.


def row_count

The number of rows.


def row_vectors

Returns an array of smaller matrices, each representing a row from self.


def rows

Returns an array of arrays that correspond to the rows of the matrix.


def shuffle

def shuffle!

Shuffles the elements of the matrix.


def shuffle_columns

def shuffle_columns!

Shuffles the elements of each column.


def shuffle_rows

def shuffle_rows!

Shuffles the elements of each row.


def singular?

Returns true if the matrix is singular.


def size

The total number of elements.


def square?

Returns true if the number of rows equals the number of columns.


def swap_columns(col_1 : Int, col_2 : Int)

Swaps two columns.


def swap_rows(row_1 : Int, row_2 : Int)

Swaps two rows.


def symmetric?

Returns true if the matrix is symmetric.


def to_a

Returns an array of every element in the matrix.


def to_h

Returns a hash: {row_index, column_index} => element


def to_s(io : IO)

Displays the matrix in a more readable form.


def trace

Returns the sum of the diagonal elements. Only useful for numeric matrices.


def transpose

def transpose!

Changes the rows into columns and vice versa.


def upper_triangular?

Returns true if the matrix is an upper triangular matrix.


def |(other : T | Number)

Macro Detail

macro def_exception(name, message)

macro def_operators(*operators)