DualMatrixTools.jl Documentation
This package provides an overloaded factorize and \ that work with dual-valued arrays.
It is essentially based on the dual type defined by the DualNumbers.jl package.
Motivation
The idea is that for a dual-valued matrix $M = A + \varepsilon B$, its inverse is given by $M^{-1} = (I - \varepsilon_1 A^{-1} B) A^{-1}$. Therefore, only the inverse of $A$ is required to evaluate the inverse of $M$. This package should be useful for evaluation of first derivatives of functions that use \ (e.g., with iterative solvers).
How it works
DualMatrixTools.jl makes available a DualFactors type which contains the factors of $A$ (i.e., the output of factorize, e.g., $L$ and $U$, or $Q$ and $R$) and the non-real part of $M$ (i.e., $B$). DualMatrixTools.jl overloads factorize so that for a dual-valued matrix M, factorize(M) creates an instance of DualFactors. Finally, DualMatrixTools.jl also overloads \ to efficiently solve dual-valued linear systems of the type $M x = y$ by using the default \ with the factors of $A$ only.
Usage
Create your hyperdual-valued matrix M:
n = 4
A, B = rand(n, n), randn(n, n)
M = A + ε * B
typeof(M)
# output
Array{DualNumbers.Dual{Float64},2}Factorize M:
Mf = factorize(M)
typeof(Mf)
# output
DualFactorsApply \ to solve systems of the type M * x = y
y = rand(n, 2) * [1.0, ε]
x = Mf \ y
M * x ≈ y
# output
trueFunctions
LinearAlgebra.factorize — Function.LinearAlgebra.factorize(M::SparseMatrixCSC{<:Dual,<:Int})
Invokes LinearAlgebra.factorize on just the real part of M and stores it along with the dual part into a DualFactors object.
LinearAlgebra.factorize(M::Array{<:Dual,2})
Invokes LinearAlgebra.factorize on just the real part of M and stores it along with the dual part into a DualFactors object.
Base.:\ — Function.\(M::DualFactors, y::AbstractVecOrMat{Float64})Backsubstitution for DualFactors. See DualFactors for details.
\(M::DualFactors, y::AbstractVecOrMat{Dual128})Backsubstitution for DualFactors. See DualFactors for details.
\(Af::Factorization{Float64}, y::AbstractVecOrMat{Dual128})Backsubstitution for Dual-valued RHS.
\(M::AbstractArray{Dual128,2}, y::AbstractVecOrMat)Backslash (factorization and backsubstitution) for Dual-valued matrix M.
New types
DualMatrixTools.DualFactors — Type.DualFactorsContainer type to work efficiently with backslash on dual-valued sparse matrices.
factorize(M) will create an instance containing
Af = factorize(realpart.(M))— the factors of the real partB = dualpart.(M)— the dual part
for a dual-valued matrix M.
This is because only the factors of the real part are needed when solving a linear system of the type $M x = b$ for a dual-valued matrix $M = A + \varepsilon B$. In fact, the inverse of $M$ is given by $M^{-1} = (I - \varepsilon A^{-1} B) A^{-1}$.