Julia's Extended Linear Algebra Interface

The following ArrayInterface functions extend Julia's Base LinearAlgebra interface to improve the ability to do generic linear algebra.

Generic Matrix Constructors

These functions allow for the construction of matrices from array information in a generic way. It handles cases like how if x is a vector on the GPU, its associated matrix type should also be GPU-based, and thus appropriately placed with zeros/undef values.

ArrayInterface.zeromatrixFunction
zeromatrix(u::AbstractVector)

Creates the zero'd matrix version of u. Note that this is unique because similar(u,length(u),length(u)) returns a mutable type, so it is not type-matching, while fill(zero(eltype(u)),length(u),length(u)) doesn't match the array type, i.e., you'll get a CPU array from a GPU array. The generic fallback is u .* u' .* false, which works on a surprising number of types, but can be broken with weird (recursive) broadcast overloads. For higher-order tensors, this returns the matrix linear operator type which acts on the vec of the array.

source
ArrayInterface.undefmatrixFunction
undefmatrix(u::AbstractVector)

Creates the matrix version of u with possibly undefined values. Note that this is unique because similar(u,length(u),length(u)) returns a mutable type, so it is not type-matching, while fill(zero(eltype(u)),length(u),length(u)) doesn't match the array type, i.e., you'll get a CPU array from a GPU array. The generic fallback is u .* u', which works on a surprising number of types, but can be broken with weird (recursive) broadcast overloads. For higher-order tensors, this returns the matrix linear operator type which acts on the vec of the array.

source

Generic Matrix Functions

These query allow for easily learning properties of a general matrix.

Factorization Instance Functions

These functions allow for generating the instance of a factorization's result without running the full factorization. This thus allows for building types to hold the factorization without having to perform expensive extra computations.

ArrayInterface.bunchkaufman_instanceFunction

bunchkaufmaninstance(A, pivot = LinearAlgebra.RowMaximum()) -> bunchkaufmanfactorization_instance

Returns an instance of the Bunch-Kaufman factorization object with the correct type cheaply.

source

bunchkaufman_instance(a::Number) -> a

Returns the number.

source

bunchkaufman_instance(a::Any) -> cholesky(a, check=false)

Returns the number.

source
ArrayInterface.cholesky_instanceFunction

choleskyinstance(A, pivot = LinearAlgebra.RowMaximum()) -> choleskyfactorization_instance

Returns an instance of the Cholesky factorization object with the correct type cheaply.

source

cholesky_instance(a::Number, pivot = LinearAlgebra.RowMaximum()) -> a

Returns the number.

source

cholesky_instance(a::Any, pivot = LinearAlgebra.RowMaximum()) -> cholesky(a, check=false)

Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.

source
ArrayInterface.ldlt_instanceFunction

ldltinstance(A) -> ldltfactorization_instance

Returns an instance of the LDLT factorization object with the correct type cheaply.

source

ldlt_instance(a::Number) -> a

Returns the number.

source

ldlt_instance(a::Any) -> ldlt(a, check=false)

Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.

source
ArrayInterface.lu_instanceFunction

luinstance(A) -> lufactorization_instance

Returns an instance of the LU factorization object with the correct type cheaply.

source

lu_instance(a::Number) -> a

Returns the number.

source
lu_instance(a::Any) -> lu(a, check=false)

Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.

source
ArrayInterface.qr_instanceFunction

qrinstance(A, pivot = NoPivot()) -> qrfactorization_instance

Returns an instance of the QR factorization object with the correct type cheaply.

source

qr_instance(a::Number) -> a

Returns the number.

source
qr_instance(a::Any) -> qr(a)

Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.

source
ArrayInterface.svd_instanceFunction

svdinstance(A) -> qrfactorization_instance

Returns an instance of the SVD factorization object with the correct type cheaply.

source

svd_instance(a::Number) -> a

Returns the number.

source
svd_instance(a::Any) -> svd(a)

Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.

source

Addtional Linear Algebra Interface Tools

If dealing with general linear algebra, consider:

  • LinearSolve.jl: An extended linear solving library with support for generic arrays.