abstract class LA::Matrix(T)

Overview

class that provide all utility matrix functions

Included Modules

Direct Known Subclasses

Defined in:

linalg/cholesky.cr
linalg/eig.cr
linalg/expm.cr
linalg/lapack_helper.cr
linalg/linalg.cr
linalg/lu.cr
linalg/matfun.cr
linalg/mult.cr
linalg/power.cr
linalg/qr.cr
linalg/rq_lq_ql.cr
linalg/schur.cr
matrix/flag_checks.cr
matrix/formatted_reader.cr
matrix/formatted_writer.cr
matrix/iteration.cr
matrix/matrix.cr
matrix/special_matrix.cr:6
matrix/special_matrix.cr:142
matrix/special_matrix.cr:177

Class Method Summary

Macro Summary

Instance Method Summary

Instance methods inherited from module Enumerable(T)

product(initial : Complex)
product(initial : Complex, &)
product

Class Method Detail

def self.arange(start_val : T, end_val : T, delta = 1.0) #

Create row from start_val...end_val with step of delta between


[View source]
def self.block_diag(*args) #

[View source]
def self.circulant(c) #

[View source]
def self.column(values) #

[View source]
def self.companion(a) #

[View source]
def self.dft(n, scale : DFTScale = DFTScale::None) #

[View source]
def self.diag(nrows, ncolumns, value : Number | Complex) #

[View source]
def self.diag(nrows, ncolumns, values) #

[View source]
def self.diag(values) #

[View source]
def self.diag(nrows, ncolumns, &) #

[View source]
def self.eye(n) #

[View source]
def self.from_custom(io, prefix, columns_separator, rows_separator, postfix) #

from_custom(io, "[", ",", "],[", "]")


[View source]
def self.from_matlab(s) #

[View source]
def self.hadamard(n) #

TODO - faster implementation


[View source]
def self.hankel(column : Indexable | Matrix, row : Indexable | Matrix | Nil = nil) #

[View source]
def self.helmert(n, full = false) #

[View source]
def self.hilbert(n) #

[View source]
def self.identity(n) #

[View source]
def self.invpascal(n, kind : PascalKind = PascalKind::Symmetric) #

[View source]
def self.kron(a, b) #

[View source]
def self.leslie(f, s) #

[View source]
def self.load_csv(filename) #

[View source]
def self.multiplicative_identity #

[View source]
def self.ones(nrows, ncolumns) #

[View source]
def self.pascal(n, kind : PascalKind = PascalKind::Symmetric) #

[View source]
def self.rand(nrows, ncolumns, rng = Random::DEFAULT) #

[View source]
def self.repmat(a : Matrix(T), nrows, ncolumns) #

[View source]
def self.row(values) #

[View source]
def self.toeplitz(column : Indexable | Matrix, row : Indexable | Matrix | Nil = nil) #

[View source]
def self.tri(nrows, ncolumns, k = 0) #

[View source]
def self.zero #

[View source]
def self.zeros(nrows, ncolumns) #

[View source]

Macro Detail

macro blas(storage, name, *args) #

[View source]
macro lapack(name, *args, worksize = nil) #

[View source]
macro lapack_util(name, worksize, *args) #

[View source]

Instance Method Detail

def *(k : Number) #

multiplies at scalar


[View source]
def *(k : Complex) #

[View source]
def *(m : Matrix(T)) #

[View source]
def **(other : Int) #

Taken from https://github.com/Exilor/matrix/


[View source]
def +(k : Number) #

adds scalar element-wise


[View source]
def +(k : Complex) #

[View source]
def +(m : Matrix(T)) #

returns element-wise sum


[View source]
def -(k : Number | Complex) #

[View source]
def -(m : Matrix(T)) #

returns element-wise subtract


[View source]
def - #

[View source]
def /(k : Number | Complex) #

divides at scalar


[View source]
def ==(other) #
Description copied from class Reference

Returns false (other can only be a Value here).


[View source]
def [](i : Int32, j : Int32) #

[View source]
def [](arows : Range(Int32 | Nil, Int32 | Nil), acolumns : Range(Int32 | Nil, Int32 | Nil)) #

return submatrix over given ranges.


[View source]
def [](row : Int32, acolumns : Range(Int32 | Nil, Int32 | Nil)) #

[View source]
def [](arows : Range(Int32 | Nil, Int32 | Nil), column : Int32) #

[View source]
def []=(i : Int32, j : Int32, value) #

[View source]
def []=(arows : Range(Int32, Int32), acolumns : Range(Int32, Int32), value) #

[View source]
def []=(row : Int32, acolumns : Range(Int32, Int32), value) #

[View source]
def []=(nrows : Range(Int32, Int32), column : Int32, value) #

[View source]
def abs(kind : MatrixNorm = MatrixNorm::Frobenius) #

[View source]
def add!(k : Number, m : Matrix) #

[View source]
def add!(m) #

[View source]
def add_mult(a, b : Matrix(T), *, alpha = 1.0, beta = 1.0) #

performs c = alphaab + beta*c (BLAS routines gemm/symm/hemm/trmm)


[View source]
def almost_eq(other : Matrix(T), eps) #

[View source]
def almost_eq(other : Matrix(T)) #

[View source]
def assume!(flag : MatrixFlags, value : Bool = true) #

[View source]
def balance(*, permute = true, scale = true, separate = false) #

[View source]
def balance!(*, permute = true, scale = true, separate = false) #

[View source]
def cat(other : Matrix(T), axis : Axis) #

[View source]
def cho_solve(b : self, *, overwrite_b = false) #

[View source]
def cholesky(*, lower = false, dont_clean = false) #

[View source]
def cholesky!(*, lower = false, dont_clean = false) #

[View source]
def chop(eps = self.tolerance) #

[View source]
def clear_flags #

[View source]
def columns #

[View source]
def conjt #

[View source]
def conjt! #

[View source]
def conjtranspose #

returns transposed matrix


[View source]
def coshm #

[View source]
def cosm #

optimization idea for noncomplex matrix is from scipy


[View source]
def det(*, overwrite_a = false) #

[View source]
def detect(aflags : MatrixFlags = MatrixFlags::All, eps = tolerance) #

[View source]
def detect?(aflags : MatrixFlags = MatrixFlags::All, eps = tolerance) #

[View source]
def diag(offset = 0) #

[View source]
def each(*, all = false, &) #

[View source]
def each_index(*, all = false, &) #

[View source]
def each_with_index(*, all = false, &) #

[View source]
def eigs(*, left = false, overwrite_a = false) #

[View source]
def eigs(*, need_left : Bool, need_right : Bool, overwrite_a = false) #

[View source]
def eigs(*, b : Matrix(T), need_left : Bool, need_right : Bool, overwrite_a = false, overwrite_b = false) #

generalized eigenvalues problem


[View source]
def eigvals(*, overwrite_a = false) #

[View source]
def expm(*, schur_fact = false) #

[View source]
def expm_sqtri(t, f, s) #

[View source]
abstract def flags : MatrixFlags #

[View source]
abstract def flags=(value : MatrixFlags) #

[View source]
def hcat(other) #

[View source]
def hessenberg #

[View source]
def hessenberg(*, calc_q = false) #

[View source]
def hessenberg! #

[View source]
def hessenberg!(*, calc_q = false) #

[View source]
def inspect(io) #

[View source]
def inv #

[View source]
def inv! #

[View source]
def kron(b : Matrix(T)) #

returns kroneker product with matrix b


[View source]
def lq(*, overwrite_a = false) #

[View source]
def lq_r(*, overwrite_a = false) #

[View source]
def lstsq(b : self, method : LSMethod = LSMethod::Auto, *, overwrite_a = false, overwrite_b = false, cond = -1) #

[View source]
def lu(*, overwrite_a = false) #

[View source]
def lu_factor #

[View source]
def lu_factor! #

[View source]
def map(&) #
Description copied from module Enumerable(T)

Returns an Array with the results of running the block against each element of the collection.

[1, 2, 3].map { |i| i * 10 } # => [10, 20, 30]

[View source]
def map!(&) #

[View source]
def map_with_index(&) #
Description copied from module Enumerable(T)

Like #map, but the block gets passed both the element and its index.

["Alice", "Bob"].map_with_index { |name, i| "User ##{i}: #{name}" }
# => ["User #0: Alice", "User #1: Bob"]

Accepts an optional offset parameter, which tells it to start counting from there.


[View source]
def map_with_index!(&) #

[View source]
def max(axis : Axis) #

[View source]
def min(axis : Axis) #

[View source]
abstract def ncolumns : Int32 #

[View source]
def norm(kind : MatrixNorm = MatrixNorm::Frobenius) #

returns matrix norm


[View source]
abstract def nrows : Int32 #

[View source]
def product(axis : Axis) #

[View source]
def ql(*, overwrite_a = false) #

[View source]
def ql_r(*, overwrite_a = false) #

[View source]
def qr(*, overwrite_a = false, pivoting = false) #

[View source]
def qr_r(*, overwrite_a = false, pivoting = false) #

[View source]
def qr_raw(*, overwrite_a = false, pivoting = false) #

[View source]
def qz(b, overwrite_a = false, overwrite_b = false) #

[View source]
def rank(eps = self.tolerance, *, method : RankMethod = RankMethod::SVD, overwrite_a = false) #

determine effective rank either by SVD method or QR-factorization with pivoting QR method is faster, but could fail to determine rank in some cases


[View source]
def reduce(axis : Axis, initial, &) #

[View source]
def repmat(arows, acolumns) #

return matrix repeated arows times by vertical and acolumns times by horizontal


[View source]
def rows #

[View source]
def rq(*, overwrite_a = false) #

[View source]
def rq_r(*, overwrite_a = false) #

[View source]
def save_csv(filename) #

[View source]
def scale!(k : Number | Complex) #

[View source]
def schur(*, overwrite_a = false) #

[View source]
def sinhm #

[View source]
def sinm #

[View source]
def size #
Description copied from module Enumerable(T)

Returns the number of elements in the collection.

[1, 2, 3, 4].size # => 4

[View source]
def solve(b : self, *, overwrite_a = false, overwrite_b = false) #

[View source]
def solvels(b : self, *, overwrite_a = false, overwrite_b = false, cond = -1) #

[View source]
def square? #

returns True if matrix is square and False otherwise


[View source]
def sum(axis : Axis) #

[View source]
def svd(*, overwrite_a = false) #

[View source]
def svdvals(*, overwrite_a = false) #

[View source]
def t #

[View source]
def t! #

[View source]
def tanhm #

[View source]
def tanm #

[View source]
def to_custom(io, prefix, columns_separator, rows_separator, postfix) #

to_custom(io, "[", ",", "],[", "]")


[View source]
def to_general #

creates generic matrix with same content. Useful for banded\sparse matrices


[View source]
def to_imag #

converts complex matrix to imaginary part


[View source]
def to_matlab(io) #

[View source]
def to_matlab #

[View source]
def to_real #

converts complex matrix to real part


[View source]
def to_s(io) #

converts to string, with linefeeds before and after matrix: [1, 2, 3, .... 10] [11, 12, 13, .... 20] ... [91, 92, 93, .... 100]


[View source]
def to_unsafe #

to_unsafe method raises at runtime and is overriden by matrix that actually have pointer


[View source]
def tolerance #

[View source]
def tr_mult!(a : Matrix(T), *, alpha = 1.0, left = false) #

[View source]
def trace #

[View source]
def transpose #

returns transposed matrix


[View source]
def tril(k = 0) #

same as tril in scipy - returns lower triangular or trapezoidal part of matrix


[View source]
def tril!(k = 0) #

like a tril in scipy - remove all elements above k-diagonal


[View source]
def triu(k = 0) #

same as triu in scipy - returns upper triangular or trapezoidal part of matrix


[View source]
def triu!(k = 0) #

like a triu in scipy - remove all elements below k-diagonal


[View source]
def vcat(other) #

[View source]