class

LA::GeneralMatrix(T)

Inherits LA::Matrix / LA::LapackHelper / Enumerable / Reference / Object

generic matrix, heap-allocated

Data are stored in column-major as this is a storage used by LAPACK

See SUPPORTED_TYPES for supported types

Constructors

new(nrows : Int32, ncolumns : Int32, values : Indexable, col_major = false, flags : LA::MatrixFlags = MatrixFlags::None)

Creates matrix with given size and populate elements from values

if col_major is true, values content is just copied to #raw, otherwise a conversion from row-major form is performed Example:

values = [1, 2, 3, 4]
a = GMat.new(2, 2, values)
a.to_aa # => [[1,2],[3,4]]
b = GMat.new(2, 2, values, col_major: true)
b.to_aa # => [[1,3],[2,4]]
Source
new(nrows : Int32, ncolumns : Int32, flags : LA::MatrixFlags = MatrixFlags::None)

Creates zero-initialized matrix of given size

Example: LA::GMat.new(4,4)

Source
new(nrows : Int32, ncolumns : Int32, flags : LA::MatrixFlags = MatrixFlags::None, &)

Creates matrix of given size and then call block to initialize each element

Example: LA::GMat.new(4,4){|i,j| i+j }

Source
new(values : Indexable)

Creates matrix from any Indexable of Indexables

Example:

m = GMat.new([
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
  [10, 11, 12],
])
Source
new(matrix : Matrix)

Creates matrix with same content as another matrix

Source

Class methods

[](*args)

Alias for #new

Source
columns(*args)

Creates matrix from a number of columns

Example:

a = GMat.columns([1, 2, 3, 4], [5, 6, 7, 8])
a.to_aa # => [[1, 5], [2, 6], [3, 7], [4, 8]]
Source
diag(nrows, ncolumns, values)

Returns diagonal matrix of given size with diagonal elements taken from array values

Source
diag(nrows, ncolumns, &)

Returns diagonal matrix of given size with diagonal elements equal to block value

Source
rows(*args)

Creates matrix from a number of rows

Example:

a = GMat.rows([1, 2, 3, 4], [5, 6, 7, 8])
a.to_aa # => [[1,2,3,4], [5,6,7,8]]
Source

Instance methods

==(other : self)

see LA::Matrix#==

Source
cat!(other : Matrix(T), dimension)

Concatenate matrix adding another matrix by dimension Axis::Rows (horizontal) or Axis::Columns (vertical)

Source
clone

returns copy of matrix

Source
conjtranspose!

Conjurgate transposes matrix inplace

Currently, transpose of non-square matrix still allocates temporary buffer

Source
dup

returns copy of matrix

Source
flags

Matrix flags (see MatrixFlags for description)

Source
flags=(flags : MatrixFlags)

Matrix flags (see MatrixFlags for description)

Source
hcat!(other)

Concatenate matrix adding another matrix horizontally (so they form a row)

Source
ncolumns

Count of columns in matrix

Source
nrows

Count of rows in matrix

Source
raw

Pointer to a raw data

Source
reshape(anrows, ancolumns, col_major = false)

Returns a matrix with different nrows and ncolumns but same elements (total number of elements must not change)

if col_major is true, just nrows and ncolumns are changed, data kept the same Otherwise, elements are reordered to emulate row-major storage Example:

a = GMat[[1, 2, 3], [4, 5, 6]]
a.reshape(2, 3).to_aa # => [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]
b = GMat[[1, 2, 3], [4, 5, 6]]
this is because in-memory order of values is (1, 4, 2, 5, 3, 6)
b.reshape(2, 3, col_major: true).to_aa # => [[1.0, 5.0], [4.0, 3.0], [2.0, 6.0]]
Source
reshape!(anrows : Int32, ancolumns : Int32, col_major = false)

Changes nrows and ncolumns of matrix (total number of elements must not change)

if col_major is true, just nrows and ncolumns are changed, data kept the same Otherwise, elements are reordered to emulate row-major storage Example:

a = GMat[[1, 2, 3], [4, 5, 6]]
a.reshape!(2, 3)
a.to_aa # => [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]
b = GMat[[1, 2, 3], [4, 5, 6]]
b.reshape!(2, 3, col_major: true)
this is because in-memory order of values is (1, 4, 2, 5, 3, 6)
b.to_aa # => [[1.0, 5.0], [4.0, 3.0], [2.0, 6.0]]
Source
resize!(anrows : Int32, ancolumns : Int32)

Change number of rows and columns in matrix.

if new number is higher zero elements are added, if new number is lower, exceeding elements are lost

Source
to_a(col_major = false)

Converts matrix to plain array of elements if col_major is true, elements are returned as stored inplace, otherwise row-major storage is emulated

Source
to_aa(col_major = false)

Converts matrix to array of array of elements if col_major is true, elements are returned as stored inplace, otherwise row-major storage is emulated Example:

a = GMat[[1, 2], [3, 4]]
a.to_aa                  # => [[1.0, 2.0],[3.0, 4.0]]
a.to_aa(col_major: true) # => [[1.0, 3.0],[2.0, 4.0]]
Source
to_unsafe

Returns pointer to raw data, suitable to e.g. use with LAPACK

Source
transpose!

transposes matrix inplace

Currently, transpose of non-square matrix still allocates temporary buffer

Source
unsafe_fetch(i, j)

returns element at row i and column j, without performing any checks

Source
unsafe_set(i, j, value)

sets element at row i and column j to value, without performing any checks

Source
vcat!(other)

Concatenate matrix adding another matrix vertically (so they form a column)

Source