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.zeromatrix
— Functionzeromatrix(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.
ArrayInterface.undefmatrix
— Functionundefmatrix(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.
Generic Matrix Functions
These query allow for easily learning properties of a general matrix.
ArrayInterface.issingular
— Functionissingular(A::AbstractMatrix) -> Bool
Determine whether a given abstract matrix is singular.
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_instance
— Functionbunchkaufmaninstance(A, pivot = LinearAlgebra.RowMaximum()) -> bunchkaufmanfactorization_instance
Returns an instance of the Bunch-Kaufman factorization object with the correct type cheaply.
bunchkaufman_instance(a::Number) -> a
Returns the number.
bunchkaufman_instance(a::Any) -> cholesky(a, check=false)
Returns the number.
ArrayInterface.cholesky_instance
— Functioncholeskyinstance(A, pivot = LinearAlgebra.RowMaximum()) -> choleskyfactorization_instance
Returns an instance of the Cholesky factorization object with the correct type cheaply.
cholesky_instance(a::Number, pivot = LinearAlgebra.RowMaximum()) -> a
Returns the number.
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.
ArrayInterface.ldlt_instance
— Functionldltinstance(A) -> ldltfactorization_instance
Returns an instance of the LDLT factorization object with the correct type cheaply.
ldlt_instance(a::Number) -> a
Returns the number.
ldlt_instance(a::Any) -> ldlt(a, check=false)
Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.
ArrayInterface.lu_instance
— Functionluinstance(A) -> lufactorization_instance
Returns an instance of the LU factorization object with the correct type cheaply.
lu_instance(a::Number) -> a
Returns the number.
lu_instance(a::Any) -> lu(a, check=false)
Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.
ArrayInterface.qr_instance
— Functionqrinstance(A, pivot = NoPivot()) -> qrfactorization_instance
Returns an instance of the QR factorization object with the correct type cheaply.
qr_instance(a::Number) -> a
Returns the number.
qr_instance(a::Any) -> qr(a)
Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.
ArrayInterface.svd_instance
— Functionsvdinstance(A) -> qrfactorization_instance
Returns an instance of the SVD factorization object with the correct type cheaply.
svd_instance(a::Number) -> a
Returns the number.
svd_instance(a::Any) -> svd(a)
Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.
Addtional Linear Algebra Interface Tools
If dealing with general linear algebra, consider:
- LinearSolve.jl: An extended linear solving library with support for generic arrays.