abstract class LA::Matrix(T)
- LA::Matrix(T)
- Reference
- Object
Overview
class that provide all utility matrix functions
Included Modules
Direct Known Subclasses
Defined in:
linalg/cholesky.crlinalg/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
-
.arange(start_val : T, end_val : T, delta = 1.0)
Create row from start_val...end_val with step of delta between
- .block_diag(*args)
- .circulant(c)
- .column(values)
- .companion(a)
- .dft(n, scale : DFTScale = DFTScale::None)
- .diag(nrows, ncolumns, value : Number | Complex)
- .diag(nrows, ncolumns, values)
- .diag(values)
- .diag(nrows, ncolumns, &)
- .eye(n)
-
.from_custom(io, prefix, columns_separator, rows_separator, postfix)
from_custom(io, "[", ",", "],[", "]")
- .from_matlab(s)
-
.hadamard(n)
TODO - faster implementation
- .hankel(column : Indexable | Matrix, row : Indexable | Matrix | Nil = nil)
- .helmert(n, full = false)
- .hilbert(n)
- .identity(n)
- .invpascal(n, kind : PascalKind = PascalKind::Symmetric)
- .kron(a, b)
- .leslie(f, s)
- .load_csv(filename)
- .multiplicative_identity
- .ones(nrows, ncolumns)
- .pascal(n, kind : PascalKind = PascalKind::Symmetric)
- .rand(nrows, ncolumns, rng = Random::DEFAULT)
- .repmat(a : Matrix(T), nrows, ncolumns)
- .row(values)
- .toeplitz(column : Indexable | Matrix, row : Indexable | Matrix | Nil = nil)
- .tri(nrows, ncolumns, k = 0)
- .zero
- .zeros(nrows, ncolumns)
Macro Summary
Instance Method Summary
-
#*(k : Number)
multiplies at scalar
- #*(k : Complex)
- #*(m : Matrix(T))
-
#**(other : Int)
Taken from https://github.com/Exilor/matrix/
-
#+(k : Number)
adds scalar element-wise
- #+(k : Complex)
-
#+(m : Matrix(T))
returns element-wise sum
- #-(k : Number | Complex)
-
#-(m : Matrix(T))
returns element-wise subtract
- #-
-
#/(k : Number | Complex)
divides at scalar
-
#==(other)
Returns
false
(other can only be aValue
here). - #[](i : Int32, j : Int32)
-
#[](arows : Range(Int32 | Nil, Int32 | Nil), acolumns : Range(Int32 | Nil, Int32 | Nil))
return submatrix over given ranges.
- #[](row : Int32, acolumns : Range(Int32 | Nil, Int32 | Nil))
- #[](arows : Range(Int32 | Nil, Int32 | Nil), column : Int32)
- #[]=(i : Int32, j : Int32, value)
- #[]=(arows : Range(Int32, Int32), acolumns : Range(Int32, Int32), value)
- #[]=(row : Int32, acolumns : Range(Int32, Int32), value)
- #[]=(nrows : Range(Int32, Int32), column : Int32, value)
- #abs(kind : MatrixNorm = MatrixNorm::Frobenius)
- #add!(k : Number, m : Matrix)
- #add!(m)
-
#add_mult(a, b : Matrix(T), *, alpha = 1.0, beta = 1.0)
performs c = alphaab + beta*c (BLAS routines gemm/symm/hemm/trmm)
- #almost_eq(other : Matrix(T), eps)
- #almost_eq(other : Matrix(T))
- #assume!(flag : MatrixFlags, value : Bool = true)
- #balance(*, permute = true, scale = true, separate = false)
- #balance!(*, permute = true, scale = true, separate = false)
- #cat(other : Matrix(T), axis : Axis)
- #cho_solve(b : self, *, overwrite_b = false)
- #cholesky(*, lower = false, dont_clean = false)
- #cholesky!(*, lower = false, dont_clean = false)
- #chop(eps = self.tolerance)
- #clear_flags
- #columns
- #conjt
- #conjt!
-
#conjtranspose
returns transposed matrix
- #coshm
-
#cosm
optimization idea for noncomplex matrix is from scipy
- #det(*, overwrite_a = false)
- #detect(aflags : MatrixFlags = MatrixFlags::All, eps = tolerance)
- #detect?(aflags : MatrixFlags = MatrixFlags::All, eps = tolerance)
- #diag(offset = 0)
- #each(*, all = false, &)
- #each_index(*, all = false, &)
- #each_with_index(*, all = false, &)
- #eigs(*, left = false, overwrite_a = false)
- #eigs(*, need_left : Bool, need_right : Bool, overwrite_a = false)
-
#eigs(*, b : Matrix(T), need_left : Bool, need_right : Bool, overwrite_a = false, overwrite_b = false)
generalized eigenvalues problem
- #eigvals(*, overwrite_a = false)
- #expm(*, schur_fact = false)
- #expm_sqtri(t, f, s)
- #flags : MatrixFlags
- #flags=(value : MatrixFlags)
- #hcat(other)
- #hessenberg
- #hessenberg(*, calc_q = false)
- #hessenberg!
- #hessenberg!(*, calc_q = false)
- #inspect(io)
- #inv
- #inv!
-
#kron(b : Matrix(T))
returns kroneker product with matrix b
- #lq(*, overwrite_a = false)
- #lq_r(*, overwrite_a = false)
- #lstsq(b : self, method : LSMethod = LSMethod::Auto, *, overwrite_a = false, overwrite_b = false, cond = -1)
- #lu(*, overwrite_a = false)
- #lu_factor
- #lu_factor!
-
#map(&)
Returns an
Array
with the results of running the block against each element of the collection. - #map!(&)
-
#map_with_index(&)
Like
#map
, but the block gets passed both the element and its index. - #map_with_index!(&)
- #max(axis : Axis)
- #min(axis : Axis)
- #ncolumns : Int32
-
#norm(kind : MatrixNorm = MatrixNorm::Frobenius)
returns matrix norm
- #nrows : Int32
- #product(axis : Axis)
- #ql(*, overwrite_a = false)
- #ql_r(*, overwrite_a = false)
- #qr(*, overwrite_a = false, pivoting = false)
- #qr_r(*, overwrite_a = false, pivoting = false)
- #qr_raw(*, overwrite_a = false, pivoting = false)
- #qz(b, overwrite_a = false, overwrite_b = false)
-
#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
- #reduce(axis : Axis, initial, &)
-
#repmat(arows, acolumns)
return matrix repeated
arows
times by vertical andacolumns
times by horizontal - #rows
- #rq(*, overwrite_a = false)
- #rq_r(*, overwrite_a = false)
- #save_csv(filename)
- #scale!(k : Number | Complex)
- #schur(*, overwrite_a = false)
- #sinhm
- #sinm
-
#size
Returns the number of elements in the collection.
- #solve(b : self, *, overwrite_a = false, overwrite_b = false)
- #solvels(b : self, *, overwrite_a = false, overwrite_b = false, cond = -1)
-
#square?
returns True if matrix is square and False otherwise
- #sum(axis : Axis)
- #svd(*, overwrite_a = false)
- #svdvals(*, overwrite_a = false)
- #t
- #t!
- #tanhm
- #tanm
-
#to_custom(io, prefix, columns_separator, rows_separator, postfix)
to_custom(io, "[", ",", "],[", "]")
-
#to_general
creates generic matrix with same content.
-
#to_imag
converts complex matrix to imaginary part
- #to_matlab(io)
- #to_matlab
-
#to_real
converts complex matrix to real part
-
#to_s(io)
converts to string, with linefeeds before and after matrix: [1, 2, 3, ....
-
#to_unsafe
to_unsafe method raises at runtime and is overriden by matrix that actually have pointer
- #tolerance
- #tr_mult!(a : Matrix(T), *, alpha = 1.0, left = false)
- #trace
-
#transpose
returns transposed matrix
-
#tril(k = 0)
same as tril in scipy - returns lower triangular or trapezoidal part of matrix
-
#tril!(k = 0)
like a tril in scipy - remove all elements above k-diagonal
-
#triu(k = 0)
same as triu in scipy - returns upper triangular or trapezoidal part of matrix
-
#triu!(k = 0)
like a triu in scipy - remove all elements below k-diagonal
- #vcat(other)
Instance methods inherited from module Enumerable(T)
product(initial : Complex)product(initial : Complex, &) product
Class Method Detail
Create row from start_val...end_val with step of delta between
from_custom(io, "[", ",", "],[", "]")
Macro Detail
Instance Method Detail
Returns false
(other can only be a Value
here).
return submatrix over given ranges.
performs c = alphaab + beta*c (BLAS routines gemm/symm/hemm/trmm)
generalized eigenvalues problem
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]
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.
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
return matrix repeated arows
times by vertical and acolumns
times by horizontal
Returns the number of elements in the collection.
[1, 2, 3, 4].size # => 4
to_custom(io, "[", ",", "],[", "]")
converts to string, with linefeeds before and after matrix: [1, 2, 3, .... 10] [11, 12, 13, .... 20] ... [91, 92, 93, .... 100]
to_unsafe method raises at runtime and is overriden by matrix that actually have pointer