Matrix(T)
Inherits Iterable < Enumerable < Struct < Value < Object
Constructors
Creates a matrix with the given number of rows and columns. It yields the linear, row and column indexes in that order.
Class methods
Creates a matrix interpreting each argument as a column.
Creates a diagonal matrix with the supplied arguments. Best suited to numeric matrices.
Creates a Matrix(Int32), whose diagonal values are 1 and the rest are 0.
Instance methods
Returns a new matrix of the same size after calling the unary #- method on every element. Best suited to numeric matrices.
Retrieves the element at the given row and column indexes. Raises IndexError.
Replaces the element at the given row and column with the given value.
Replaces the element at the given linear index with the given value.
Retrieves the element at the given row and column indexes. Returns nil if out of bounds.
Retrieves the element at the given linear index. Returns nil if out of bounds
Retrieves the element at the given row and column indexes. Yields if out of bounds.
Retrieves the element at the given row and column indexes. Raises IndexError.
Returns an iterator for the elements of the column at the given index.
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
Yields every element of the matrix linearly: First the elements of the first row, then the elements of the second row, etc.
Yields every row and column index. See #each for the optional directives.
Yields every element along with its row and column index. See #each for the optional directives.
Generates an UInt64 hash value for this object.
This method must have the property that a == b implies a.hash == b.hash.
The hash value is used along with == by the Hash class to determine if two objects
reference the same hash key.
Subclasses must not override this method. Instead, they must define hash(hasher),
though usually the macro def_hash can be used to generate this method.
Returns the row and column index of the first occurrence of "value" in the matrix, nil otherwise.
Returns the row and column index of the first occurrence of the block returning true, nil otherwise
Appends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
Returns a new matrix with the return values of the block. Yields the element and its linear, row and column indices in that order.
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.
Returns a subsection of the matrix.
Returns a subsection of the matrix.