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 — Function
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.
ArrayInterface.undefmatrix — Function
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.
Generic Matrix Functions
These query allow for easily learning properties of a general matrix.
ArrayInterface.issingular — Function
issingular(A::AbstractMatrix) -> BoolDetermine 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 — Function
bunchkaufman_instance(A, pivot = LinearAlgebra.RowMaximum()) -> bunchkaufman_factorization_instanceReturns an instance of the Bunch-Kaufman factorization object with the correct type cheaply.
bunchkaufman_instance(a::Number) -> aReturns the number.
bunchkaufman_instance(a::Any) -> cholesky(a, check=false)Returns the number.
ArrayInterface.cholesky_instance — Function
cholesky_instance(A, pivot = LinearAlgebra.NoPivot()) -> cholesky_factorization_instanceReturns an instance of the Cholesky factorization object with the correct type cheaply.
cholesky_instance(a::Number, pivot = LinearAlgebra.NoPivot()) -> aReturns the number.
cholesky_instance(a::Any, pivot = LinearAlgebra.NoPivot()) -> cholesky(a, check=false)Slow fallback which gets the instance via factorization. Should get specialized for new matrix types.
ArrayInterface.ldlt_instance — Function
ldlt_instance(A) -> ldlt_factorization_instanceReturns an instance of the LDLT factorization object with the correct type cheaply.
ldlt_instance(a::Number) -> aReturns 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 — Function
lu_instance(A) -> lu_factorization_instanceReturns an instance of the LU factorization object with the correct type cheaply.
lu_instance(a::Number) -> aReturns 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 — Function
qr_instance(A, pivot = NoPivot()) -> qr_factorization_instanceReturns an instance of the QR factorization object with the correct type cheaply.
qr_instance(a::Number) -> aReturns 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 — Function
svd_instance(A) -> qr_factorization_instanceReturns an instance of the SVD factorization object with the correct type cheaply.
svd_instance(a::Number) -> aReturns 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.