fastmath.matrix

Fixed size (2x2, 3x3, 4x4) matrix types.

acos

(acos vector)

Apply acos to matrix elements.

acosh

(acosh vector)

Apply acosh to matrix elements.

acot

(acot vector)

Apply acot to matrix elements.

acoth

(acoth vector)

Apply acoth to matrix elements.

acsc

(acsc vector)

Apply acsc to matrix elements.

acsch

(acsch vector)

Apply acsch to matrix elements.

add

(add A)(add A B)

Add matrices, C=A+B.

adds

(adds A s)

Add scalar to all matrix elements

asec

(asec vector)

Apply asec to matrix elements.

asech

(asech vector)

Apply asech to matrix elements.

asin

(asin vector)

Apply asin to matrix elements.

asinh

(asinh vector)

Apply asinh to matrix elements.

atan

(atan vector)

Apply atan to matrix elements.

atanh

(atanh vector)

Apply atanh to matrix elements.

cb

(cb vector)

Apply cb to matrix elements.

cbrt

(cbrt vector)

Apply cbrt to matrix elements.

ceil

(ceil vector)

Apply ceil to matrix elements.

cholesky

(cholesky A)(cholesky A upper?)

Calculate L (lower by default) triangular for where L * L^T = A.

Checks only for symmetry, can return NaNs when A is not positive-definite.

col

(col A c)

Return column as a vector

cols

(cols A)

Return matrix columns

cols->mat

(cols->mat [a00 a10] [a01 a11])(cols->mat [a00 a10 a20] [a01 a11 a21] [a02 a12 a22])(cols->mat [a00 a10 a20 a30] [a01 a11 a21 a31] [a02 a12 a22 a32] [a03 a13 a23 a33])

Create nxn matrix from nd vectors (columns).

cols->mat2x2

(cols->mat2x2 [a00 a10] [a01 a11])

Create 2x2 matrix from 2d vectors (columns).

cols->mat3x3

(cols->mat3x3 [a00 a10 a20] [a01 a11 a21] [a02 a12 a22])

Create 3x3 matrix from 3d vectors (columns).

cols->mat4x4

(cols->mat4x4 [a00 a10 a20 a30] [a01 a11 a21 a31] [a02 a12 a22 a32] [a03 a13 a23 a33])

Create 4x4 matrix from 4d vectors (columns).

condition

(condition A)(condition A norm-type)

Condition number calculated for L2 norm by default (see norm for other norm types).

Cond(A) = norm(A) * norm(inv(A))

cos

(cos vector)

Apply cos to matrix elements.

cosh

(cosh vector)

Apply cosh to matrix elements.

cot

(cot vector)

Apply cot to matrix elements.

coth

(coth vector)

Apply coth to matrix elements.

csc

(csc vector)

Apply csc to matrix elements.

csch

(csch vector)

Apply csch to matrix elements.

degrees

(degrees vector)

Apply degrees to matrix elements.

det

(det A)

Return determinant of the matrix.

diag

(diag A)

Return diagonal of the matrix as a vector.

diagonal

(diagonal v)(diagonal a11 a22)(diagonal a11 a22 a33)(diagonal a11 a22 a33 a44)

Create diagonal matrix

eigenvalues

(eigenvalues A)

Return complex eigenvalues for given matrix as a sequence

eigenvalues-matrix

(eigenvalues-matrix A)

Return eigenvalues for given matrix as a diagonal or block diagonal matrix

eigenvectors

(eigenvectors A)(eigenvectors A normalize?)

Return eigenvectors as a matrix (columns). Vectors can be normalized.

emulm

(emulm A B)

Multiply two matrices element-wise, Hadamard product, C=AoB

exp

(exp vector)

Apply exp to matrix elements.

expm1

(expm1 vector)

Apply expm1 to matrix elements.

eye

floor

(floor vector)

Apply floor to matrix elements.

fmap

(fmap A f)

Apply a function f to each matrix element.

frac

(frac vector)

Apply frac to matrix elements.

inverse

(inverse m)

Matrix inversion.

Returns nil if inversion doesn’t exist.

jinc

(jinc vector)

Apply jinc to matrix elements.

ln

(ln vector)

Apply ln to matrix elements.

log

(log vector)

Apply log to matrix elements.

log10

(log10 vector)

Apply log10 to matrix elements.

log1mexp

(log1mexp vector)

Apply log1mexp to matrix elements.

log1p

(log1p vector)

Apply log1p to matrix elements.

log1pexp

(log1pexp vector)

Apply log1pexp to matrix elements.

log1pmx

(log1pmx vector)

Apply log1pmx to matrix elements.

log1psq

(log1psq vector)

Apply log1psq to matrix elements.

log2

(log2 vector)

Apply log2 to matrix elements.

logexpm1

(logexpm1 vector)

Apply logexpm1 to matrix elements.

logit

(logit vector)

Apply logit to matrix elements.

logmxp1

(logmxp1 vector)

Apply logmxp1 to matrix elements.

mat

(mat a00 a01 a10 a11)(mat a00 a01 a02 a10 a11 a12 a20 a21 a22)(mat a00 a01 a02 a03 a10 a11 a12 a13 a20 a21 a22 a23 a30 a31 a32 a33)

Create mat2x2, mat3x3 or mat4x4

mat->array

(mat->array A)

Return doubles of doubles

mat->array2d

(mat->array2d A)

Return doubles of doubles

mat->float-array

(mat->float-array A)

Return doubles of doubles

mat->float-array2d

(mat->float-array2d A)

Return doubles of doubles

mat->RealMatrix

(mat->RealMatrix A)

Return Apache Commons Math Array2DRowMatrix from a matrix

mat2x2

(mat2x2 v)(mat2x2 d1 d2)(mat2x2 a00 a01 a10 a11)

Create 2x2 matrix.

Arity:

  • 1 - fills matrix with given value
  • 2 - creates diagonal matrix
  • 4 - creates row ordered matrix

mat3x3

(mat3x3 v)(mat3x3 d1 d2 d3)(mat3x3 a00 a01 a02 a10 a11 a12 a20 a21 a22)

Create 3x3 matrix.

Arity:

  • 1 - fills matrix with given value
  • 3 - creates diagonal matrix
  • 9 - creates row ordered matrix

mat4x4

(mat4x4 v)(mat4x4 d1 d2 d3 d4)(mat4x4 a00 a01 a02 a03 a10 a11 a12 a13 a20 a21 a22 a23 a30 a31 a32 a33)

Create 4x4 matrix.

Arity:

  • 1 - fills matrix with given value
  • 4 - creates diagonal matrix
  • 16 - creates row ordered matrix

mulm

(mulm A B)(mulm A transposeA? B transposeB?)

Multiply two matrices, C=AxB.

Optionally you can request transposition of matrices.

mulmt

(mulmt A B)

Multiply with transposed matrix, C=AxB^T

muls

(muls A s)

Multply matrix by a scalar, C=sA

mulv

(mulv A v)

Multply matrix by vector, x=Av

ncol

(ncol A)

Return number of rows

negate

(negate A)

Negate all matrix elements, C=-A

norm

(norm A)(norm A norm-type)

Calculate norm of the matrix for given type, default: 1 (maximum absolute column sum).

All norm types are: * 1 - maximum absolute column sum * :inf - maximum absolute row sum * 2 - spectral norm, maximum singular value * :max - maximum absolute value * :frobenius - Frobenius norm * p,q - generalized L_pq norm, 2,2 - Frobenius norm, p,p - entrywise p-norm * p - Shatten p-norm, 1 - nuclear/trace norm

normalize

(normalize A)(normalize A rows?)

Normalize columns (or rows)

nrow

(nrow A)

Return number of rows

outer

(outer v1 v2)

Outer project for two vectors.

radians

(radians vector)

Apply radians to matrix elements.

rint

(rint vector)

Apply rint to matrix elements.

rotation-matrix-2d

(rotation-matrix-2d theta)

Create rotation matrix for a plane

rotation-matrix-3d

(rotation-matrix-3d [x y z])(rotation-matrix-3d x y z)

Create rotation matrix for a 3d space. Tait–Bryan angles z-y′-x″

rotation-matrix-3d-x

(rotation-matrix-3d-x a)

Create rotation matrix for a 3d space, x-axis, right hand rule.

rotation-matrix-3d-y

(rotation-matrix-3d-y a)

Create rotation matrix for a 3d space, y-axis, right hand rule.

rotation-matrix-3d-z

(rotation-matrix-3d-z a)

Create rotation matrix for a 3d space, z-axis, right hand rule.

rotation-matrix-axis-3d

(rotation-matrix-axis-3d angle axis)

Create 3d rotation matrix for axis ratation.

round

(round vector)

Apply round to matrix elements.

row

(row A r)

Return row as a vector

rows

(rows A)

Return matrix rows

rows->mat

(rows->mat [a00 a01] [a10 a11])(rows->mat [a00 a01 a02] [a10 a11 a12] [a20 a21 a22])(rows->mat [a00 a01 a02 a03] [a10 a11 a12 a13] [a20 a21 a22 a23] [a30 a31 a32 a33])

Create nxn matrix from nd vectors (rows).

rows->mat2x2

(rows->mat2x2 [a00 a01] [a10 a11])

Create 2x2 matrix from 2d vectors (rows).

rows->mat3x3

(rows->mat3x3 [a00 a01 a02] [a10 a11 a12] [a20 a21 a22])

Create 3x3 matrix from 3d vectors (rows).

rows->mat4x4

(rows->mat4x4 [a00 a01 a02 a03] [a10 a11 a12 a13] [a20 a21 a22 a23] [a30 a31 a32 a33])

Create 4x4 matrix from 4d vectors (rows).

rows->RealMatrix

(rows->RealMatrix rows)

Return Apache Commons Math Array2DRowMatrix from sequence of rows

safe-sqrt

(safe-sqrt vector)

Apply safe-sqrt to matrix elements.

sec

(sec vector)

Apply sec to matrix elements.

sech

(sech vector)

Apply sech to matrix elements.

sfrac

(sfrac vector)

Apply sfrac to matrix elements.

sgn

(sgn vector)

Apply sgn to matrix elements.

sigmoid

(sigmoid vector)

Apply sigmoid to matrix elements.

signum

(signum vector)

Apply signum to matrix elements.

sin

(sin vector)

Apply sin to matrix elements.

sinc

(sinc vector)

Apply sinc to matrix elements.

singular-values

(singular-values A)

Returun singular values of the matrix as sqrt of eigenvalues of A^T * A matrix.

sinh

(sinh vector)

Apply sinh to matrix elements.

solve

(solve A b)

Solve linear equation Ax=b

sq

(sq vector)

Apply sq to matrix elements.

sqrt

(sqrt vector)

Apply sqrt to matrix elements.

sub

(sub A)(sub A B)

Subract matrices, C=A-B.

symmetric?

(symmetric? A)

Check if matrix is symmetric

tan

(tan vector)

Apply tan to matrix elements.

tanh

(tanh vector)

Apply tanh to matrix elements.

tmulm

(tmulm A B)

Transpose and multiply, C=A^TxB

tmulmt

(tmulmt A B)

Transpose both and multiply, C=A^TxB^T

trace

(trace A)

Return trace of the matrix (sum of diagonal elements)

transpose

(transpose A)

Transpose matrix, C=A^T

trunc

(trunc vector)

Apply trunc to matrix elements.

vtmul

(vtmul A v)

Multiply transposed vector by matrix, C=v^T A

xlogx

(xlogx vector)

Apply xlogx to matrix elements.

zero