class LA::BandedMatrix(T)

Overview

banded matrix, heap-allocated

Defined in:

linalg/banded.cr
matrix/banded_matrix.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class LA::Matrix(T)

*(k : Number)
*(k : Complex)
*(m : Matrix(T))
*
, **(other : Int) **, +(k : Number)
+(k : Complex)
+(m : Matrix(T))
+
, -(k : Number | Complex)
-(m : Matrix(T))
-
-
, /(k : Number | Complex) /, ==(other) ==, [](i : Int32, j : Int32)
[](arows : Range(Int32 | Nil, Int32 | Nil), acolumns : Range(Int32 | Nil, Int32 | Nil))
[](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)
[]=
, add(m : Matrix, *, alpha = 1, beta = 1) add, add!(k : Number, m : Matrix) add!, almost_eq(other : Matrix(T), eps)
almost_eq(other : Matrix(T))
almost_eq
, assume!(flag : MatrixFlags, value : Bool = true) assume!, balance(*, permute = true, scale = true, separate = false) balance, cat(other : Matrix(T), axis : Axis) cat, cholesky(*, lower = false, dont_clean = false) cholesky, chop(eps = self.tolerance) chop, clear_flags clear_flags, columns columns, conjt conjt, conjt! conjt!, conjtranspose conjtranspose, coshm coshm, cosm cosm, det det, detect(aflags : MatrixFlags = MatrixFlags::All, eps = tolerance) detect, detect?(aflags : MatrixFlags = MatrixFlags::All, eps = tolerance) detect?, diag(offset = 0) diag, each(*, all = false, &) each, each_index(*, all = false, &) each_index, each_lower(*, diagonal = true, all = false, &) each_lower, each_upper(*, diagonal = true, all = false, &) each_upper, each_with_index(*, all = false, &) each_with_index, eigs(*, left = false)
eigs(*, need_left : Bool, need_right : Bool)
eigs(*, b : self, need_left = false, need_right = false)
eigs
, eigvals eigvals, expm expm, flags : MatrixFlags flags, hcat(other) hcat, hessenberg
hessenberg(*, calc_q = false)
hessenberg
, inspect(io) inspect, inv inv, kron(b : Matrix(T)) kron, lq lq, lq_r lq_r, lu lu, lu_factor : LUMatrix(T) lu_factor, map(&block : T -> U) forall U map, map!(&) map!, map_with_index(&block : T -> U) forall U map_with_index, map_with_index!(&) map_with_index!, max(axis : Axis) max, min(axis : Axis) min, ncolumns : Int32 ncolumns, norm(kind : MatrixNorm = MatrixNorm::Frobenius) norm, nrows : Int32 nrows, pinv pinv, product(axis : Axis) product, ql ql, ql_r ql_r, qr(*, pivoting = false) qr, qr_r(*, pivoting = false) qr_r, qr_raw(*, pivoting = false) qr_raw, qz(b : self) qz, reduce(axis : Axis, initial, &) reduce, repmat(arows, acolumns) repmat, rows rows, rq rq, rq_r rq_r, save_csv(filename) save_csv, scale!(k : Number | Complex) scale!, schur schur, shape shape, shape_str shape_str, sinhm sinhm, sinm sinm, size : Tuple(Int32, Int32) size, solve(b : self)
solve(b : GeneralMatrix(T), *, overwrite_b = false)
solve
, square? square?, sum(axis : Axis) sum, svd svd, svdvals svdvals, t t, t! t!, tanhm tanhm, tanm tanm, to_custom(io, prefix, columns_separator, rows_separator, postfix)
to_custom(prefix, columns_separator, rows_separator, postfix)
to_custom
, to_general to_general, to_imag to_imag, to_matlab(io)
to_matlab
to_matlab
, to_real to_real, to_s(io) to_s, to_unsafe to_unsafe, tolerance tolerance, trace trace, transpose transpose, tril(k = 0) tril, tril!(k = 0) tril!, triu(k = 0) triu, triu!(k = 0) triu!, vcat(other) vcat

Class methods inherited from class LA::Matrix(T)

arange(start_val : T, end_val : T, delta = 1.0) arange, block_diag(*args) block_diag, circulant(c) circulant, column(values) column, companion(a) companion, dft(n, scale : DFTScale = DFTScale::None) dft, diag(nrows, ncolumns, value : Number | Complex)
diag(nrows, ncolumns, values)
diag(values)
diag(nrows, ncolumns, &)
diag
, eye(n) eye, fiedler(values) fiedler, from_custom(str : String, prefix, columns_separator, rows_separator, postfix)
from_custom(io, prefix, columns_separator, rows_separator, postfix)
from_custom
, from_matlab(s) from_matlab, hadamard(n) hadamard, hankel(column : Indexable | Matrix, row : Indexable | Matrix | Nil = nil) hankel, helmert(n, full = false) helmert, hilbert(n) hilbert, identity(n) identity, invhilbert(n) invhilbert, invpascal(n, kind : PascalKind = PascalKind::Symmetric) invpascal, kron(a, b) kron, leslie(f, s) leslie, load_csv(filename) load_csv, ones(nrows, ncolumns) ones, pascal(n, kind : PascalKind = PascalKind::Symmetric) pascal, rand(nrows, ncolumns, rng : Random | Nil = nil) rand, repmat(a : Matrix(T), nrows, ncolumns) repmat, row(values) row, toeplitz(column : Indexable | Matrix, row : Indexable | Matrix | Nil = nil) toeplitz, tri(nrows, ncolumns, k = 0) tri, zeros(nrows, ncolumns) zeros

Macros inherited from class LA::Matrix(T)

lapack(name, *args, worksize = nil) lapack, lapack_util(name, worksize, *args) lapack_util

Instance methods inherited from module Enumerable(T)

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

Constructor Detail

def self.new(nrows : Int32, ncolumns : Int32, upper_band : Int32, lower_band : Int32, values : Indexable) #

[View source]
def self.new(nrows, ncolumns, upper_band, values : Indexable) #

[View source]
def self.new(nrows : Int32, ncolumns : Int32, upper_band : Int32, lower_band : Int32 = upper_band, flags : LA::MatrixFlags = MatrixFlags::None) #

[View source]
def self.new(nrows : Int32, ncolumns : Int32, upper_band : Int32, lower_band : Int32 = upper_band, flags : LA::MatrixFlags = MatrixFlags::None, &) #

[View source]
def self.new(matrix : BandedMatrix) #

[View source]
def self.new(matrix : Matrix, tolerance = matrix.tolerance) #

[View source]

Class Method Detail

def self.diag(nrows, ncolumns, values) #

[View source]
def self.estimate(matrix : Matrix(T), tolerance = matrix.tolerance) #

Estimates the bandwidth of a matrix.

Arguments:

  • matrix (Matrix(T)) : The matrix to estimate bandwidth for.
  • tolerance (T) : Elements with absolute value <= tolerance are considered zero. Default: matrix.tolerance.

Returns:

  • Tuple(Int32, Int32) : Lower and upper bandwidth estimates.

[View source]
def self.rand(nrows, ncolumns, upper_band : Int32, lower_band : Int32, rng : Random | Nil = nil) #

[View source]
def self.rand(nrows, ncolumns, upper_band : Int32, rng : Random | Nil = nil) #

[View source]

Instance Method Detail

def ==(other : BandedMatrix(T)) #

[View source]
def add(m : BandedMatrix(T), *, alpha = 1, beta = 1) #

Adds another banded matrix with scaling.

Arguments:

  • m (BandedMatrix(T)) : Matrix to add.
  • alpha (T) : Scale factor for self. Default: 1.
  • beta (T) : Scale factor for m. Default: 1.

Returns:

  • BandedMatrix(T) : The result of alphaself + betam.

[View source]
def add(m : DenseMatrix, *, alpha = 1, beta = 1) #

[View source]
def add!(m : BandedMatrix(T), *, alpha = 1, beta = 1) #

[View source]
def clone #

[View source]
def conjtranspose #

Returns a conjugate transpose of the matrix.

For Complex matrices, returns the conjugate transpose. For real matrices, equivalent to transpose.

Returns:

  • BandedMatrix(T) : The conjugate transposed matrix.

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

Computes the determinant of the square banded matrix.

Arguments:

  • overwrite_a (Bool) : If true, allows overwriting the matrix during factorization. Default: false.

Returns:

  • T : The determinant value.

Raises:

  • ArgumentError : If matrix is not square.

[View source]
def dup #
Description copied from class Reference

Returns a shallow copy of this object.

This allocates a new object and copies the contents of self into it.


[View source]
def each_index(*, all = false, &) #
Description copied from class LA::Matrix(T)

Yields every index

all argument controls whether to yield all or non-empty elements for banded\sparse matrices Example: m.each_index { |i, j| m[i, j] = -m[i, j] }


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

Computes eigenvalues and eigenvectors of a symmetric/Hermitian banded matrix.

Arguments:

  • overwrite_a (Bool) : Allow overwriting self during calculation. Default: false.

Returns: - Tuple(Array(Float), GeneralMatrix(T)) : - Eigenvalues (Array) - Eigenvectors as columns of the matrix

Raises:

  • Exception : If matrix is not symmetric (real) or Hermitian (complex).

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

same as #eigs, but only eigenvalues are returned


[View source]
def flags : MatrixFlags #
Description copied from class LA::Matrix(T)

Returns flags of matrix (see MatrixFlags)


[View source]
def flags=(flags : MatrixFlags) #
Description copied from class LA::Matrix(T)

Returns flags of matrix (see MatrixFlags)


[View source]
def lower_band : Int32 #

[View source]
def lower_band=(value) #

[View source]
def map_with_index(&block : T -> U) forall U #
Description copied from class LA::Matrix(T)

Returns result of appliyng block to every element with index


[View source]
def ncolumns : Int32 #
Description copied from class LA::Matrix(T)

Returns number of columns in matrix


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

Computes the norm of the banded matrix.

Arguments:

  • kind (MatrixNorm) : Type of norm to compute. Default is Frobenius.

Returns:

  • T : The computed norm value (same type as matrix elements).

[View source]
def nrows : Int32 #
Description copied from class LA::Matrix(T)

Returns number of rows in matrix


[View source]
def set_bands(aupper, alower) : Nil #

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

Solves the linear system A * X = B for X.

Arguments:

  • b (GeneralMatrix(T)) : Right-hand side matrix.
  • overwrite_a (Bool) : Allow overwriting self during calculation. Default: false.
  • overwrite_b (Bool) : Allow overwriting b during calculation. Default: false.

Returns:

  • GeneralMatrix(T) : Solution matrix X.

Raises:

  • ArgumentError : If dimensions mismatch or self is not square.

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

Computes singular values of the banded matrix.

Arguments:

  • overwrite_a (Bool) : Allow overwriting self during calculation. Default: false.

Returns:

  • Array(Float) : List of singular values in descending order.

[View source]
def to_unsafe #
Description copied from class LA::Matrix(T)

Returns pointer to underlying data

Storage format depends of matrix type This method raises at runtime if matrix doesn't have raw pointer


[View source]
def transpose #

Returns a transposed copy of the matrix.

Returns:

  • BandedMatrix(T) : The transposed matrix with swapped dimensions and bandwidth.

[View source]
def transpose! #

Transposes the matrix in-place, swapping upper and lower bandwidth.

Returns:

  • self : The transposed matrix.

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

Returns a new matrix with elements below the k-th diagonal zeroed.

Arguments:

  • k (Int32) : Diagonal offset. Default: 0.

Returns:

  • BandedMatrix(T) : New matrix with elements below diagonal zeroed.

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

In-place: keeps only elements on or below the k-th diagonal.

Arguments:

  • k (Int32) : Diagonal offset. Default: 0.

Returns:

  • self : The modified matrix.

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

Returns a new matrix with elements above the k-th diagonal zeroed.

Arguments:

  • k (Int32) : Diagonal offset. Default: 0.

Returns:

  • BandedMatrix(T) : New matrix with elements above diagonal zeroed.

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

In-place: keeps only elements on or above the k-th diagonal.

Arguments:

  • k (Int32) : Diagonal offset. Default: 0.

Returns:

  • self : The modified matrix.

[View source]
def unsafe_fetch(i, j) #

[View source]
def unsafe_set(i, j, value) #

[View source]
def upper_band : Int32 #

[View source]
def upper_band=(value) #

[View source]