matrix
Linear algebra: matrices, systems of equations, decompositions, eigenvalues and statistics.
import matrix
This package is complete linear algebra over 64 bit floats: from making a matrix and multiplying through to solving systems, decompositions, eigenvalues and singular values, and statistical tools such as principal component analysis. To solve one system, call Solve; for several systems with one matrix, Decompose once and LUSolve many times.
Matrices hold floats and the results carry a little rounding error; compare with AllClose and display with Chop. For neural networks see tensor.
Types
PCA
struct PCA| Name | Type | Description |
|---|---|---|
components | Matrix | The components in the rows. |
variances | Matrix | The variance of each component. |
center | Matrix | The column means. |
import matrix
func build(rows: int, cols: int, numbers: str): matrix.Matrix:
mut data := Vector {} as Vector<f64>
each number in numbers.split(" "):
data.push(number.to_float())
end
ret matrix.FromArray(rows, cols, data)
end
func show(name: str, m &: matrix.Matrix):
println name, matrix.ToRepr(matrix.Chop(m, 0.000001), 3)
end
func r(value: f64): str:
ret matrix.ToStringPrec(matrix.Full(1, 1, value), 3)
end
func main:
show("Hilbert", matrix.Hilbert(2))
show("Hilbert times its inverse", matrix.MatMul(matrix.Hilbert(3), matrix.HilbertInverse(3)))
show("Vandermonde", matrix.Vandermonde(build(3, 1, "1 2 3"), 3))
show("Toeplitz", matrix.Toeplitz(build(3, 1, "1 2 3"), build(1, 3, "1 4 5")))
show("Hankel", matrix.Hankel(build(3, 1, "1 2 3"), build(1, 3, "3 4 5")))
show("Circulant", matrix.Circulant(build(1, 3, "1 2 3")))
show("Companion", matrix.Companion(build(1, 3, "1 -3 2")))
show("Pascal", matrix.Pascal(3))
show("Rotation2D", matrix.Rotation2D(0.0))
show("Rotation3D", matrix.Rotation3D(2, 0.0))
show("Householder", matrix.Householder(build(2, 1, "1 0")))
show("Givens", matrix.Givens(2, 0, 1, 0.0))
show("Permutation", matrix.Permutation(build(1, 3, "2 0 1")))
mut rng := matrix.NewRng(7)
println rng.next_bits() > 0, rng.next_float() < 1.0, rng.next_normal() < 10.0
mut random := matrix.Random(2, 3, -1.0, 1.0, 5)
println matrix.ShapeString(random), matrix.Min(random) >= -1.0, matrix.Max(random) < 1.0, matrix.AllClose(random, matrix.Random(2, 3, -1.0, 1.0, 5), 0.0)
println matrix.ShapeString(matrix.RandomNormal(2, 2, 1))
println matrix.IsSymmetric(matrix.RandomSymmetric(3, 1), 0.000001), matrix.IsPositiveDefinite(matrix.RandomSPD(3, 1), 0.000001), matrix.IsOrthogonal(matrix.RandomOrthogonal(3, 1), 0.00001)
mut data := build(4, 2, "1 2 2 4 3 6 4 8")
show("CenterColumns", matrix.CenterColumns(data))
show("ColumnMeans", matrix.ColumnMeans(data))
show("ColumnStds", matrix.ColumnStds(data, false))
show("Standardize", matrix.Standardize(data, false))
show("Covariance", matrix.Covariance(data, true))
show("Correlation", matrix.Correlation(data))
mut pca := matrix.PCAFit(data)
println matrix.ShapeString(pca.components), matrix.ShapeString(pca.variances), matrix.ShapeString(pca.center)
show("ExplainedVariance", matrix.ExplainedVariance(pca))
show("PCATransform", matrix.Abs(matrix.PCATransform(pca, data, 1)))
pca.free()
mut pca2 := matrix.PCAFromSVD(data)
show("from the SVD", matrix.ExplainedVariance(pca2))
pca2.free()
mut x := build(4, 1, "1 2 3 4")
mut y := build(4, 1, "3 5 7 9")
coefficients := matrix.LinearRegression(x, y)
show("LinearRegression", coefficients)
println r(matrix.RSquared(y, y))
endfree
func free()The example for this item is shown with the ones above: matrix-Stats.salam
Eigen
struct Eigen| Name | Type | Description |
|---|---|---|
n | int = 0 | The size. |
re | Matrix | The real part. |
im | Matrix | The imaginary part. |
iterations | int = 0 | The number of iterations. |
ok | bool = false | It converged. |
import matrix
func build(rows: int, cols: int, numbers: str): matrix.Matrix:
mut data := Vector {} as Vector<f64>
each number in numbers.split(" "):
data.push(number.to_float())
end
ret matrix.FromArray(rows, cols, data)
end
func show(name: str, m &: matrix.Matrix):
println name, matrix.ToRepr(matrix.Chop(m, 0.000001), 3)
end
func r(value: f64): str:
ret matrix.ToStringPrec(matrix.Full(1, 1, value), 3)
end
func main:
mut symmetric := build(2, 2, "2 1 1 2")
mut decomposition := matrix.EigSym(symmetric)
println decomposition.ok, decomposition.n, decomposition.sweeps >= 0
show("values", decomposition.values)
show("EigReconstruct", matrix.EigReconstruct(decomposition))
decomposition.free()
show("EigValsSym", matrix.EigValsSym(symmetric))
println r(matrix.SpectralRadiusSym(symmetric))
show("PowSym", matrix.PowSym(symmetric, 2.0))
show("SqrtSym squared", matrix.MatMul(matrix.SqrtSym(symmetric), matrix.SqrtSym(symmetric)))
mut general := build(2, 2, "0 1 -2 -3")
mut eigen := matrix.EigVals(general)
println eigen.ok, eigen.n, matrix.ToRepr(eigen.re, 3), matrix.ToRepr(eigen.im, 3), eigen.iterations >= 0
eigen.free()
mut rotation := build(2, 2, "0 -1 1 0")
mut complex := matrix.EigValsAuto(rotation)
show("imaginary", complex.im)
println r(matrix.SpectralRadius(general))
show("Hessenberg", matrix.Hessenberg(build(3, 3, "1 2 3 4 5 6 7 8 10")))
show("CharPoly", matrix.CharPoly(general))
mut vector := matrix.EigVecFor(symmetric, 3.0, 50)
show("EigVecFor", matrix.Abs(vector))
mut power := matrix.PowerIteration(symmetric, 100)
mut dominant := matrix.SubMatrix(power, 0, 0, 2, 1)
println r(power.at(2, 0)), r(matrix.Rayleigh(symmetric, dominant)), r(matrix.ShiftedInverseIteration(symmetric, 0.9, 50))
mut m := build(3, 2, "3 0 0 4 0 0")
mut svd := matrix.SVDecompose(m)
println svd.ok, matrix.ShapeString(svd.u), matrix.ShapeString(svd.v)
show("singular values", svd.s)
svd.free()
show("SingularValues", matrix.SingularValues(m))
println matrix.MatrixRank(m, 0.000001)
show("PseudoInverse", matrix.PseudoInverse(m, 0.000001))
show("NullSpace", matrix.NullSpace(build(2, 2, "1 1 1 1"), 0.000001))
show("ColumnSpace", matrix.Abs(matrix.ColumnSpace(build(2, 2, "1 1 1 1"), 0.000001)))
show("LowRankApprox", matrix.LowRankApprox(build(2, 2, "3 0 0 1"), 1))
tol := 0.000001
identity := matrix.Eye(3)
println matrix.IsSquare(identity), matrix.AllClose(identity, identity, tol), matrix.IsZero(matrix.Zeros(2, 2), tol), matrix.IsIdentity(identity, tol)
println matrix.IsSymmetric(symmetric, tol), matrix.IsSkewSymmetric(rotation, tol), matrix.IsDiagonal(identity, tol)
println matrix.IsUpperTriangular(build(2, 2, "1 2 0 3"), tol), matrix.IsLowerTriangular(build(2, 2, "1 0 2 3"), tol)
tridiagonal := build(3, 3, "2 1 0 1 2 1 0 1 2")
println matrix.IsBanded(tridiagonal, 1, 1, tol), matrix.LowerBandwidth(tridiagonal, tol), matrix.UpperBandwidth(tridiagonal, tol)
println matrix.IsOrthogonal(rotation, tol), matrix.IsNormal(symmetric, tol), matrix.IsIdempotent(build(2, 2, "1 0 0 0"), tol)
println matrix.IsInvolutory(build(2, 2, "0 1 1 0"), tol), matrix.IsNilpotent(build(2, 2, "0 1 0 0"), tol)
println matrix.IsPositiveDefinite(symmetric, tol), matrix.IsPositiveSemiDefinite(build(2, 2, "1 1 1 1"), tol)
println matrix.IsSingular(build(2, 2, "1 2 2 4")), matrix.IsInvertible(symmetric)
probability := build(2, 2, "0.5 0.5 0.5 0.5")
println matrix.IsRowStochastic(probability, tol), matrix.IsColStochastic(probability, tol), matrix.IsDoublyStochastic(probability, tol)
println matrix.IsPermutation(build(2, 2, "0 1 1 0"), tol), matrix.IsToeplitz(tridiagonal, tol), matrix.IsHankel(build(2, 2, "1 2 2 3"), tol)
println r(matrix.Density(tridiagonal))
endfree
func free()The example for this item is shown with the ones above: matrix-Eigen.salam
LU
struct LU| Name | Type | Description |
|---|---|---|
n | int = 0 | The size. |
lu | Matrix | L and U in one matrix. |
piv | Vector | The row swaps. |
sign | int = 1 | The sign of the permutation. |
singular | bool = false | The matrix is singular. |
import matrix
func build(rows: int, cols: int, numbers: str): matrix.Matrix:
mut data := Vector {} as Vector<f64>
each number in numbers.split(" "):
data.push(number.to_float())
end
ret matrix.FromArray(rows, cols, data)
end
func show(name: str, m &: matrix.Matrix):
println name, matrix.ToRepr(matrix.Chop(m, 0.000001), 3)
end
func r(value: f64): str:
ret matrix.ToStringPrec(matrix.Full(1, 1, value), 3)
end
func main:
mut a := build(3, 3, "4 1 0 1 3 1 0 1 2")
mut b := build(3, 1, "1 2 3")
println r(matrix.Det(a)), r(matrix.LogAbsDet(a))
show("Solve", matrix.Solve(a, b))
show("SolveVec", matrix.SolveVec(a, b))
mut lu := matrix.Decompose(a)
println lu.n, lu.piv.len(), lu.sign, lu.singular, matrix.ShapeString(lu.lu)
show("LUSolve", matrix.LUSolve(lu, b))
lu.free()
mut inverse := matrix.Inverse(a)
show("a times its inverse", matrix.MatMul(a, inverse))
show("Adjugate", matrix.Adjugate(build(2, 2, "1 2 3 4")))
show("Residual", matrix.Residual(a, matrix.Solve(a, b), b))
mut qr := matrix.QRDecompose(a)
println qr.m, qr.n, qr.full_rank, matrix.ShapeString(qr.qr), matrix.ShapeString(qr.rdiag)
show("Q times R", matrix.MatMul(matrix.QRGetQ(qr), matrix.QRGetR(qr)))
show("QRSolve", matrix.QRSolve(qr, b))
qr.free()
mut points := build(4, 2, "1 0 1 1 1 2 1 3")
mut values := build(4, 1, "1 3 5 7")
show("LeastSquares", matrix.LeastSquares(points, values))
show("Orthonormalize", matrix.Gram(matrix.Orthonormalize(points)))
show("Cholesky", matrix.Cholesky(a))
show("SolveSPD", matrix.SolveSPD(a, b))
show("CholeskySolve", matrix.CholeskySolve(matrix.Cholesky(a), b))
show("InverseSPD", matrix.MatMul(a, matrix.InverseSPD(a)))
println r(matrix.DetSPD(a)), r(matrix.LogDetSPD(a))
mut ldl := matrix.LDLDecompose(a)
println ldl.ok, ldl.n, matrix.ShapeString(ldl.l), matrix.ShapeString(ldl.d)
show("LDLSolve", matrix.LDLSolve(ldl, b))
ldl.free()
show("Inertia", matrix.Inertia(build(2, 2, "1 0 0 -1")))
mut singular := build(3, 3, "1 2 3 2 4 6 1 1 1")
show("RowEchelon", matrix.RowEchelon(singular))
show("RREF", matrix.RREF(singular))
show("PivotColumns", matrix.PivotColumns(singular))
println matrix.RankExact(singular), matrix.Nullity(singular)
show("NullSpaceExact", matrix.NullSpaceExact(singular))
show("ColumnSpaceExact", matrix.ColumnSpaceExact(singular))
mut right := build(3, 1, "6 12 3")
println matrix.IsConsistent(singular, right), matrix.IsConsistent(singular, build(3, 1, "1 3 3"))
show("SolveGeneral", matrix.SolveGeneral(singular, right))
println matrix.IsDiagonallyDominant(a)
mut jacobi := matrix.SolveJacobi(a, b, 200, 0.00000001)
println jacobi.converged, jacobi.iterations > 0, jacobi.residual < 0.0001
show("Jacobi", jacobi.x)
jacobi.free()
each method in [1, 2, 3]:
mut result := matrix.SolveGaussSeidel(a, b, 200, 0.00000001)
if method == 2:
result = matrix.SolveSOR(a, b, 1.2, 200, 0.00000001)
else method == 3:
result = matrix.SolveCG(a, b, 200, 0.00000001)
end
show("iterative", result.x)
result.free()
end
mut d := build(2, 2, "1 0 0 2")
show("Expm", matrix.Expm(matrix.Zeros(2, 2)))
show("Sqrtm", matrix.Sqrtm(build(2, 2, "4 0 0 9")))
show("MatrixSign", matrix.MatrixSign(build(2, 2, "2 0 0 -3")))
show("PolyEval", matrix.PolyEval(d, build(1, 3, "1 0 1")))
show("CayleyHamilton", matrix.CayleyHamilton(d))
show("LogmSym", matrix.LogmSym(matrix.Eye(2)))
endfree
func free()The example for this item is shown with the ones above: matrix-Solve.salam
IterResult
struct IterResult| Name | Type | Description |
|---|---|---|
x | Matrix | The solution. |
iterations | int = 0 | The number of iterations. |
residual | f64 = 0 | The norm of the residual. |
converged | bool = false | It converged. |
The example for this item is shown with the ones above: matrix-Solve.salam
free
func free()The example for this item is shown with the ones above: matrix-Solve.salam
LDL
struct LDL| Name | Type | Description |
|---|---|---|
n | int = 0 | The size. |
l | Matrix | The unit lower triangular matrix. |
d | Matrix | The diagonal D. |
ok | bool = false | The decomposition succeeded. |
The example for this item is shown with the ones above: matrix-Solve.salam
free
func free()The example for this item is shown with the ones above: matrix-Solve.salam
Matrix
struct Matrix| Name | Type | Description |
|---|---|---|
rows | int = 0 | The number of rows. |
cols | int = 0 | The number of columns. |
a | Vector | The elements. |
import matrix
func build(rows: int, cols: int, numbers: str): matrix.Matrix:
mut data := Vector {} as Vector<f64>
each number in numbers.split(" "):
data.push(number.to_float())
end
ret matrix.FromArray(rows, cols, data)
end
func main:
mut a := build(2, 3, "1 2 3 4 5 6")
matrix.Print(a)
println matrix.ShapeString(a), a.rows, a.cols, a.a.len(), a.count(), a.min_dim(), a.is_square(), a.is_empty()
println a.at(1, 2), a.flat(4)
a.set(0, 0, 10.0)
a.add_at(0, 1, 0.5)
a.mul_at(0, 2, 2.0)
a.set_flat(5, -1.0)
matrix.PrintPrec(a, 1)
matrix.PrintLabeled("a", a)
println matrix.ToString(matrix.Zeros(1, 2)), matrix.ToString(matrix.Ones(1, 2)), matrix.ToString(matrix.Full(1, 2, 7.0))
println matrix.ToString(matrix.Eye(2))
println matrix.ToString(matrix.EyeOffset(2, 3, 1))
mut data := Vector {} as Vector<f64>
data.push(1.0)
data.push(2.0)
println matrix.ShapeString(matrix.RowVector(data)), matrix.ShapeString(matrix.ColVector(data)), matrix.ToString(matrix.Diag(data))
mut b := matrix.Clone(a)
matrix.SetAll(b, 0.0)
matrix.CopyInto(b, a)
println b.same_shape(a), b.at(0, 0)
println matrix.ToStringPrec(matrix.Arange(0.0, 1.0, 0.25), 2)
println matrix.ToStringPrec(matrix.Linspace(0.0, 1.0, 5), 2)
println matrix.ToStringPrec(matrix.Logspace(0.0, 2.0, 3, 10.0), 1)
println matrix.ToCSV(a, 1)
println matrix.ToRepr(a, 1)
println matrix.MAT_EPS > 0.0, matrix.MAT_TOL > 0.0, matrix.MAT_INF > 1000.0
matrix.Free(b)
a.free()
endat
func at(i: int, j: int): f64The example for this item is shown with the ones above: matrix-Create.salam
set
func set(i: int, j: int, v: f64)The example for this item is shown with the ones above: matrix-Create.salam
add_at
func add_at(i: int, j: int, v: f64)The example for this item is shown with the ones above: matrix-Create.salam
mul_at
func mul_at(i: int, j: int, v: f64)The example for this item is shown with the ones above: matrix-Create.salam
flat
func flat(k: int): f64The example for this item is shown with the ones above: matrix-Create.salam
set_flat
func set_flat(k: int, v: f64)The example for this item is shown with the ones above: matrix-Create.salam
count
func count(): intThe example for this item is shown with the ones above: matrix-Create.salam
is_square
func is_square(): boolThe example for this item is shown with the ones above: matrix-Create.salam
is_empty
func is_empty(): boolThe example for this item is shown with the ones above: matrix-Create.salam
same_shape
func same_shape(o &: Matrix): boolThe example for this item is shown with the ones above: matrix-Create.salam
min_dim
func min_dim(): intThe example for this item is shown with the ones above: matrix-Create.salam
free
func free()The example for this item is shown with the ones above: matrix-Create.salam
EigenSym
struct EigenSym| Name | Type | Description |
|---|---|---|
n | int = 0 | The size. |
values | Matrix | The eigenvalues, descending. |
vectors | Matrix | The eigenvectors in the columns. |
sweeps | int = 0 | The number of Jacobi sweeps. |
ok | bool = false | It converged. |
The example for this item is shown with the ones above: matrix-Eigen.salam
free
func free()The example for this item is shown with the ones above: matrix-Eigen.salam
Rng
struct Rng| Name | Type | Description |
|---|---|---|
s | u64 = 0 | The state. |
The example for this item is shown with the ones above: matrix-Stats.salam
next_bits
func next_bits(): u64The example for this item is shown with the ones above: matrix-Stats.salam
next_float
func next_float(): f64The example for this item is shown with the ones above: matrix-Stats.salam
next_normal
func next_normal(): f64The example for this item is shown with the ones above: matrix-Stats.salam
SVD
struct SVD| Name | Type | Description |
|---|---|---|
u | Matrix | The left singular vectors. |
s | Matrix | The singular values, descending. |
v | Matrix | The right singular vectors. |
ok | bool = false | It converged. |
The example for this item is shown with the ones above: matrix-Eigen.salam
free
func free()The example for this item is shown with the ones above: matrix-Eigen.salam
QR
struct QR| Name | Type | Description |
|---|---|---|
m | int = 0 | The number of rows. |
n | int = 0 | The number of columns. |
qr | Matrix | The reflections and R, packed. |
rdiag | Matrix | The diagonal of R. |
full_rank | bool = true | The columns are independent. |
The example for this item is shown with the ones above: matrix-Solve.salam
free
func free()The example for this item is shown with the ones above: matrix-Solve.salam
Constants and variables
MAT_EPS
const MAT_EPS: f64 = 2.22045e-16The example for this item is shown with the ones above: matrix-Create.salam
MAT_TOL
const MAT_TOL: f64 = 1e-09The example for this item is shown with the ones above: matrix-Create.salam
MAT_INF
const MAT_INF: f64 = 1e+300The example for this item is shown with the ones above: matrix-Create.salam
Functions
CenterColumns
func CenterColumns(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
ColumnMeans
func ColumnMeans(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
ColumnStds
func ColumnStds(x &: Matrix, sample: bool): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Standardize
func Standardize(x &: Matrix, sample: bool): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Covariance
func Covariance(x &: Matrix, sample: bool): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Correlation
func Correlation(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
PCAFit
func PCAFit(x &: Matrix): PCAThe example for this item is shown with the ones above: matrix-Stats.salam
PCAFromSVD
func PCAFromSVD(x &: Matrix): PCAThe example for this item is shown with the ones above: matrix-Stats.salam
PCATransform
func PCATransform(p &: PCA, x &: Matrix, k: int): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
ExplainedVariance
func ExplainedVariance(p &: PCA): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
LinearRegression
func LinearRegression(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
RSquared
func RSquared(y &: Matrix, fitted &: Matrix): f64The example for this item is shown with the ones above: matrix-Stats.salam
Expm
func Expm(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
Sqrtm
func Sqrtm(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
MatrixSign
func MatrixSign(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
PolyEval
func PolyEval(x &: Matrix, coeffs &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
CayleyHamilton
func CayleyHamilton(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
LogmSym
func LogmSym(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
Hessenberg
func Hessenberg(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
EigVals
func EigVals(x &: Matrix): EigenThe example for this item is shown with the ones above: matrix-Eigen.salam
EigValsAuto
func EigValsAuto(x &: Matrix): EigenThe example for this item is shown with the ones above: matrix-Eigen.salam
SpectralRadius
func SpectralRadius(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Eigen.salam
CharPoly
func CharPoly(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
EigVecFor
func EigVecFor(x &: Matrix, lambda: f64, iters: int): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
Decompose
func Decompose(x &: Matrix): LUThe example for this item is shown with the ones above: matrix-Solve.salam
Det
func Det(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Solve.salam
LogAbsDet
func LogAbsDet(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Solve.salam
Solve
func Solve(a &: Matrix, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
LUSolve
func LUSolve(f &: LU, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
SolveVec
func SolveVec(a &: Matrix, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
Inverse
func Inverse(x &: Matrix): Matriximport matrix
func build(rows: int, cols: int, numbers: str): matrix.Matrix:
mut data := Vector {} as Vector<f64>
each number in numbers.split(" "):
data.push(number.to_float())
end
ret matrix.FromArray(rows, cols, data)
end
func show(name: str, m &: matrix.Matrix):
println name, matrix.ToRepr(m, 1)
end
func r(value: f64): str:
ret matrix.ToStringPrec(matrix.Full(1, 1, value), 3)
end
func main:
mut a := build(2, 2, "1 2 3 4")
mut b := build(2, 2, "0 1 1 0")
mut row := build(1, 2, "10 20")
mut col := build(2, 1, "1 -1")
show("Transpose", matrix.Transpose(a))
show("MatMul", matrix.MatMul(a, b))
mut out := matrix.Zeros(2, 2)
println matrix.TransposeInto(a, out), matrix.MatMulInto(a, b, out)
show("into", out)
show("TransposeMul", matrix.TransposeMul(a, b))
show("MulTranspose", matrix.MulTranspose(a, b))
show("Gram", matrix.Gram(a))
show("MatVec", matrix.MatVec(a, col))
show("VecMat", matrix.VecMat(row, a))
println matrix.Dot(col, col), matrix.Trace(a)
show("Outer", matrix.Outer(col, col))
show("Kron", matrix.Kron(matrix.Eye(2), matrix.Full(1, 2, 3.0)))
show("MatPow", matrix.MatPow(a, 2))
show("Cross3", matrix.Cross3(build(3, 1, "1 0 0"), build(3, 1, "0 1 0")))
show("Add", matrix.Add(a, b))
show("Sub", matrix.Sub(a, b))
show("MulElem", matrix.MulElem(a, b))
show("DivElem", matrix.DivElem(a, a))
show("Neg", matrix.Neg(a))
show("with scalars", matrix.AddScalar(matrix.SubScalar(matrix.Scale(matrix.DivScalar(a, 2.0), 4.0), 1.0), 1.0))
mut c := matrix.Clone(a)
matrix.AddInPlace(c, b)
matrix.SubInPlace(c, b)
matrix.MulElemInPlace(c, a)
matrix.ScaleInPlace(c, 0.5)
matrix.AddScalarInPlace(c, 1.0)
matrix.NegInPlace(c)
matrix.AddScaled(c, a, 2.0)
show("in place", c)
show("Combine", matrix.Combine(a, 2.0, b, -1.0))
show("MaxElem", matrix.MaxElem(a, matrix.Full(2, 2, 2.5)))
show("MinElem", matrix.MinElem(a, matrix.Full(2, 2, 2.5)))
show("AddRowVector", matrix.AddRowVector(a, row))
show("AddColVector", matrix.AddColVector(a, col))
show("MulRowVector", matrix.MulRowVector(a, row))
show("MulColVector", matrix.MulColVector(a, col))
mut m := build(1, 4, "-2.25 0 0.5 9")
show("Abs", matrix.Abs(m))
show("Sqrt", matrix.Sqrt(matrix.Abs(m)))
show("Cbrt", matrix.Cbrt(build(1, 2, "8 -27")))
show("Floor and Ceil", matrix.HStack(matrix.Floor(m), matrix.Ceil(m)))
show("Round and Trunc", matrix.HStack(matrix.Round(m), matrix.Trunc(m)))
show("Sign", matrix.Sign(m))
show("Square", matrix.Square(m))
show("Reciprocal", matrix.Reciprocal(build(1, 2, "2 4")))
show("PowElem", matrix.PowElem(build(1, 2, "2 3"), 3.0))
show("Clip", matrix.Clip(m, 0.0, 1.0))
show("MaxScalar and MinScalar", matrix.HStack(matrix.MaxScalar(m, 0.0), matrix.MinScalar(m, 0.0)))
show("Chop", matrix.Chop(build(1, 2, "0.0000001 1"), 0.0001))
mut zero := matrix.Zeros(1, 1)
println matrix.ToStringPrec(matrix.HStack(matrix.Exp(zero), matrix.Log(matrix.Ones(1, 1))), 3), matrix.ToStringPrec(matrix.Log10(matrix.Full(1, 1, 100.0)), 3), matrix.ToStringPrec(matrix.Log2(matrix.Full(1, 1, 8.0)), 3)
println matrix.ToStringPrec(matrix.HStack(matrix.Sin(zero), matrix.Cos(zero)), 3), matrix.ToStringPrec(matrix.Tan(zero), 3)
println matrix.ToStringPrec(matrix.HStack(matrix.Asin(zero), matrix.Acos(matrix.Ones(1, 1))), 3), matrix.ToStringPrec(matrix.Atan(zero), 3)
println matrix.ToStringPrec(matrix.HStack(matrix.Sinh(zero), matrix.Cosh(zero)), 3), matrix.ToStringPrec(matrix.Tanh(zero), 3)
println matrix.Sum(a), matrix.Prod(a), matrix.Mean(a), matrix.Min(a), matrix.Max(a), matrix.Range(a)
k := matrix.ArgMax(a)
println matrix.ArgMin(a), k, matrix.IndexRow(a, k), matrix.IndexCol(a, k), matrix.MaxAbs(m)
println r(matrix.Var(a, true)), r(matrix.Std(a, false)), matrix.Median(a)
show("RowSums", matrix.RowSums(a))
show("ColSums", matrix.ColSums(a))
show("RowMeans", matrix.RowMeans(a))
show("ColMeans", matrix.ColMeans(a))
show("RowMins and RowMaxs", matrix.HStack(matrix.RowMins(a), matrix.RowMaxs(a)))
show("ColMins and ColMaxs", matrix.VStack(matrix.ColMins(a), matrix.ColMaxs(a)))
show("cumulative", matrix.HStack(matrix.CumSumRows(a), matrix.CumSumCols(a)))
show("CumProdRows", matrix.CumProdRows(a))
println matrix.CountNonZero(b), matrix.Any(b), matrix.All(b), matrix.AllFinite(b)
println r(matrix.NormFrobenius(a)), matrix.Norm1(a), matrix.NormInf(a), matrix.NormMax(a)
println r(matrix.Norm2(a)), r(matrix.NormNuclear(a)), matrix.VecNorm(col, 1.0), r(matrix.Distance(col, matrix.Zeros(2, 1)))
show("Normalize", matrix.Normalize(build(1, 2, "3 4")))
println matrix.ToStringPrec(matrix.NormalizeRows(a), 2)
println matrix.ToStringPrec(matrix.NormalizeCols(a), 2)
println r(matrix.Cond1(a)), r(matrix.CondInf(a)), r(matrix.Cond2(a))
endAdjugate
func Adjugate(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
IsDiagonallyDominant
func IsDiagonallyDominant(a &: Matrix): boolThe example for this item is shown with the ones above: matrix-Solve.salam
SolveJacobi
func SolveJacobi(a &: Matrix, b &: Matrix, iters: int, tol: f64): IterResultThe example for this item is shown with the ones above: matrix-Solve.salam
SolveGaussSeidel
func SolveGaussSeidel(a &: Matrix, b &: Matrix, iters: int, tol: f64): IterResultThe example for this item is shown with the ones above: matrix-Solve.salam
SolveSOR
func SolveSOR(a &: Matrix, b &: Matrix, omega: f64, iters: int, tol: f64): IterResultThe example for this item is shown with the ones above: matrix-Solve.salam
SolveCG
func SolveCG(a &: Matrix, b &: Matrix, iters: int, tol: f64): IterResultThe example for this item is shown with the ones above: matrix-Solve.salam
PowerIteration
func PowerIteration(a &: Matrix, iters: int): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
Rayleigh
func Rayleigh(a &: Matrix, x &: Matrix): f64The example for this item is shown with the ones above: matrix-Eigen.salam
ShiftedInverseIteration
func ShiftedInverseIteration(a &: Matrix, shift: f64, iters: int): f64The example for this item is shown with the ones above: matrix-Eigen.salam
Cholesky
func Cholesky(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
SolveSPD
func SolveSPD(a &: Matrix, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
CholeskySolve
func CholeskySolve(l &: Matrix, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
InverseSPD
func InverseSPD(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
DetSPD
func DetSPD(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Solve.salam
LogDetSPD
func LogDetSPD(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Solve.salam
LDLDecompose
func LDLDecompose(x &: Matrix): LDLThe example for this item is shown with the ones above: matrix-Solve.salam
LDLSolve
func LDLSolve(f &: LDL, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
Inertia
func Inertia(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
Zeros
func Zeros(rows: int, cols: int): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
Ones
func Ones(rows: int, cols: int): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
Full
func Full(rows: int, cols: int, x: f64): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
Eye
func Eye(n: int): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
EyeOffset
func EyeOffset(rows: int, cols: int, k: int): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
FromArray
func FromArray(rows: int, cols: int, data &: Vector<f64>): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
RowVector
func RowVector(data &: Vector<f64>): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
ColVector
func ColVector(data &: Vector<f64>): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
Diag
func Diag(data &: Vector<f64>): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
Clone
func Clone(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
CopyInto
func CopyInto(dst &: Matrix, src &: Matrix)The example for this item is shown with the ones above: matrix-Create.salam
Free
func Free(x &: Matrix)The example for this item is shown with the ones above: matrix-Create.salam
SetAll
func SetAll(x &: Matrix, v: f64)The example for this item is shown with the ones above: matrix-Create.salam
Arange
func Arange(start: f64, stop: f64, step: f64): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
Linspace
func Linspace(start: f64, stop: f64, num: int): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
Logspace
func Logspace(start: f64, stop: f64, num: int, base: f64): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
RowEchelon
func RowEchelon(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
RREF
func RREF(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
PivotColumns
func PivotColumns(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
RankExact
func RankExact(x &: Matrix): intThe example for this item is shown with the ones above: matrix-Solve.salam
Nullity
func Nullity(x &: Matrix): intThe example for this item is shown with the ones above: matrix-Solve.salam
NullSpaceExact
func NullSpaceExact(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
ColumnSpaceExact
func ColumnSpaceExact(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
SolveGeneral
func SolveGeneral(a &: Matrix, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
IsConsistent
func IsConsistent(a &: Matrix, b &: Matrix): boolThe example for this item is shown with the ones above: matrix-Solve.salam
EigSym
func EigSym(x &: Matrix): EigenSymThe example for this item is shown with the ones above: matrix-Eigen.salam
EigValsSym
func EigValsSym(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
EigReconstruct
func EigReconstruct(f &: EigenSym): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
SpectralRadiusSym
func SpectralRadiusSym(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Eigen.salam
PowSym
func PowSym(x &: Matrix, p: f64): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
SqrtSym
func SqrtSym(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
HStack
func HStack(x &: Matrix, y &: Matrix): Matriximport matrix
func build(rows: int, cols: int, numbers: str): matrix.Matrix:
mut data := Vector {} as Vector<f64>
each number in numbers.split(" "):
data.push(number.to_float())
end
ret matrix.FromArray(rows, cols, data)
end
func show(name: str, m &: matrix.Matrix):
println name, matrix.ToRepr(m, 1)
end
func main:
mut a := build(2, 3, "1 2 3 4 5 6")
mut square := build(3, 3, "1 2 3 4 5 6 7 8 9")
show("Reshape", matrix.Reshape(a, 3, 2))
show("Flatten", matrix.Flatten(a))
show("FlattenCol", matrix.FlattenCol(a))
mut row := matrix.Row(a, 1)
mut col := matrix.Col(a, 2)
show("Row", row)
show("Col", col)
mut b := matrix.Clone(a)
matrix.SetRow(b, 0, row)
matrix.SetCol(b, 0, col)
show("SetRow and SetCol", b)
show("SubMatrix", matrix.SubMatrix(square, 1, 1, 2, 2))
show("Minor", matrix.Minor(square, 0, 0))
show("DeleteRow", matrix.DeleteRow(square, 1))
show("DeleteCol", matrix.DeleteCol(square, 1))
show("InsertRow", matrix.InsertRow(a, 1, matrix.Row(a, 0)))
show("InsertCol", matrix.InsertCol(a, 0, matrix.Col(a, 2)))
matrix.SwapRows(b, 0, 1)
matrix.SwapCols(b, 0, 2)
show("swapped", b)
show("Diagonal", matrix.Diagonal(square))
show("DiagonalOffset", matrix.DiagonalOffset(square, 1))
mut c := matrix.Clone(square)
matrix.SetDiagonal(c, matrix.Ones(3, 1))
matrix.ShiftDiagonal(c, 10.0)
show("new diagonal", matrix.Diagonal(c))
show("HStack", matrix.HStack(a, a))
show("VStack", matrix.VStack(a, a))
show("Augment", matrix.Augment(square, matrix.Eye(3)))
show("BlockDiag", matrix.BlockDiag(matrix.Eye(1), matrix.Full(1, 1, 2.0)))
show("Triu", matrix.Triu(square, 0))
show("Tril", matrix.Tril(square, -1))
show("SymmetrizeUpper", matrix.SymmetrizeUpper(square))
show("SymPart", matrix.SymPart(square))
show("SkewPart", matrix.SkewPart(square))
show("FlipVertical", matrix.FlipVertical(a))
show("FlipHorizontal", matrix.FlipHorizontal(a))
show("Rot90", matrix.Rot90(a, 1))
show("Roll", matrix.Roll(a, 0, 1))
show("Tile", matrix.Tile(matrix.Eye(1), 2, 2))
show("Pad", matrix.Pad(matrix.Eye(1), 1, 0, 0, 1, 9.0))
endVStack
func VStack(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Augment
func Augment(a &: Matrix, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
BlockDiag
func BlockDiag(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Triu
func Triu(x &: Matrix, k: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Tril
func Tril(x &: Matrix, k: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
SymmetrizeUpper
func SymmetrizeUpper(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
SymPart
func SymPart(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
SkewPart
func SkewPart(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
FlipVertical
func FlipVertical(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
FlipHorizontal
func FlipHorizontal(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Rot90
func Rot90(x &: Matrix, k: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Roll
func Roll(x &: Matrix, dr: int, dc: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Tile
func Tile(x &: Matrix, ry: int, rx: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Pad
func Pad(x &: Matrix, top: int, bottom: int, left: int, right: int, v: f64): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Sum
func Sum(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Prod
func Prod(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Mean
func Mean(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Min
func Min(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Create.salam
Max
func Max(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Range
func Range(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
ArgMin
func ArgMin(x &: Matrix): intThe example for this item is shown with the ones above: matrix-Math.salam
ArgMax
func ArgMax(x &: Matrix): intThe example for this item is shown with the ones above: matrix-Math.salam
IndexRow
func IndexRow(x &: Matrix, k: int): intThe example for this item is shown with the ones above: matrix-Math.salam
IndexCol
func IndexCol(x &: Matrix, k: int): intThe example for this item is shown with the ones above: matrix-Math.salam
MaxAbs
func MaxAbs(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Var
func Var(x &: Matrix, sample: bool): f64The example for this item is shown with the ones above: matrix-Math.salam
Std
func Std(x &: Matrix, sample: bool): f64The example for this item is shown with the ones above: matrix-Math.salam
Median
func Median(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
RowSums
func RowSums(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
ColSums
func ColSums(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
RowMeans
func RowMeans(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
ColMeans
func ColMeans(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
RowMins
func RowMins(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
RowMaxs
func RowMaxs(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
ColMins
func ColMins(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
ColMaxs
func ColMaxs(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
CumSumRows
func CumSumRows(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
CumSumCols
func CumSumCols(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
CumProdRows
func CumProdRows(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
CountNonZero
func CountNonZero(x &: Matrix): intThe example for this item is shown with the ones above: matrix-Math.salam
Any
func Any(x &: Matrix): boolThe example for this item is shown with the ones above: matrix-Create.salam
All
func All(x &: Matrix): boolThe example for this item is shown with the ones above: matrix-Create.salam
AllFinite
func AllFinite(x &: Matrix): boolThe example for this item is shown with the ones above: matrix-Math.salam
NewRng
func NewRng(seed: i64): RngThe example for this item is shown with the ones above: matrix-Stats.salam
Hilbert
func Hilbert(n: int): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
HilbertInverse
func HilbertInverse(n: int): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Vandermonde
func Vandermonde(x &: Matrix, cols: int): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Toeplitz
func Toeplitz(first_col &: Matrix, first_row &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
Hankel
func Hankel(first_col &: Matrix, last_row &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
Circulant
func Circulant(c &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Companion
func Companion(coeffs &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Pascal
func Pascal(n: int): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Rotation2D
func Rotation2D(theta: f64): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Rotation3D
func Rotation3D(axis: int, theta: f64): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Householder
func Householder(v &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Givens
func Givens(n: int, p: int, q: int, theta: f64): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Permutation
func Permutation(perm &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Random
func Random(rows: int, cols: int, lo: f64, hi: f64, seed: i64): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
RandomNormal
func RandomNormal(rows: int, cols: int, seed: i64): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
RandomSymmetric
func RandomSymmetric(n: int, seed: i64): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
RandomSPD
func RandomSPD(n: int, seed: i64): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
RandomOrthogonal
func RandomOrthogonal(n: int, seed: i64): MatrixThe example for this item is shown with the ones above: matrix-Stats.salam
Add
func Add(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Sub
func Sub(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MulElem
func MulElem(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
DivElem
func DivElem(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Neg
func Neg(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
AddScalar
func AddScalar(x &: Matrix, s: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
SubScalar
func SubScalar(x &: Matrix, s: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Scale
func Scale(x &: Matrix, s: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
DivScalar
func DivScalar(x &: Matrix, s: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
AddInPlace
func AddInPlace(dst &: Matrix, src &: Matrix)The example for this item is shown with the ones above: matrix-Math.salam
SubInPlace
func SubInPlace(dst &: Matrix, src &: Matrix)The example for this item is shown with the ones above: matrix-Math.salam
MulElemInPlace
func MulElemInPlace(dst &: Matrix, src &: Matrix)The example for this item is shown with the ones above: matrix-Math.salam
ScaleInPlace
func ScaleInPlace(dst &: Matrix, s: f64)The example for this item is shown with the ones above: matrix-Math.salam
AddScalarInPlace
func AddScalarInPlace(dst &: Matrix, s: f64)The example for this item is shown with the ones above: matrix-Math.salam
NegInPlace
func NegInPlace(dst &: Matrix)The example for this item is shown with the ones above: matrix-Math.salam
AddScaled
func AddScaled(dst &: Matrix, src &: Matrix, alpha: f64)The example for this item is shown with the ones above: matrix-Math.salam
Combine
func Combine(x &: Matrix, a: f64, y &: Matrix, b: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MaxElem
func MaxElem(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MinElem
func MinElem(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
AddRowVector
func AddRowVector(x &: Matrix, row &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
AddColVector
func AddColVector(x &: Matrix, col &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MulRowVector
func MulRowVector(x &: Matrix, row &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MulColVector
func MulColVector(x &: Matrix, col &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
SVDecompose
func SVDecompose(x &: Matrix): SVDThe example for this item is shown with the ones above: matrix-Eigen.salam
SingularValues
func SingularValues(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
MatrixRank
func MatrixRank(x &: Matrix, tol: f64): intThe example for this item is shown with the ones above: matrix-Solve.salam
PseudoInverse
func PseudoInverse(x &: Matrix, tol: f64): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
NullSpace
func NullSpace(x &: Matrix, tol: f64): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
ColumnSpace
func ColumnSpace(x &: Matrix, tol: f64): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
LowRankApprox
func LowRankApprox(x &: Matrix, k: int): MatrixThe example for this item is shown with the ones above: matrix-Eigen.salam
NormFrobenius
func NormFrobenius(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Norm1
func Norm1(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
NormInf
func NormInf(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
NormMax
func NormMax(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Norm2
func Norm2(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
NormNuclear
func NormNuclear(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
VecNorm
func VecNorm(x &: Matrix, p: f64): f64The example for this item is shown with the ones above: matrix-Math.salam
Distance
func Distance(x &: Matrix, y &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Normalize
func Normalize(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
NormalizeRows
func NormalizeRows(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
NormalizeCols
func NormalizeCols(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Cond1
func Cond1(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
CondInf
func CondInf(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Cond2
func Cond2(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
QRDecompose
func QRDecompose(x &: Matrix): QRThe example for this item is shown with the ones above: matrix-Solve.salam
QRGetQ
func QRGetQ(f &: QR): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
QRGetR
func QRGetR(f &: QR): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
LeastSquares
func LeastSquares(a &: Matrix, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
QRSolve
func QRSolve(f &: QR, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
Residual
func Residual(a &: Matrix, x &: Matrix, b &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
Orthonormalize
func Orthonormalize(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Solve.salam
ToStringPrec
func ToStringPrec(x &: Matrix, prec: int): strThe example for this item is shown with the ones above: matrix-Create.salam
ToString
func ToString(x &: Matrix): strThe example for this item is shown with the ones above: matrix-Create.salam
ShapeString
func ShapeString(x &: Matrix): str2x3.The example for this item is shown with the ones above: matrix-Create.salam
Print
func Print(x &: Matrix)The example for this item is shown with the ones above: matrix-Create.salam
PrintPrec
func PrintPrec(x &: Matrix, prec: int)The example for this item is shown with the ones above: matrix-Create.salam
PrintLabeled
func PrintLabeled(label: str, x &: Matrix)The example for this item is shown with the ones above: matrix-Create.salam
ToCSV
func ToCSV(x &: Matrix, prec: int): strThe example for this item is shown with the ones above: matrix-Create.salam
ToRepr
func ToRepr(x &: Matrix, prec: int): str[1,2; 3,4].The example for this item is shown with the ones above: matrix-Create.salam
Transpose
func Transpose(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MatMul
func MatMul(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
TransposeInto
func TransposeInto(x &: Matrix, out &: Matrix): boolThe example for this item is shown with the ones above: matrix-Math.salam
MatMulInto
func MatMulInto(x &: Matrix, y &: Matrix, out &: Matrix): boolThe example for this item is shown with the ones above: matrix-Math.salam
TransposeMul
func TransposeMul(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MulTranspose
func MulTranspose(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Gram
func Gram(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MatVec
func MatVec(a &: Matrix, x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
VecMat
func VecMat(x &: Matrix, a &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Dot
func Dot(x &: Matrix, y &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Outer
func Outer(u &: Matrix, v &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Kron
func Kron(x &: Matrix, y &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MatPow
func MatPow(x &: Matrix, k: int): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Trace
func Trace(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Math.salam
Cross3
func Cross3(u &: Matrix, v &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
IsSquare
func IsSquare(x &: Matrix): boolThe example for this item is shown with the ones above: matrix-Create.salam
AllClose
func AllClose(x &: Matrix, y &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsZero
func IsZero(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsIdentity
func IsIdentity(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsSymmetric
func IsSymmetric(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsSkewSymmetric
func IsSkewSymmetric(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsDiagonal
func IsDiagonal(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Solve.salam
IsUpperTriangular
func IsUpperTriangular(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsLowerTriangular
func IsLowerTriangular(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsBanded
func IsBanded(x &: Matrix, lower: int, upper: int, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
LowerBandwidth
func LowerBandwidth(x &: Matrix, tol: f64): intThe example for this item is shown with the ones above: matrix-Eigen.salam
UpperBandwidth
func UpperBandwidth(x &: Matrix, tol: f64): intThe example for this item is shown with the ones above: matrix-Eigen.salam
IsOrthogonal
func IsOrthogonal(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsNormal
func IsNormal(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsIdempotent
func IsIdempotent(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsInvolutory
func IsInvolutory(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsNilpotent
func IsNilpotent(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsPositiveDefinite
func IsPositiveDefinite(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsPositiveSemiDefinite
func IsPositiveSemiDefinite(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsSingular
func IsSingular(x &: Matrix): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsInvertible
func IsInvertible(x &: Matrix): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsRowStochastic
func IsRowStochastic(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsColStochastic
func IsColStochastic(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsDoublyStochastic
func IsDoublyStochastic(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsPermutation
func IsPermutation(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsToeplitz
func IsToeplitz(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
IsHankel
func IsHankel(x &: Matrix, tol: f64): boolThe example for this item is shown with the ones above: matrix-Eigen.salam
Density
func Density(x &: Matrix): f64The example for this item is shown with the ones above: matrix-Eigen.salam
Reshape
func Reshape(x &: Matrix, rows: int, cols: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Flatten
func Flatten(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
FlattenCol
func FlattenCol(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Row
func Row(x &: Matrix, i: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Col
func Col(x &: Matrix, j: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
SetRow
func SetRow(x &: Matrix, i: int, v &: Matrix)The example for this item is shown with the ones above: matrix-Shape.salam
SetCol
func SetCol(x &: Matrix, j: int, v &: Matrix)The example for this item is shown with the ones above: matrix-Shape.salam
SubMatrix
func SubMatrix(x &: Matrix, r0: int, c0: int, dr: int, dc: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
Minor
func Minor(x &: Matrix, i: int, j: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
DeleteRow
func DeleteRow(x &: Matrix, i: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
DeleteCol
func DeleteCol(x &: Matrix, j: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
InsertRow
func InsertRow(x &: Matrix, i: int, v &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
InsertCol
func InsertCol(x &: Matrix, j: int, v &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
SwapRows
func SwapRows(x &: Matrix, i: int, j: int)The example for this item is shown with the ones above: matrix-Shape.salam
SwapCols
func SwapCols(x &: Matrix, i: int, j: int)The example for this item is shown with the ones above: matrix-Shape.salam
Diagonal
func Diagonal(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
DiagonalOffset
func DiagonalOffset(x &: Matrix, k: int): MatrixThe example for this item is shown with the ones above: matrix-Shape.salam
SetDiagonal
func SetDiagonal(x &: Matrix, v &: Matrix)The example for this item is shown with the ones above: matrix-Shape.salam
ShiftDiagonal
func ShiftDiagonal(x &: Matrix, c: f64)The example for this item is shown with the ones above: matrix-Shape.salam
Abs
func Abs(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Sqrt
func Sqrt(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Exp
func Exp(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Log
func Log(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Log10
func Log10(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Log2
func Log2(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Sin
func Sin(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Cos
func Cos(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Tan
func Tan(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Asin
func Asin(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Acos
func Acos(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Atan
func Atan(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Sinh
func Sinh(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Cosh
func Cosh(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Tanh
func Tanh(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Floor
func Floor(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Ceil
func Ceil(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Round
func Round(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Trunc
func Trunc(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Sign
func Sign(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Square
func Square(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Create.salam
Reciprocal
func Reciprocal(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Cbrt
func Cbrt(x &: Matrix): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
PowElem
func PowElem(x &: Matrix, p: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Clip
func Clip(x &: Matrix, lo: f64, hi: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MaxScalar
func MaxScalar(x &: Matrix, s: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
MinScalar
func MinScalar(x &: Matrix, s: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam
Chop
func Chop(x &: Matrix, tol: f64): MatrixThe example for this item is shown with the ones above: matrix-Math.salam